__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
import codecs
import os
import re
from landscape.lib.compat import _PY3
# List of filesystem types authorized when generating disk use statistics.
STABLE_FILESYSTEMS = frozenset(
[
"ext",
"ext2",
"ext3",
"ext4",
"reiserfs",
"ntfs",
"msdos",
"dos",
"vfat",
"xfs",
"hpfs",
"jfs",
"ufs",
"hfs",
"hfsplus",
"simfs",
"drvfs",
"lxfs",
"zfs",
"btrfs",
],
)
EXTRACT_DEVICE = re.compile("([a-z]+)[0-9]*")
def get_mount_info(
mounts_file,
statvfs_,
filesystems_whitelist=STABLE_FILESYSTEMS,
):
"""
This is a generator that yields information about mounted filesystems.
@param mounts_file: A file with information about mounted filesystems,
such as C{/proc/mounts}.
@param statvfs_: A function to get file status information.
@param filesystems_whitelist: Optionally, a list of which filesystems to
stat.
@return: A C{dict} with C{device}, C{mount-point}, C{filesystem},
C{total-space} and C{free-space} keys. If the filesystem information
is not available, C{None} is returned. Both C{total-space} and
C{free-space} are in megabytes.
"""
for line in open(mounts_file):
try:
device, mount_point, filesystem = line.split()[:3]
if _PY3:
mount_point = codecs.decode(mount_point, "unicode_escape")
else:
mount_point = codecs.decode(mount_point, "string_escape")
except ValueError:
continue
if (
filesystems_whitelist is not None
and filesystem not in filesystems_whitelist
):
continue
megabytes = 1024 * 1024
try:
stats = statvfs_(mount_point)
except OSError:
continue
block_size = stats.f_bsize
total_space = (stats.f_blocks * block_size) // megabytes
free_space = (stats.f_bfree * block_size) // megabytes
yield {
"device": device,
"mount-point": mount_point,
"filesystem": filesystem,
"total-space": total_space,
"free-space": free_space,
}
def get_filesystem_for_path(path, mounts_file, statvfs_):
"""
Tries to determine to which of the mounted filesystem C{path} belongs to,
and then returns information about that filesystem or C{None} if it
couldn't be determined.
@param path: The path we want filesystem information about.
@param mounts_file: A file with information about mounted filesystems,
such as C{/proc/mounts}.
@param statvfs_: A function to get file status information.
@return: A C{dict} with C{device}, C{mount-point}, C{filesystem},
C{total-space} and C{free-space} keys. If the filesystem information
is not available, C{None} is returned. Both C{total-space} and
C{free-space} are in megabytes.
"""
candidate = None
path = os.path.realpath(path)
path_segments = path.split("/")
for info in get_mount_info(mounts_file, statvfs_):
mount_segments = info["mount-point"].split("/")
if path.startswith(info["mount-point"]):
if (not candidate) or path_segments[
: len(mount_segments)
] == mount_segments:
candidate = info
return candidate
def is_device_removable(device):
"""
This function returns whether a given device is removable or not by looking
at the corresponding /sys/block/<device>/removable file
@param device: The filesystem path to the device, e.g. /dev/sda1
"""
# Shortcut the case where the device an SD card. The kernel/udev currently
# consider SD cards (mmcblk devices) to be non-removable.
if os.path.basename(device).startswith("mmcblk"):
return True
path = _get_device_removable_file_path(device)
if not path:
return False
contents = None
try:
with open(path, "r") as f:
contents = f.readline()
except OSError:
return False
if contents.strip() == "1":
return True
return False
def _get_device_removable_file_path(device):
"""
Get a device's "removable" file path.
This function figures out the C{/sys/block/<device>/removable} path
associated with the given device. The file at that path contains either
a "0" if the device is not removable, or a "1" if it is.
@param device: File system path of the device.
"""
# The device will be a symlink if the disk is mounted by uuid or by label.
if os.path.islink(device):
# Paths are in the form "/dev/disk/by-uuid/<uuid>" and symlink
# to the device file under /dev
device = os.readlink(device) # /dev/disk/by-uuid/<uuid> -> ../../sda1
[device_name] = device.split("/")[-1:] # /dev/sda1 -> sda1
matched = EXTRACT_DEVICE.match(device_name) # sda1 -> sda
if not matched:
return None
device_name = matched.groups()[0]
removable_file = os.path.join("/sys/block/", device_name, "removable")
return removable_file
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| apt | Folder | 0755 |
|
|
| __init__.py | File | 198 B | 0644 |
|
| amp.py | File | 21.87 KB | 0644 |
|
| backoff.py | File | 1.65 KB | 0644 |
|
| base64.py | File | 156 B | 0644 |
|
| bootstrap.py | File | 1.36 KB | 0644 |
|
| bpickle.py | File | 6.68 KB | 0644 |
|
| cli.py | File | 457 B | 0644 |
|
| cloud.py | File | 1.69 KB | 0644 |
|
| compat.py | File | 621 B | 0644 |
|
| config.py | File | 12.36 KB | 0644 |
|
| disk.py | File | 5.09 KB | 0644 |
|
| encoding.py | File | 545 B | 0644 |
|
| fd.py | File | 750 B | 0644 |
|
| fetch.py | File | 6.65 KB | 0644 |
|
| format.py | File | 1.96 KB | 0644 |
|
| fs.py | File | 3.8 KB | 0644 |
|
| gpg.py | File | 1.88 KB | 0644 |
|
| hashlib.py | File | 264 B | 0644 |
|
| jiffies.py | File | 1.59 KB | 0644 |
|
| juju.py | File | 828 B | 0644 |
|
| lock.py | File | 705 B | 0644 |
|
| log.py | File | 444 B | 0644 |
|
| logging.py | File | 2.94 KB | 0644 |
|
| machine_id.py | File | 1.02 KB | 0644 |
|
| message.py | File | 2.57 KB | 0644 |
|
| monitor.py | File | 6.19 KB | 0644 |
|
| network.py | File | 9.74 KB | 0644 |
|
| os_release.py | File | 1.78 KB | 0644 |
|
| persist.py | File | 20.57 KB | 0644 |
|
| plugin.py | File | 1.69 KB | 0644 |
|
| process.py | File | 6.66 KB | 0644 |
|
| reactor.py | File | 8.65 KB | 0644 |
|
| schema.py | File | 6.61 KB | 0644 |
|
| scriptcontent.py | File | 519 B | 0644 |
|
| sequenceranges.py | File | 5.58 KB | 0644 |
|
| store.py | File | 1.42 KB | 0644 |
|
| sysstats.py | File | 7.71 KB | 0644 |
|
| tag.py | File | 506 B | 0644 |
|
| testing.py | File | 24.48 KB | 0644 |
|
| timestamp.py | File | 233 B | 0644 |
|
| twisted_util.py | File | 4.54 KB | 0644 |
|
| user.py | File | 1.44 KB | 0644 |
|
| versioning.py | File | 1.25 KB | 0644 |
|
| vm_info.py | File | 3.12 KB | 0644 |
|
| warning.py | File | 393 B | 0644 |
|