本文整理汇总了Python中shutil.disk_usage函数的典型用法代码示例。如果您正苦于以下问题:Python disk_usage函数的具体用法?Python disk_usage怎么用?Python disk_usage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了disk_usage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: copyfiles
def copyfiles(destid, dirid):
dest = tabledest.getdest(destid)
directory = tabledir.getdir(dirid)
srcdirpath = str(PurePath(directory['Location']).joinpath(directory['DirName']))
destdirpath = str(PurePath(dest['DiskPath']).joinpath(directory['DirName']))
makedirs(destdirpath)
while True:
if not (os.path.exists(srcdirpath) and os.path.exists(destdirpath)):
raise OSError('No such direcory')
freeusage = disk_usage(destdirpath).free - pow(2,30)
file = tablefile.getfilefrom(dirid, database.CopyState.idle, freeusage)
if file:
srcfilepath = getfilepath(file)
destfilepath = str(PurePath(destdirpath).joinpath(file['FileName'] + file['ExtName']))
try:
copyfile(srcfilepath, destfilepath)
except OSError as why:
print(why)
tablefile.updatecopystate(file['FileID'], destid, database.CopyState.failed, str(why))
os.remove(destfilepath)
else:
tablefile.updatecopystate(file['FileID'], destid, database.CopyState.finished)
log(destid, directory['DirName'], file['FileName'], file['ExtName'], srcfilepath)
else:
tabledir.updatecopystate(dirid, database.CopyState.finished)
break;
开发者ID:kanzihuang,项目名称:OfflineBackup,代码行数:27,代码来源:copyfiles.py
示例2: install_progress
def install_progress():
"""
Function to calculate progress percentage of install.
:return:
"""
from . import progressbar
try:
usb_details = details(config.usb_disk)
except PartitionNotMounted as e:
log(str(e))
return
config.usb_mount = usb_details['mount_point']
usb_size_used = usb_details['size_used']
thrd = threading.Thread(target=install_distro, name="install_progress")
# thrd.daemon()
# install_size = usb_size_used / 1024
# install_size = iso_size(config.image_path) / 1024
final_size = (usb_size_used + iso_size(config.image_path)) + config.persistence
thrd.start()
pbar = progressbar.ProgressBar(maxval=100).start() # bar = progressbar.ProgressBar(redirect_stdout=True)
while thrd.is_alive():
current_size = shutil.disk_usage(usb_details['mount_point'])[1]
percentage = int((current_size / final_size) * 100)
if percentage > 100:
percentage = 100
config.percentage = percentage
pbar.update(percentage)
time.sleep(0.1)
开发者ID:mbusb,项目名称:multibootusb,代码行数:29,代码来源:install.py
示例3: freespace
def freespace(self):
"""Get the amount of free space available.
"""
self.log.info("freespace")
freebytes = shutil.disk_usage(self.s3_dir).free
self.log.info("returning:" + str(freebytes))
return freebytes
开发者ID:HDFGroup,项目名称:datacontainer,代码行数:7,代码来源:s3downloader.py
示例4: get_disk_free
def get_disk_free(path):
'''
@type path: str
@rtype tuple
'''
return (path, floor(float(shutil.disk_usage(path).free) / MB))
开发者ID:kaysoky,项目名称:dcos,代码行数:7,代码来源:make_disk_resources.py
示例5: create_download_instructions
def create_download_instructions(self):
self.instlObj.batch_accum.set_current_section('sync')
already_synced_num_files, already_synced_num_bytes = self.instlObj.info_map_table.get_not_to_download_num_files_and_size()
to_sync_num_files, bytes_to_sync = self.instlObj.info_map_table.get_to_download_num_files_and_size()
var_stack.add_const_config_variable("__NUM_FILES_TO_DOWNLOAD__", "create_download_instructions", to_sync_num_files)
var_stack.add_const_config_variable("__NUM_BYTES_TO_DOWNLOAD__", "create_download_instructions", bytes_to_sync)
# notify user how many files and bytes to sync
self.instlObj.progress("{} of {} files to sync".format(to_sync_num_files, to_sync_num_files+already_synced_num_files))
self.instlObj.progress("{} of {} bytes to sync".format(bytes_to_sync, bytes_to_sync+already_synced_num_bytes))
if already_synced_num_files > 0:
self.instlObj.batch_accum += self.instlObj.platform_helper.progress("{} files already in cache".format(already_synced_num_files), math.ceil(already_synced_num_files/4))
if to_sync_num_files == 0:
return to_sync_num_files
file_list = self.instlObj.info_map_table.get_download_items_sync_info()
if False: # need to rethink how to calc mount point sizes efficiently
mount_points_to_size = total_sizes_by_mount_point(file_list)
for m_p in sorted(mount_points_to_size):
free_bytes = shutil.disk_usage(m_p).free
print(mount_points_to_size[m_p], "bytes to sync to drive", "".join(("'", m_p, "'")), free_bytes-mount_points_to_size[m_p], "bytes will remain")
self.create_sync_folders()
self.create_sync_urls(file_list)
self.create_curl_download_instructions()
self.instlObj.create_sync_folder_manifest_command("after-sync", back_ground=True)
self.create_check_checksum_instructions(to_sync_num_files)
return to_sync_num_files
开发者ID:wavesaudio,项目名称:instl,代码行数:34,代码来源:instlInstanceSync_url.py
示例6: diskfree_sigterm
def diskfree_sigterm(disk: Union[str, Path], pid: list, freethres: int, verbose: bool = False):
def _stop(pid: int):
if verbose:
print('sending', SIG, 'to', pid)
os.kill(pid, SIG)
disk = Path(disk).expanduser().resolve().anchor
du = shutil.disk_usage(disk)
freerat = du.free / du.total
if freerat < freethres:
for p in pid:
if isinstance(p, str):
try:
pstr = subprocess.check_output(
['pgrep', '-f', p], timeout=10, universal_newlines=True)
except Exception:
logging.error(f'did not find PID for {p}')
for s in pstr.split():
_stop(int(s))
_stop(p)
if verbose:
print(f'{disk} free percentage {freerat*100:.1f}')
开发者ID:scienceopen,项目名称:pybashutils,代码行数:27,代码来源:diskfree_sigterm.py
示例7: test_disk_usage
def test_disk_usage(self):
usage = psutil.disk_usage(os.getcwd())
assert usage.total > 0, usage
assert usage.used > 0, usage
assert usage.free > 0, usage
assert usage.total > usage.used, usage
assert usage.total > usage.free, usage
assert 0 <= usage.percent <= 100, usage.percent
if hasattr(shutil, 'disk_usage'):
# py >= 3.3, see: http://bugs.python.org/issue12442
shutil_usage = shutil.disk_usage(os.getcwd())
tolerance = 5 * 1024 * 1024 # 5MB
self.assertEqual(usage.total, shutil_usage.total)
self.assertAlmostEqual(usage.free, shutil_usage.free,
delta=tolerance)
self.assertAlmostEqual(usage.used, shutil_usage.used,
delta=tolerance)
# if path does not exist OSError ENOENT is expected across
# all platforms
fname = tempfile.mktemp()
try:
psutil.disk_usage(fname)
except OSError as err:
if err.args[0] != errno.ENOENT:
raise
else:
self.fail("OSError not raised")
开发者ID:0-wiz-0,项目名称:psutil,代码行数:28,代码来源:test_system.py
示例8: disk_usage_info
def disk_usage_info(wd, keep_free: int, warn=True, quiet=0):
"""Display information about disk usage and maybe a warning
:param wd: Working directory
:param keep_free: Disk space in bytes to keep free
:param warn: Show warning when keep_free seems too low
:param quiet: Show disk usage information
"""
# We create a directory here to prevent FileNotFoundError
# if someone specified --free without --download they are dumb
makedirs(wd,exist_ok=True)
free = disk_usage(wd).free
if quiet < 1:
print('free space: {:} MiB, minimum limit: {:} MiB'.format(free//1024**2, keep_free//1024**2), file=stderr)
if warn and free < keep_free:
msg = '\nWarning:\n' \
'The disk usage currently exceeds the limit by {} MiB.\n' \
'If the limit was set too high, many or ALL videos may get deleted.\n' \
'Press Enter to proceed or Ctrl+D to abort... '
print(msg.format((keep_free-free) // 1024**2), file=stderr)
try:
input()
except EOFError:
exit(1)
开发者ID:allejok96,项目名称:jw-scripts,代码行数:26,代码来源:arguments.py
示例9: test_disk_usage
def test_disk_usage(self):
usage = shutil.disk_usage(os.getcwd())
self.assertGreater(usage.total, 0)
self.assertGreater(usage.used, 0)
self.assertGreaterEqual(usage.free, 0)
self.assertGreaterEqual(usage.total, usage.used)
self.assertGreater(usage.total, usage.free)
开发者ID:Naddiseo,项目名称:cpython,代码行数:7,代码来源:test_shutil.py
示例10: diagnostic
def diagnostic(request):
# Load version number
with open('./package.json') as f:
package = json.load(f)
version = package['version']
# Disk space
total_disk_space, used_disk_space, free_disk_space = shutil.disk_usage('./')
template_args = {
'title': 'Diagnostic',
'version': version,
'total_disk_space': total_disk_space,
'used_disk_space': used_disk_space,
'free_disk_space': free_disk_space
}
# Memory (Linux only)
memory_stats = get_memory_stats()
if 'free' in memory_stats:
template_args['free_memory'] = memory_stats['free']
template_args['used_memory'] = memory_stats['used']
template_args['total_memory'] = memory_stats['total']
return render(request, self.template_path("diagnostic.html"), template_args)
开发者ID:pierotofy,项目名称:WebODM,代码行数:25,代码来源:plugin.py
示例11: test_disk_usage
def test_disk_usage(self):
usage = psutil.disk_usage(os.getcwd())
self.assertEqual(usage._fields, ('total', 'used', 'free', 'percent'))
assert usage.total > 0, usage
assert usage.used > 0, usage
assert usage.free > 0, usage
assert usage.total > usage.used, usage
assert usage.total > usage.free, usage
assert 0 <= usage.percent <= 100, usage.percent
if hasattr(shutil, 'disk_usage'):
# py >= 3.3, see: http://bugs.python.org/issue12442
shutil_usage = shutil.disk_usage(os.getcwd())
tolerance = 5 * 1024 * 1024 # 5MB
self.assertEqual(usage.total, shutil_usage.total)
self.assertAlmostEqual(usage.free, shutil_usage.free,
delta=tolerance)
self.assertAlmostEqual(usage.used, shutil_usage.used,
delta=tolerance)
# if path does not exist OSError ENOENT is expected across
# all platforms
fname = tempfile.mktemp()
with self.assertRaises(OSError) as exc:
psutil.disk_usage(fname)
self.assertEqual(exc.exception.errno, errno.ENOENT)
开发者ID:mabuaita,项目名称:ops,代码行数:26,代码来源:test_system.py
示例12: get_free_space
def get_free_space(dir=None):
if dir is None:
dir = os.getenv('PANDIR')
_, _, free_space = shutil.disk_usage(dir)
free_space = (free_space * u.byte).to(u.gigabyte)
return free_space
开发者ID:panoptes,项目名称:POCS,代码行数:7,代码来源:__init__.py
示例13: __init__
def __init__(self, path):
self.path = os.path.normpath(path)
self.free = disk_usage(path)[2]
self.folders = {}
self.big = {}
self.targets = self.settings()['folders']
self.set_folders()
开发者ID:jwdafoe,项目名称:DataTrans,代码行数:7,代码来源:datacopy.py
示例14: details_udisks2
def details_udisks2(usb_disk_part):
"""
Get details of USB disk detail.
usb_disk_part: It is the partition of an USB removable disk.
"""
import dbus
bus = dbus.SystemBus()
mount_point = ''
uuid = ''
file_system = ''
vendor = ''
model = ''
label = ''
devtype = "disk"
bd = bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2/block_devices%s'%usb_disk_part[4:])
device = bd.Get('org.freedesktop.UDisks2.Block', 'Device', dbus_interface='org.freedesktop.DBus.Properties')
device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
if device[-1].isdigit() is True:
uuid = bd.Get('org.freedesktop.UDisks2.Block', 'IdUUID', dbus_interface='org.freedesktop.DBus.Properties')
file_system = bd.Get('org.freedesktop.UDisks2.Block', 'IdType', dbus_interface='org.freedesktop.DBus.Properties')
mount_point = bd.Get('org.freedesktop.UDisks2.Filesystem', 'MountPoints', dbus_interface='org.freedesktop.DBus.Properties')
devtype = 'partition'
else:
devtype = 'disk'
file_system = 'No_File_System'
if mount_point:
# mount_point = str(bytearray(mount_point[0]).decode('utf-8').replace(b'\x00', b''))
mount_point = bytearray(mount_point[0]).replace(b'\x00', b'').decode('utf-8')
else:
try:
mount_point = UDISKS.mount(usb_disk_part)
config.add_remounted(usb_disk_part)
except:
mount_point = "No_Mount"
try:
label = bd.Get('org.freedesktop.UDisks2.Block', 'IdLabel', dbus_interface='org.freedesktop.DBus.Properties')
except:
label = "No_Label"
usb_drive_id = (bd.Get('org.freedesktop.UDisks2.Block', 'Drive', dbus_interface='org.freedesktop.DBus.Properties'))
bd1 = bus.get_object('org.freedesktop.UDisks2', usb_drive_id)
try:
vendor = bd1.Get('org.freedesktop.UDisks2.Drive', 'Vendor', dbus_interface='org.freedesktop.DBus.Properties')
except:
vendor = str('No_Vendor')
try:
model = bd1.Get('org.freedesktop.UDisks2.Drive', 'Model', dbus_interface='org.freedesktop.DBus.Properties')
except:
model = str('No_Model')
if not mount_point == "No_Mount":
size_total, size_used, size_free = \
shutil.disk_usage(mount_point)[:3]
else:
raise PartitionNotMounted(usb_disk_part)
return {'uuid': uuid, 'file_system': file_system, 'label': label, 'mount_point': mount_point,
'size_total': size_total, 'size_used': size_used, 'size_free': size_free,
'vendor': vendor, 'model': model, 'devtype': devtype}
开发者ID:mbusb,项目名称:multibootusb,代码行数:59,代码来源:usb.py
示例15: get_free_space_bytes
def get_free_space_bytes(folder):
""" Return folder/drive free space (in bytes)
"""
try:
total, _, free = shutil.disk_usage(folder)
return total, free
except:
return 0, 0
开发者ID:eomsoft,项目名称:teleport,代码行数:8,代码来源:audit.py
示例16: test_disk_usage
def test_disk_usage(self):
self.skip_real_fs()
file_path = self.make_path('foo', 'bar')
self.fs.create_file(file_path, st_size=400)
# root = self.os.path.splitdrive(file_path)[0] + self.fs.path_separator
disk_usage = shutil.disk_usage(file_path)
self.assertEqual(1000, disk_usage.total)
self.assertEqual(400, disk_usage.used)
self.assertEqual(600, disk_usage.free)
self.assertEqual((1000, 400, 600), disk_usage)
mount_point = self.create_mount_point()
dir_path = self.os.path.join(mount_point, 'foo')
file_path = self.os.path.join(dir_path, 'bar')
self.fs.create_file(file_path, st_size=400)
disk_usage = shutil.disk_usage(dir_path)
self.assertEqual((500, 400, 100), disk_usage)
开发者ID:mrbean-bremen,项目名称:pyfakefs,代码行数:17,代码来源:fake_filesystem_shutil_test.py
示例17: DiskSpace
def DiskSpace():
DiskSpace = shutil.disk_usage('/')
tkinter.messagebox.showinfo('Disk space', 'Free: %f Gbytes'
% (DiskSpace.free / 1e9) + '\n'
+ 'Used: %f Gbytes' % (DiskSpace.used
/ 1e9) + '\n' + 'Total: %f Gbytes'
% (DiskSpace.total / 1e9))
Logger(Trace=MyTrace(GFI(CF())), Message='DiskSpace')
开发者ID:dbkaynor,项目名称:PyCopyMoveTk,代码行数:8,代码来源:DougModules.py
示例18: getdisk_usage
def getdisk_usage(self):
"""only works on Python 3. returns 0 for Python 2"""
if disk_usage:
# noinspection PyCallingNonCallable
spaces = disk_usage(self.serverpath)
frsp = spaces.free
return frsp
return int(0)
开发者ID:benbaptist,项目名称:minecraft-wrapper,代码行数:8,代码来源:web.py
示例19: get_info_from_folder
def get_info_from_folder(name, folder_path):
info = {}
folder_usage = shutil.disk_usage(folder_path)
info[name + 'folder'] = folder_path
info[name + 'disktotal'] = folder_usage[0]
info[name + 'diskused'] = folder_usage[1]
info[name + 'used'] = get_folder_size(folder_path)
return info
开发者ID:jamesabel,项目名称:latus,代码行数:8,代码来源:usage.py
示例20: __init__
def __init__(self, top, min_size):
self.top = top
self.min_size = min_size
# disk usage in bytes (3.3+)
(self.total, self.used, z) = shutil.disk_usage(top)
manager = mp.Manager()
self.files = manager.list()
self.worker_size = manager.Value('i',0)
开发者ID:rutherford,项目名称:diskhog,代码行数:8,代码来源:diskhog_old.py
注:本文中的shutil.disk_usage函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论