Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a = pickle.dumps(ret)
b = pickle.loads(a)
self.assertEqual(ret, b)
check(psutil.Process().as_dict())
check(psutil.virtual_memory())
check(psutil.swap_memory())
check(psutil.cpu_times())
check(psutil.cpu_times_percent(interval=0))
check(psutil.net_io_counters())
if LINUX and not os.path.exists('/proc/diskstats'):
pass
else:
if not APPVEYOR:
check(psutil.disk_io_counters())
check(psutil.disk_partitions())
check(psutil.disk_usage(os.getcwd()))
check(psutil.users())
default=False,
required=False,
help='Pass this option to extract files found'
)
args = argparser.parse_args()
if not admin.isUserAdmin():
admin.runAsAdmin()
sys.exit()
dirPath = args.path
if not args.search == '.*':
print "Search Term Provided",args.search
outfile = open(args.output,'w')
outfile.write('"Inode","Full Path","Creation Time","Size","MD5 Hash","SHA1 Hash"\n')
wr = csv.writer(outfile, quoting=csv.QUOTE_ALL)
partitionList = psutil.disk_partitions()
for partition in partitionList:
imagehandle = pytsk3.Img_Info('\\\\.\\'+partition.device.strip("\\"))
if 'NTFS' in partition.fstype:
filesystemObject = pytsk3.FS_Info(imagehandle)
directoryObject = filesystemObject.open_dir(path=dirPath)
print "Directory:",dirPath
directoryRecurse(directoryObject,[])
async def is_mounted(middleware, path):
mounted = await middleware.run_in_thread(psutil.disk_partitions)
return any(fs.mountpoint == path for fs in mounted)
num /= 1024.0
return "%3.1f %s" % (num, 'TB')
# pip install psutil
import psutil
print('Disk partitions:')
for disk in psutil.disk_partitions():
print(' {}'.format(disk))
print()
print('Disk usage:')
for disk in filter(lambda x: 'fixed' in x.opts, psutil.disk_partitions()):
info = psutil.disk_usage(disk.device)
print(' {} {}'.format(disk.device, info))
print(' {} free of {}'.format(sizeof_fmt(info.free), sizeof_fmt(info.total)))
print()
print()
print('Disk io (input/output) total sum counters:')
print(' {}'.format(psutil.disk_io_counters()))
physical_drive_by_info = list(psutil.disk_io_counters(True).items())
print()
print('Physical drive io (input/output) counters ({}):'.format(len(physical_drive_by_info)))
#
# for drive, info in physical_drive_by_info:
def get_sys_disk():
sys_disk = {}
partition_info = []
partitions = psutil.disk_partitions()
for p in partitions:
partition_info.append(parser_sys_disk(p.mountpoint))
sys_disk = partition_info
return sys_disk
def get_tesladashcam_folder():
""" Check if there is a drive mounted with the Tesla DashCam folder."""
for partition in disk_partitions(all=False):
if "cdrom" in partition.opts or partition.fstype == "":
continue
teslacamfolder = os.path.join(partition.mountpoint, "TeslaCam")
if os.path.isdir(teslacamfolder):
_LOGGER.debug(f"{get_current_timestamp()}Folder TeslaCam found on partition {partition.mountpoint}.")
return teslacamfolder, partition.mountpoint
_LOGGER.debug(f"{get_current_timestamp()}No TeslaCam folder on partition {partition.mountpoint}.")
return None, None
print(f"Available: {get_size(svmem.available)}")
print(f"Used: {get_size(svmem.used)}")
print(f"Percentage: {svmem.percent}%")
print("="*20, "SWAP", "="*20)
# get the swap memory details (if exists)
swap = psutil.swap_memory()
print(f"Total: {get_size(swap.total)}")
print(f"Free: {get_size(swap.free)}")
print(f"Used: {get_size(swap.used)}")
print(f"Percentage: {swap.percent}%")
# Disk Information
print("="*40, "Disk Information", "="*40)
print("Partitions and Usage:")
# get all disk partitions
partitions = psutil.disk_partitions()
for partition in partitions:
print(f"=== Device: {partition.device} ===")
print(f" Mountpoint: {partition.mountpoint}")
print(f" File system type: {partition.fstype}")
try:
partition_usage = psutil.disk_usage(partition.mountpoint)
except PermissionError:
# this can be catched due to the disk that
# isn't ready
continue
print(f" Total Size: {get_size(partition_usage.total)}")
print(f" Used: {get_size(partition_usage.used)}")
print(f" Free: {get_size(partition_usage.free)}")
print(f" Percentage: {partition_usage.percent}%")
# get IO statistics since boot
disk_io = psutil.disk_io_counters()
def _disk_usage(self, all=False):
du = []
for part in psutil.disk_partitions(all=all):
du.append(
dict(
path=part.mountpoint,
**psutil.disk_usage(part.mountpoint)._asdict()
)
)
return du
def getDiskInfo(self, get=None):
return self.getDiskInfo2()
# 取磁盘分区信息
diskIo = psutil.disk_partitions()
diskInfo = []
for disk in diskIo:
if disk[1] == '/mnt/cdrom':
continue
if disk[1] == '/boot':
continue
tmp = {}
tmp['path'] = disk[1]
tmp['size'] = psutil.disk_usage(disk[1])
diskInfo.append(tmp)
return diskInfo
self.add_property(Property('description', _(u'Description'), lsb_release('-d', '-s')))
self.add_property(Property('release', _(u'Release'), lsb_release('-r', '-s')))
self.add_property(Property('codename', _(u'Codename'), lsb_release('-c', '-s')))
self.add_property(Property('sysinfo', _(u'System info'), uname('-a')))
else:
self.add_property(Property('is_lsb', _(u'LSB OS'), False))
self.add_property(Property('architecture', _(u'OS architecture'), platform.architecture()))
self.add_property(Property('python_version', _(u'Python version'), platform.python_version()))
self.add_property(Property('hostname', _(u'Hostname'), platform.node()))
self.add_property(Property('platform', _(u'Platform'), sys.platform))
self.add_property(Property('machine', _(u'Machine'), platform.machine()))
self.add_property(Property('processor', _(u'Processor'), platform.processor()))
self.add_property(Property('cpus', _(u'Number of CPUs'), psutil.NUM_CPUS))
self.add_property(Property('total_phymem', _(u'Total physical memory'), pretty_size(psutil.TOTAL_PHYMEM)))
self.add_property(Property('disk_partitions', _(u'Disk partitions'), '; '.join(['%s %s %s %s' % (partition.device, partition.mountpoint, partition.fstype, partition.opts) for partition in psutil.disk_partitions()])))
tesseract = pbs.Command(TESSERACT_PATH)
try:
self.add_property(Property('tesseract', _(u'tesseract version'), tesseract('-v').stderr))
except pbs.CommandNotFound:
self.add_property(Property('tesseract', _(u'tesseract version'), _(u'not found')))
except Exception:
self.add_property(Property('tesseract', _(u'tesseract version'), _(u'error getting version')))
unpaper = pbs.Command(UNPAPER_PATH)
try:
self.add_property(Property('unpaper', _(u'unpaper version'), unpaper('-V').stdout))
except pbs.CommandNotFound:
self.add_property(Property('unpaper', _(u'unpaper version'), _(u'not found')))
except Exception:
self.add_property(Property('unpaper', _(u'unpaper version'), _(u'error getting version')))