Debian Codegraph @

btrfs/__init__.py

raw symbols SCIP
1 # Copyright (C) 2016 Hans van Kranenburg <[email protected]>
2 #
3 # This file is part of the python-btrfs module.
4 #
5 # python-btrfs is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # python-btrfs is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with python-btrfs. If not, see <http://www.gnu.org/licenses/>.
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 # noqa
25 from btrfs.ctree import ( # noqa
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 # noqa
34 import btrfs.ioctl # noqa
35 import btrfs.utils # noqa
36 import btrfs.crc32c # noqa
37 import btrfs.free_space_tree # noqa
38 import btrfs.volumes # noqa
39 import btrfs.fs_usage # noqa
40 from btrfs.version import __version__ # noqa
41
42
43 # Classes in our modules can define a _pretty_properties class method that
44 # returns hints for properties for the pretty printer that they want to have
45 # added dynamically.
46 #
47 # Each value in the list is a tuple containing two values:
48 # * The function that needs to be run to get the pretty string representation.
49 # * The name of the attribute whose value needs to be fed to that function.
50 #
51 # The helper functions and pretty printer itself can be found in btrfs.utils.
52 #
53 # After importing all modules, we look around for classes and gather all info.
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()