Permalink
Browse files

Prettify code according to PEP8.

Signed-off-by: Volker Theile <votdev@gmx.de>
  • Loading branch information...
votdev committed Nov 2, 2018
1 parent 7ae8c78 commit f182b72ff064a982948d89bc2b04dbb194899bb7
Showing with 3,382 additions and 3,261 deletions.
  1. +6 −1 .editorconfig
  2. +6 −1 deb/openmediavault.mk
  3. +44 −37 deb/openmediavault/srv/salt/_modules/omv.py
  4. +23 −22 deb/openmediavault/srv/salt/_runners/omv.py
  5. +47 −44 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/__init__.py
  6. +201 −196 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/collections.py
  7. +97 −95 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/confdbadm.py
  8. +795 −784 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/config/database.py
  9. +284 −281 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/config/datamodel.py
  10. +192 −192 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/config/object.py
  11. +75 −74 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/datamodel/datamodel.py
  12. +78 −77 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/datamodel/schema.py
  13. +3 −2 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/exceptions.py
  14. +13 −12 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/firstaid.py
  15. +467 −459 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/json/schema.py
  16. +41 −36 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/log.py
  17. +51 −47 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/mkrrdgraph.py
  18. +67 −66 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/productinfo.py
  19. +46 −44 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/rpc.py
  20. +61 −59 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/settings.py
  21. +53 −48 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/string.py
  22. +25 −20 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/subprocess.py
  23. +173 −167 deb/openmediavault/usr/lib/python3/dist-packages/openmediavault/systemd.py
  24. +38 −34 deb/openmediavault/usr/sbin/omv-confdbadm
  25. +47 −44 deb/openmediavault/usr/sbin/omv-firstaid
  26. +19 −17 deb/openmediavault/usr/sbin/omv-jsonprettify
  27. +83 −79 deb/openmediavault/usr/sbin/omv-mkrrdgraph
  28. +18 −9 deb/openmediavault/usr/sbin/omv-salt
  29. +56 −54 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/create.py
  30. +59 −57 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/delete.py
  31. +29 −27 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/exists.py
  32. +29 −27 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/list-ids.py
  33. +71 −68 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/migrate.py
  34. +54 −52 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/read.py
  35. +31 −29 deb/openmediavault/usr/share/openmediavault/confdbadm/commands.d/update.py
