| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import inspect |
| 19 |
import sys |
| 20 |
if sys.version_info.major < 3: |
| 21 |
raise ImportError("This library is not compatible with Python 2 any more, sorry.") |
| 22 |
|
| 23 |
|
| 24 |
from btrfs.ctree import FileSystem |
| 25 |
from btrfs.ctree import ( |
| 26 |
BLOCK_GROUP_DATA, BLOCK_GROUP_SYSTEM, BLOCK_GROUP_METADATA, |
| 27 |
SPACE_INFO_GLOBAL_RSV, BLOCK_GROUP_TYPE_MASK, |
| 28 |
BLOCK_GROUP_RAID0, BLOCK_GROUP_RAID1, BLOCK_GROUP_RAID5, |
| 29 |
BLOCK_GROUP_RAID1C3, BLOCK_GROUP_RAID1C4, |
| 30 |
BLOCK_GROUP_RAID6, BLOCK_GROUP_DUP, BLOCK_GROUP_RAID10, |
| 31 |
BLOCK_GROUP_SINGLE, BLOCK_GROUP_PROFILE_MASK, |
| 32 |
) |
| 33 |
import btrfs.ctree |
| 34 |
import btrfs.ioctl |
| 35 |
import btrfs.utils |
| 36 |
import btrfs.crc32c |
| 37 |
import btrfs.free_space_tree |
| 38 |
import btrfs.volumes |
| 39 |
import btrfs.fs_usage |
| 40 |
from btrfs.version import __version__ |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
def _generate_pretty_properties(): |
| 55 |
def pretty_property_factory(cls, fn, attribute_name): |
| 56 |
def property_fn(self): |
| 57 |
return fn(getattr(self, attribute_name)) |
| 58 |
return property_fn |
| 59 |
|
| 60 |
for module in [ |
| 61 |
btrfs.ctree, |
| 62 |
btrfs.ioctl, |
| 63 |
btrfs.fs_usage, |
| 64 |
]: |
| 65 |
for name, cls in inspect.getmembers( |
| 66 |
module, |
| 67 |
lambda member: inspect.isclass(member) and member.__module__ == module.__name__ |
| 68 |
): |
| 69 |
try: |
| 70 |
hints = cls._pretty_properties() |
| 71 |
except AttributeError: |
| 72 |
continue |
| 73 |
for fn, attribute_name in hints: |
| 74 |
setattr(cls, '{}_str'.format(attribute_name), |
| 75 |
property(pretty_property_factory(cls, fn, attribute_name), None, |
| 76 |
doc="Pretty string representation for the {} attribute.".format( |
| 77 |
attribute_name))) |
| 78 |
|
| 79 |
|
| 80 |
_generate_pretty_properties() |