本文整理汇总了Python中hurry.filesize.size方法的典型用法代码示例。如果您正苦于以下问题:Python filesize.size方法的具体用法?Python filesize.size怎么用?Python filesize.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hurry.filesize
的用法示例。
在下文中一共展示了filesize.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_message_if_space_insufficient
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def _get_message_if_space_insufficient(cls, paths_to_copy):
INSUFFIENT_SPACE_ERROR_FMT = "There is insufficient space remaining on this instance to " + \
"containerize this notebook. Containerization would require {} of additional space."
files_to_copy_bytes = cls._get_total_size_of_files(paths_to_copy)
_, _, free_space_bytes = shutil.disk_usage("/")
required_bytes = int(cls.REQUIRED_SPACE_PER_FILES_SPACE * files_to_copy_bytes
) + cls.SPACE_REQUIREMENT_FUDGE_BYTES
if required_bytes > free_space_bytes:
cls.logger.info("Insufficient space to containerize. Has {} bytes, requires {} bytes, " +
"with fudge space requires {} bytes.".format(
free_space_bytes, files_to_copy_bytes, required_bytes))
additional_required_bytes = required_bytes - free_space_bytes
human_readable_additional_space_required = size(required_bytes - free_space_bytes)
return INSUFFIENT_SPACE_ERROR_FMT.format("{} bytes ({})".format(
additional_required_bytes, human_readable_additional_space_required))
示例2: __on_download_progress_update
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def __on_download_progress_update(self, blocknum, blocksize, totalsize):
"""
Prints some download progress information
:param blocknum:
:param blocksize:
:param totalsize:
:return:
"""
if not self.__show_download_progress:
return
readsofar = blocknum * blocksize
if totalsize > 0:
s = "\r%s / %s" % (size(readsofar), size(totalsize))
sys.stdout.write(s)
if readsofar >= totalsize: # near the end
sys.stderr.write("\r")
else: # total size is unknown
sys.stdout.write("\rread %s" % (size(readsofar)))
示例3: do_list
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def do_list(self, args):
try:
#call UForge API
printer.out("Getting all your bundles ...")
bundles = self.api.Users(self.login).Mysoftware.Getall()
bundles = bundles.mySoftwareList.mySoftware
if bundles is None or len(bundles) == 0:
printer.out("No bundles available")
else:
table = Texttable(800)
table.set_cols_dtype(["t","t","t", "t","t","t","t"])
table.header(["Id", "Name", "Version", "Description", "Category", "Size", "Imported"])
bundles = generics_utils.order_list_object_by(bundles, "name")
for bundle in bundles:
category = ""
if bundle.category is not None:
category = bundle.category.name
table.add_row([bundle.dbId, bundle.name, bundle.version, bundle.description, category, size(bundle.size), "X" if bundle.imported else ""])
print table.draw() + "\n"
printer.out("Found "+str(len(bundles))+" bundles")
return 0
except Exception as e:
return handle_uforge_exception(e)
示例4: test_do_info_draw_general
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def test_do_info_draw_general(self, mock_table_draw, mock_table_add_row, mock_draw_source, mock_draw_generation):
# given
i = self.prepare_image()
info_image = info_utils.create_image()
# when
i.do_info_draw_general(info_image)
# then
calls = []
calls.append(call(["Name", info_image.name]))
calls.append(call(["Format", info_image.targetFormat.name]))
calls.append(call(["Id", info_image.dbId]))
calls.append(call(["Version", info_image.version]))
calls.append(call(["Revision", info_image.revision]))
calls.append(call(["Uri", info_image.uri]))
calls.append(call(["Created", info_image.created.strftime("%Y-%m-%d %H:%M:%S")]))
calls.append(call(["Size", size(info_image.fileSize)]))
calls.append(call(["Compressed", "Yes" if info_image.compress else "No"]))
mock_table_draw.assert_called_once()
mock_draw_source.assert_called_once()
mock_draw_generation.assert_called_once()
assert mock_table_add_row.call_count == 9
mock_table_add_row.assert_has_calls(calls)
示例5: log_new
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def log_new(file, branch):
"""
Writes new changes to log file
"""
with open('log', 'a') as log:
codename = str(file).split("_")[1]
model = str(file).split("_")[3]
version = str(file).split("_")[4].strip()
android = str(file).split("_")[6].split(".zip")[0]
try:
zip_size = size(path.getsize(file), system=alternative)
md5_hash = md5_check(file)
except NameError:
pass
if str(file).split("_")[0] == 'fw':
var = 'firmware'
elif str(file).split("_")[0] == 'fw-non-arb':
var = 'non-arb firmware'
try:
log.write(var + '|' + branch + '|' + model + '|' + codename + '|' + version + '|'
+ android + '|' + file + '|' + zip_size + '|' + md5_hash + '\n')
except NameError:
pass
示例6: get_image_file_names
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def get_image_file_names(filepath, pattern):
matches = []
if os.path.exists(filepath):
for root, dirnames, filenames in os.walk(filepath):
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(root, filename)) # full path
if matches:
print("Found {} files, with a total file size of {}.".format(
len(matches), get_total_size(matches)))
return matches
else:
print("No files found.")
else:
print("Sorry that path does not exist. Try again.")
示例7: get_total_size
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def get_total_size(list_of_image_names):
total_size = 0
for image_name in list_of_image_names:
total_size += os.path.getsize(image_name)
return size(total_size)
示例8: setup_toolbar
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def setup_toolbar(self):
uncheck_all_icon = GUIUtilities.get_icon("uncheck_all.png")
self.btn_uncheck_all = ImageButton(icon=uncheck_all_icon, size=QSize(20, 20))
check_all_icon = GUIUtilities.get_icon("check_all.png")
self.btn_check_all = ImageButton(icon=check_all_icon, size=QSize(20, 20))
self.btn_check_all.setFixedWidth(40)
self.btn_uncheck_all.setFixedWidth(40)
self.btn_check_all.clicked.connect(self.btn_check_all_on_click_slot)
self.btn_uncheck_all.clicked.connect(self.btn_uncheck_all_on_click_slot)
示例9: build_ds_card
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def build_ds_card(self, ds: DatasetVO):
card_widget: GridCard = GridCard(debug=False)
card_widget.label = "{}".format(ds.name)
card_widget.label2 = "{} files \n {} ".format(ds.count,
size(ds.size, system=alternative) if ds.size else "0 MB")
btn_delete = ImageButton(GUIUtilities.get_icon("delete.png"), size=QSize(15, 15))
btn_delete.setToolTip("Delete dataset")
btn_edit = ImageButton(GUIUtilities.get_icon("edit.png"), size=QSize(15, 15))
btn_edit.setToolTip("Edit dataset")
btn_refresh = ImageButton(GUIUtilities.get_icon("refresh.png"), size=QSize(15, 15))
btn_refresh.setToolTip("Refresh dataset")
btn_export_annotations = ImageButton(GUIUtilities.get_icon("download.png"), size=QSize(15, 15))
btn_export_annotations.setToolTip("Export annotations")
btn_import_annotations = ImageButton(GUIUtilities.get_icon("upload.png"), size=QSize(15, 15))
btn_import_annotations.setToolTip("Import annotations")
card_widget.add_buttons([btn_delete, btn_edit, btn_refresh, btn_export_annotations, btn_import_annotations])
icon_file = "folder_empty.png"
icon = GUIUtilities.get_icon(icon_file)
# events
btn_delete.clicked.connect(lambda: self.delete_dataset_action_signal.emit(ds))
btn_edit.clicked.connect(lambda: self.edit_dataset_action_signal.emit(ds))
btn_export_annotations.clicked.connect(lambda: self.download_anno_action_signal.emit(ds))
btn_import_annotations.clicked.connect(lambda: self.import_anno_action_signal.emit(ds))
card_widget.body = ImageButton(icon)
btn_refresh.clicked.connect(lambda: self.refresh_dataset_action_signal.emit(ds))
card_widget.body.doubleClicked.connect(lambda evt: self.open_dataset_action_signal.emit(ds))
return card_widget
示例10: model_size
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def model_size(variables):
"""Get model size."""
total_params = sum(
[np.prod(var.shape.as_list()) * var.dtype.size for var in variables])
return hfsize.size(total_params, system=hfsize.alternative)
示例11: update
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def update(self):
self.i += 1
if self.i > 10:
self.text = 'mem:' + str(size(self.process.memory_info().rss))
self.i = 0
示例12: do_search
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def do_search(self, args):
try:
#add arguments
doParser = self.arg_search()
doArgs = doParser.parse_args(shlex.split(args))
#if the help command is called, parse_args returns None object
if not doArgs:
return 2
#call UForge API
printer.out("Search package '"+doArgs.pkg+"' ...")
distribution = self.api.Distributions(Id=doArgs.id).Get()
printer.out("for OS '"+distribution.name+"', version "+distribution.version)
pkgs = self.api.Distributions(Id=distribution.dbId).Pkgs.Getall(Query="name=="+doArgs.pkg)
pkgs = pkgs.pkgs.pkg
if pkgs is None or len(pkgs) == 0:
printer.out("No package found")
else:
table = Texttable(800)
table.set_cols_dtype(["t","t","t","t","t","t","t"])
table.header(["Name", "Version", "Arch", "Release", "Build date", "Size", "FullName"])
pkgs = generics_utils.order_list_object_by(pkgs, "name")
for pkg in pkgs:
table.add_row([pkg.name, pkg.version, pkg.arch, pkg.release, pkg.pkgBuildDate.strftime("%Y-%m-%d %H:%M:%S"), size(pkg.size), pkg.fullName])
print table.draw() + "\n"
printer.out("Found "+str(len(pkgs))+" packages")
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: "+str(e), printer.ERROR)
self.help_search()
except Exception as e:
return handle_uforge_exception(e)
示例13: do_list
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def do_list(self, args):
try:
#call UForge API
printer.out("Getting quotas for ["+self.login+"] ...")
quotas = self.api.Users(self.login).Quotas.Get()
if quotas is None or len(quotas.quotas.quota) == 0:
printer.out("No quotas available")
else:
values = {}
for quota in quotas.quotas.quota:
if quota.limit == -1:
nb = " (" + str(quota.nb) + ")"
else:
nb = " (" + str(size(quota.nb)) + "/" + str(size(quota.limit)) + ")"
if quota.type == constants.QUOTAS_SCAN:
text = "Scan" + ("s" if quota.nb > 1 else "") + nb
elif quota.type == constants.QUOTAS_TEMPLATE:
text = "Template" + ("s" if quota.nb > 1 else "") + nb
elif quota.type == constants.QUOTAS_GENERATION:
text = "Generation" + ("s" if quota.nb > 1 else "") + nb
elif quota.type == constants.QUOTAS_DISK_USAGE:
text = "Disk usage" + nb
if quota.limit != -1:
nb = float(quota.nb)
limit = float(quota.limit)
values[text] = (nb/limit) * 50
else:
values[text] = -1
ascii_bar_graph.print_graph(values)
return 0
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: "+str(e), printer.ERROR)
self.help_list()
except Exception as e:
return handle_uforge_exception(e)
示例14: do_delete
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def do_delete(self, args):
try:
#add arguments
doParser = self.arg_delete()
doArgs = doParser.parse_args(shlex.split(args))
#if the help command is called, parse_args returns None object
if not doArgs:
return 2
#call UForge API
printer.out("Searching bundle with id ["+doArgs.id+"] ...")
myBundle = self.api.Users(self.login).Mysoftware(doArgs.id).Get()
if myBundle is None or type(myBundle) is not MySoftware:
printer.out("Bundle not found", printer.WARNING)
else:
table = Texttable(800)
table.set_cols_dtype(["t","t","t", "t","t", "t"])
table.header(["Id", "Name", "Version", "Description", "Size", "Imported"])
table.add_row([myBundle.dbId, myBundle.name, myBundle.version, myBundle.description, size(myBundle.size), "X" if myBundle.imported else ""])
print table.draw() + "\n"
if generics_utils.query_yes_no("Do you really want to delete bundle with id "+str(myBundle.dbId)):
self.api.Users(self.login).Mysoftware(myBundle.dbId).Delete()
printer.out("Bundle deleted", printer.OK)
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: "+str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return handle_uforge_exception(e)
示例15: test_do_list_check_size
# 需要导入模块: from hurry import filesize [as 别名]
# 或者: from hurry.filesize import size [as 别名]
def test_do_list_check_size(self, mock_table_add_row, mock_api_pimg_getall, mock_api_getall):
# given
i = self.prepare_image()
mock_api_getall.return_value = self.create_images(6000, "users/myuser/whatever/12/testing/18")
new_pimages = uforge.publishImages()
new_pimages.publishImages = pyxb.BIND()
mock_api_pimg_getall.return_value = new_pimages
# when
i.do_list("")
# then
self.assertEquals(mock_table_add_row.call_count, 1)
mock_table_add_row.assert_called_with([ANY, ANY, ANY, ANY, ANY, ANY, size(6000), ANY, ANY])