-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,591 additions
and
807 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
from glob import glob | ||
|
||
|
||
def linux_block_devices(): | ||
for device_size in glob("/sys/block/*/size"): | ||
with open(device_size, "r") as sf: | ||
yield device_size.split("/")[3], int(sf.readlines()[0]) * 512 | ||
|
||
|
||
def linux_block_devices_largest_first(): | ||
devs = [dev for dev in linux_block_devices()] | ||
devs.sort(key = lambda dev: dev[1], reverse=True) | ||
devs.sort(key=lambda dev: dev[1], reverse=True) | ||
return devs | ||
|
||
|
||
def linux_unmounted_block_devices(): | ||
for dev in linux_block_devices(): | ||
if not linux_is_dev_mounted(dev[0]): | ||
yield dev | ||
|
||
|
||
def linux_unmounted_block_devices_largest_first(): | ||
devs = [dev for dev in linux_unmounted_block_devices()] | ||
devs.sort(key = lambda dev: dev[1], reverse=True) | ||
devs.sort(key=lambda dev: dev[1], reverse=True) | ||
return devs | ||
|
||
|
||
def linux_is_dev_mounted(device): | ||
with open("/proc/mounts", "r") as mounts: | ||
for mount in mounts.readlines(): | ||
if mount.startswith(("/dev/" + device)): | ||
return True | ||
return False | ||
return False |
Oops, something went wrong.