Created
          June 2, 2010 00:01 
        
      - 
      
 - 
        
Save batok/421705 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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.