@@ -6,11 +6,16 @@ root = true
end_of_line = lf
insert_final_newline = true
[*.{js,py,php,inc,sh,xml,json,html,css}]
[*.{js,php,inc,sh,xml,json,html,css}]
charset = utf-8
indent_size = 4
indent_style = tab
[*.py]
charset = utf-8
indent_style = space
indent_size = 4
[*.sls]
indent_size = 2
indent_style = space
@@ -19,6 +19,8 @@
# You should have received a copy of the GNU General Public License
# along with OpenMediaVault. If not, see <http://www.gnu.org/licenses/>.
NUM_PROCESSORS := $(shell nproc)
OMV_PACKAGE := $(shell pwd | sed 's|.*/||')
OMV_POT_DIR := $(CURDIR)/usr/share/openmediavault/locale
OMV_POT_FILE := $(OMV_PACKAGE).pot
@@ -60,9 +62,12 @@ omv_build_doc: debian/doxygen.conf
mkdir -p debian/doxygen
doxygen $<
omv_beautify_py:
autopep8 --in-place --recursive --jobs $(NUM_PROCESSORS) .
source: clean
dpkg-buildpackage -S -us -uc
.PHONY: omv_tx_status omv_tx_pull_po omv_tx_push_pot
.PHONY: omv_build_pot omv_build_doc omv_clean_scm
.PHONY: source
.PHONY: omv_beautify_py source
@@ -29,54 +29,61 @@
import salt.utils.network
from salt.utils.decorators.jinja import jinja_filter
def get_config(id, identifier=None):
db = openmediavault.config.Database()
objs = db.get(id, identifier)
if isinstance(objs, list):
return [obj.get_dict() for obj in objs]
return objs.get_dict()
db = openmediavault.config.Database()
objs = db.get(id, identifier)
if isinstance(objs, list):
return [obj.get_dict() for obj in objs]
return objs.get_dict()
def get_config_by_filter(id, filter):
db = openmediavault.config.Database()
objs = db.get_by_filter(id, openmediavault.config.DatabaseFilter(filter))
if isinstance(objs, list):
return [obj.get_dict() for obj in objs]
return objs.get_dict()
db = openmediavault.config.Database()
objs = db.get_by_filter(id, openmediavault.config.DatabaseFilter(filter))
if isinstance(objs, list):
return [obj.get_dict() for obj in objs]
return objs.get_dict()
def get_sharedfolder_path(uuid):
sf_obj = get_config('conf.system.sharedfolder', uuid)
mp_obj = get_config('conf.system.filesystem.mountpoint',
sf_obj['mntentref'])
return os.path.join(mp_obj['dir'], sf_obj['reldirpath'])
sf_obj = get_config('conf.system.sharedfolder', uuid)
mp_obj = get_config('conf.system.filesystem.mountpoint',
sf_obj['mntentref'])
return os.path.join(mp_obj['dir'], sf_obj['reldirpath'])
def get_sharedfolder_name(uuid):
sf_obj = get_config('conf.system.sharedfolder', uuid)
return sf_obj['name']
sf_obj = get_config('conf.system.sharedfolder', uuid)
return sf_obj['name']
def get_sharedfolder_mount_dir(uuid):
sf_obj = get_config('conf.system.sharedfolder', uuid)
mp_obj = get_config('conf.system.filesystem.mountpoint',
sf_obj['mntentref'])
return mp_obj['dir']
sf_obj = get_config('conf.system.sharedfolder', uuid)
mp_obj = get_config('conf.system.filesystem.mountpoint',
sf_obj['mntentref'])
return mp_obj['dir']
def is_ipv6_enabled():
"""
Check whether IPv6 is enabled.
:return: Return True if IPv6 is enabled, otherwise False.
:rtype: bool
"""
if not os.path.exists('/proc/net/if_inet6'):
return False
with open('/proc/net/if_inet6') as f:
lines = f.readlines()
# Filter unwanted interfaces.
lines = [l for l in lines if not re.match(r'^\s+lo$', l)]
return len(lines) > 0
"""
Check whether IPv6 is enabled.
:return: Return True if IPv6 is enabled, otherwise False.
:rtype: bool
"""
if not os.path.exists('/proc/net/if_inet6'):
return False
with open('/proc/net/if_inet6') as f:
lines = f.readlines()
# Filter unwanted interfaces.
lines = [l for l in lines if not re.match(r'^\s+lo$', l)]
return len(lines) > 0
@jinja_filter('network_prefix_len')
def get_net_size(mask):
"""
Turns an IPv4 netmask into it's corresponding prefix length
(255.255.255.0 -> 24 as in 192.168.1.10/24).
"""
return salt.utils.network.get_net_size(mask)
"""
Turns an IPv4 netmask into it's corresponding prefix length
(255.255.255.0 -> 24 as in 192.168.1.10/24).
"""
return salt.utils.network.get_net_size(mask)
@@ -26,26 +26,27 @@
log = logging.getLogger(__name__)
def populate_pillar():
"""
Populate the pillar data.
"""
# Create the pillar containing the default values. Read them from the
# file /etc/default/openmediavault.
data = openmediavault.settings.Environment.as_dict()
filename = '/srv/pillar/omv/default.sls'
log.info('Writing {}'.format(filename))
with open(filename, 'w') as fd:
fd.write(yaml.dump({'default': data},
Dumper=yaml.SafeDumper,
default_flow_style=False))
# Create the pillar containing the product information.
prod_info = openmediavault.productinfo.ProductInfo()
data = prod_info.as_dict()
filename = '/srv/pillar/omv/productinfo.sls'
log.info('Writing {}'.format(filename))
with open(filename, 'w') as fd:
fd.write(yaml.dump({'productinfo': data},
Dumper=yaml.SafeDumper,
default_flow_style=False))
return True
"""
Populate the pillar data.
"""
# Create the pillar containing the default values. Read them from the
# file /etc/default/openmediavault.
data = openmediavault.settings.Environment.as_dict()
filename = '/srv/pillar/omv/default.sls'
log.info('Writing {}'.format(filename))
with open(filename, 'w') as fd:
fd.write(yaml.dump({'default': data},
Dumper=yaml.SafeDumper,
default_flow_style=False))
# Create the pillar containing the product information.
prod_info = openmediavault.productinfo.ProductInfo()
data = prod_info.as_dict()
filename = '/srv/pillar/omv/productinfo.sls'
log.info('Writing {}'.format(filename))
with open(filename, 'w') as fd:
fd.write(yaml.dump({'productinfo': data},
Dumper=yaml.SafeDumper,
default_flow_style=False))
return True
@@ -18,56 +18,59 @@
#
# You should have received a copy of the GNU General Public License
# along with OpenMediaVault. If not, see <http://www.gnu.org/licenses/>.
__all__ = [ "bool", "getenv", "setenv" ]
__all__ = ["bool", "getenv", "setenv"]
import re
import openmediavault.settings
def bool(x):
"""
Get the boolean value of a variable. A boolean True will be returned for
the values 1, '1', 'on', 'yes', 'y' and 'true'.
>>> assert bool(True) == True
>>> assert bool("1") == True
>>> assert bool("true") == True
>>> assert bool("no") == False
>>> assert bool("False") == False
>>> assert bool(False) == False
"""
if type(x) == bool:
return x
if str(x).lower() in ["1", "on", "yes", "y", "true", "t"]:
return True
return False
"""
Get the boolean value of a variable. A boolean True will be returned for
the values 1, '1', 'on', 'yes', 'y' and 'true'.
>>> assert bool(True) == True
>>> assert bool("1") == True
>>> assert bool("true") == True
>>> assert bool("no") == False
>>> assert bool("False") == False
>>> assert bool(False) == False
"""
if type(x) == bool:
return x
if str(x).lower() in ["1", "on", "yes", "y", "true", "t"]:
return True
return False
def getenv(key, default=None, type="str"):
"""
Get an environment variable, return None if it doesn't exist.
:param key: The name of the variable.
:param default: The optional second argument can specify an alternate
default. Defaults to None.
:param type: The type in which the result value is converted.
Defaults to 'str'.
:returns: Returns the value of the requested environment variable.
"""
value = openmediavault.settings.Environment.get_str(key, default)
if "str" == type:
pass
elif "int" == type:
value = int(value)
elif "float" == type:
value = float(value)
elif "bool" == type:
value = openmediavault.bool(value)
else:
raise TypeError("Converting to '%s' is not supported." % type)
return value;
"""
Get an environment variable, return None if it doesn't exist.
:param key: The name of the variable.
:param default: The optional second argument can specify an alternate
default. Defaults to None.
:param type: The type in which the result value is converted.
Defaults to 'str'.
:returns: Returns the value of the requested environment variable.
"""
value = openmediavault.settings.Environment.get_str(key, default)
if "str" == type:
pass
elif "int" == type:
value = int(value)
elif "float" == type:
value = float(value)
elif "bool" == type:
value = openmediavault.bool(value)
else:
raise TypeError("Converting to '%s' is not supported." % type)
return value
def setenv(key, value):
"""
Set an environment variable.
:param key: The name of the variable.
:param value: The value to set.
:returns: Returns the old value if it exists, otherwise None.
"""
return openmediavault.settings.Environment.set(key, value)
"""
Set an environment variable.
:param key: The name of the variable.
:param value: The value to set.
:returns: Returns the old value if it exists, otherwise None.
"""
return openmediavault.settings.Environment.set(key, value)
Oops, something went wrong.

0 comments on commit f182b72

Please sign in to comment.