def account_info(self): """display account information""" f = self.api_client.account_info() for k, v in sorted(f.items()): if k in ['max_file_size', 'quota_total', 'quota_used']: v = sizeof_fmt(v) print('%s => %s' % (k, v))
def output(metadata, prefix=''): for k, v in metadata: if k == 'quota_info': print('%squota info:' % prefix) output(sorted(v.items()), prefix=' ' * 4) continue elif k in ['normal', 'quota']: v = sizeof_fmt(v) print('%s%s => %s' % (prefix, k, v))
def ls(self, path='/'): path = os.path.join('/', path) resp = self.api_client.metadata(path) if 'files' in resp: for f in resp['files']: size = '' folder='' if f['type'] == 'folder': folder='/' else: size = f['size'] size = sizeof_fmt(size) name = os.path.join(path,f['name']) encoding = locale.getdefaultlocale()[1] sys.stdout.write(('%9s %s%s\n' % (size,name,folder)).encode(encoding))
def get(self, from_path, to_path=''): if not to_path: to_path = os.path.basename(from_path) to_file = FileCallback(os.path.expanduser(to_path), "wb") rs = self.api_client.download_file(from_path) md = self.api_client.metadata(from_path) total_size = md.get('size', 0) cur_size = 0 bufsize = 4096 print('Downloading %s => %s: %s' % (from_path, to_path, sizeof_fmt(total_size))) data = rs.read(bufsize) while data != '': cur_size += len(data) to_file.write(data) file_callback(cur_size, total_size) data = rs.read(bufsize) sys.stdout.write('\n') # to keep process bar to_file.close() return total_size