Skip to content

Commit

Permalink
Refactor ConsoleTools slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
ppolewicz committed Dec 26, 2015
1 parent 6249da0 commit fd38c4f
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions b2
Original file line number Diff line number Diff line change
Expand Up @@ -1152,37 +1152,33 @@ def ls(args):
)

class ConsoleTool(object):
def __init__(self, info=None):
if info is None:
info = StoredAccountInfo()
self.info = info
def get_api(self):
return B2Api(self.info, AuthInfoCache(self.info))
def __init__(self):
info = StoredAccountInfo()
self.api = B2Api(info, AuthInfoCache(info))

def create_bucket(self, args):
if len(args) != 2:
usage_and_exit()
bucket_name = args[0]
bucket_type = args[1]

api = self.get_api()
print api.create_bucket(bucket_name, bucket_type).id_
print self.api.create_bucket(bucket_name, bucket_type).id_

def delete_bucket(self, args):
if len(args) != 1:
usage_and_exit()
bucket_name = args[0]

api = self.get_api()
bucket = api.get_bucket_by_name(bucket_name)
response = api.delete_bucket(bucket)
bucket = self.api.get_bucket_by_name(bucket_name)
response = self.api.delete_bucket(bucket)

print json.dumps(response, indent=4, sort_keys=True)

def list_buckets(self, args):
if len(args) != 0:
usage_and_exit()
api = self.get_api()
for b in api.list_buckets():

for b in self.api.list_buckets():
print '%s %-10s %s' % (b.id_, b.type_, b.name)


Expand Down

0 comments on commit fd38c4f

Please sign in to comment.