Download and install GSUtil.
GSUtil is bundled in a single archive named gsutil.zip. Unpack the archive in a convenient location, such as C:\GSUtil, see also https://developers.google.com/storage/docs/gsutil_install
Open a cmd window, and cd to the installed folder:
|cmd> cd gsutil
cmd> python gsutil config
Follow the instruction in the command window, and copy the URL as suggested and paste it in the web browser:
Click continue. Paste the authorization code obtained above in the cmd window. Follow the rest instructions in the cmd window.
Visit http://code.google.com/apis/console, and click the services tab as shown below:
Then click the Google Cloud Storage
Copy the x-ggo-project-id back to the cmd window
Boto config file will be created and saved to “C:\Users\YourAcoount\.boto”. You might have a look at it with any text editor if you like, and for advanced users, you can customize the configuration as well.
in cmd window, type: cmd> “python gsutil ls”
Then all you existing bucket in Google Cloud bucket is listed. Success!
Program using python
Now it is time to run your python code to automate your task. Test the code in https://developers.google.com/storage/docs/gspythonlibrary, it is fun.
You may encounter a few problems, for instance: “No module named oauth2_plugin” or sth like that. And the workaround is to add your gsutil installation path to the system variable “PYTHONPATH”.
Close your old cmd window and open a new one. This is important since the old cmd window does not know that the PYTHONPATH has changed, and to reflect this update, you have to spawn a new cmd.
Rerun below python code, and you will find two bucket is create in your google cloud storage.
from oauth2_plugin import oauth2_pluginimport boto
# URI scheme for Google Cloud Storage.
now = time.time()
for name in (CATS_BUCKET, DOGS_BUCKET):
Cute! It works! You can now create, delete cloud buckets and copy/move files to and from local file system and remote cloud storage systems!