Skip to content

Instantly share code, notes, and snippets.

@batok
Created June 2, 2010 00:01
Show Gist options
  • Save batok/421705 to your computer and use it in GitHub Desktop.
Save batok/421705 to your computer and use it in GitHub Desktop.
import configobj
from boto.gs.connection import GSConnection
import os
def main(upload = False):
try:
from win32com.shell import shellcon, shell
homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
except ImportError:
homedir = os.path.expanduser("~")
config = configobj.ConfigObj( os.path.join(homedir,".boto"))
cred = config["Credentials"]
ak, sak = cred["gs_access_key_id"], cred["gs_secret_access_key"]
c = GSConnection(ak,sak)
for bucket in c.get_all_buckets():
print "Bucket ... ", bucket.name
for key in bucket.get_all_keys():
print key.name
if upload:
key = bucket.new_key("testboto.py")
with open("testboto.py","rb") as f:
key.set_contents_from_file(f,policy="private")
if __name__ == "__main__":
main(True)
main()
@garnaat
Copy link

garnaat commented Jun 2, 2010

Cool. You actually don't have to muck around with the config directly. If you just put the "gs_access_key_id" and "gs_secret_access_key" values in the Credentials section of the ~/.boto config file you can just call:

c = GSConnection()

and it will pull the credentials out of the config file for you.

@batok
Copy link
Author

batok commented Jun 2, 2010

Good tip, Mitch... tks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment