Skip to content

Instantly share code, notes, and snippets.

@batok
Created May 3, 2010 13:57
Show Gist options
  • Save batok/388118 to your computer and use it in GitHub Desktop.
Save batok/388118 to your computer and use it in GitHub Desktop.
from cmd2 import Cmd
import s3accounts
from boto.s3.connection import S3Connection
class Shell(Cmd):
prompt = "sc2s3>"
def __init__(self, connection):
Cmd.__init__(self)
self.conn = connection
self.bucket = s3accounts.preferred_bucket
self.prompt = "sc2s3_{0}> ".format( self.bucket)
def default(self, arg):
print "Command not recognized"
def do_quit(self, arg):
print "Bye"
return True
def do_ls( self, arg):
print "I will list the preferred bucket here"
b = self.conn.get_bucket(self.bucket)
for key in b.get_all_keys():
print key.name
def do_buckets( self, arg ):
print "Your S3 Buckets are..."
self.buckets = []
for i,b in enumerate(self.conn.get_all_buckets()):
print "{0:5d} {1}".format(i+1,b.name)
self.buckets.append(b.name)
def do_bucket(self, arg ):
self.bucket = self.buckets[int(arg) -1]
self.prompt = "sc2s3_{0}> ".format( self.bucket)
if __name__ == "__main__":
shell = Shell( S3Connection(*s3accounts.accounts.get("myaccount")))
shell.cmdloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment