def _list_all_objects(self, bucket, prefix, limit, outfile=None): items = ObsCmdUtil(self.client).get_objects_info(bucket, prefix, ('lastModified', 'size', 'key'), limit) for item in items: self._outprint("%19s\t%8s\t%s\n" % (item[0], bytes_to_unitstr(item[1]), join_bucket_key(bucket, item[2])), outfile) self._outprint('\ndisplay total: %d objects' % len(items), outfile) if outfile: self._outprint('ls to file %s complete.' % outfile)
def _get_bucket_storage(self, bucket): """ get bucket storage info, include size and object number :param bucket: :return: """ resp = self.client.getBucketStorageInfo(bucket) check_resp(resp) self._outprint("size: %s\n" % bytes_to_unitstr(resp.body.size)) self._outprint("objectNumber: %s\n" % resp.body.objectNumber)
def _list_dirs_objects(self, bucket, prefix, limit, outfile=None): dirs, objects = ObsCmdUtil(self.client).list_dirs_objects(bucket, prefix) cur = 0 for item in dirs: if limit and cur >= limit: break self._outprint("%19s\t%8s\t%s\n" % ('--', '--', join_bucket_key(bucket, item)), outfile) cur += 1 for item in objects: if limit and cur >= limit: break self._outprint("%19s\t%8s\t%s\n" % (item['lastModified'], bytes_to_unitstr(item['size']), (join_bucket_key(bucket, item['key']))), outfile) cur += 1 self._outprint('\ntotal: %d dirs, %d objects' % (len(dirs), len(objects)), outfile)
def test_bytes_more_gb(self): self.assertEqual(bytes_to_unitstr(1024 * 1024 * 1024 * 3.6), '3.6G')
def print_run_time(self, size, seconds, tasknum, cmd): total = unitstr_to_bytes(size) flowspeed = bytes_to_unitstr(total / seconds) msg = '%s/s\t\d tasks\t%s' % (flowspeed, tasknum, cmd) print(msg)
def test_bytes_gb(self): self.assertEqual(bytes_to_unitstr(1024 * 1024 * 1024 * 1.0), '1.0G')
def test_bytes_more_mb(self): self.assertEqual(bytes_to_unitstr(1024 * 1024 * 23.7), '23.7M')
def test_bytes_more_kb(self): self.assertEqual(bytes_to_unitstr(1024 * 1.1), '1.1K')
def test_bytes_less_kb(self): self.assertEqual(bytes_to_unitstr(1023), '1023B')
def test_1byte(self): self.assertEqual(bytes_to_unitstr(1), '1B')