From d7d85c7d9df4d985ce00d627553c79d6a9c612c3 Mon Sep 17 00:00:00 2001 From: brent s Date: Wed, 11 Dec 2019 04:33:15 -0500 Subject: [PATCH] future proofing is good, but... since print() was made a function in py3, i can predict at some point that return will be made a func as well. sure, good. but "return()" *currently* returns an empty tuple. We want to explicitly return None for testing purposes. --- aif/config/parser.py | 26 +++++++++++++------------- aif/disk/block.py | 16 ++++++++-------- aif/disk/block_fallback.py | 14 +++++++------- aif/disk/filesystem.py | 12 ++++++------ aif/disk/filesystem_fallback.py | 12 ++++++------ aif/disk/luks.py | 22 +++++++++++----------- aif/disk/luks_fallback.py | 22 +++++++++++----------- aif/disk/lvm.py | 32 ++++++++++++++++---------------- aif/disk/lvm_fallback.py | 32 ++++++++++++++++---------------- aif/disk/mdadm.py | 18 +++++++++--------- aif/disk/mdadm_fallback.py | 18 +++++++++--------- aif/network/_common.py | 12 ++++++------ aif/network/netctl.py | 6 +++--- aif/network/networkd.py | 10 +++++----- aif/network/networkmanager.py | 8 ++++---- aif/system/__init__.py | 2 +- aif/system/console.py | 2 +- aif/system/locales.py | 8 ++++---- aif/system/services.py | 2 +- aif/system/users.py | 24 ++++++++++++------------ aif/utils/__init__.py | 2 +- aif/utils/file_handler.py | 2 +- aif/utils/gpg_handler.py | 8 ++++---- extras/genPSK.py | 2 +- 24 files changed, 156 insertions(+), 156 deletions(-) diff --git a/aif/config/parser.py b/aif/config/parser.py index 86b3981..ed9d24c 100644 --- a/aif/config/parser.py +++ b/aif/config/parser.py @@ -26,11 +26,11 @@ class Config(object): if validate: self.validate() self.pythonize() - return() + return(None) def fetch(self): # Just a fail-safe; this is overridden by specific subclasses. pass - return() + return(None) def getXSD(self, xsdpath = None): if not xsdpath: @@ -62,7 +62,7 @@ class Config(object): raw_xsd = req.content base_url = os.path.split(req.url)[0] # This makes me feel dirty. self.xsd = etree.XMLSchema(etree.XML(raw_xsd, base_url = base_url)) - return() + return(None) def parseRaw(self, parser = None): # self.xml = etree.parse(self.raw, parser = parser) @@ -74,7 +74,7 @@ class Config(object): self.tree.xinclude() self.namespaced_tree.xinclude() self.stripNS() - return() + return(None) def populateDefaults(self): if not self.xsd: @@ -82,7 +82,7 @@ class Config(object): if not self.defaultsParser: self.defaultsParser = etree.XMLParser(schema = self.xsd, attribute_defaults = True) self.parseRaw(parser = self.defaultsParser) - return() + return(None) def pythonize(self, stripped = True, obj = 'tree'): # https://bugs.launchpad.net/lxml/+bug/1850221 @@ -90,11 +90,11 @@ class Config(object): self.obj = objectify.fromstring(strobj) objectify.annotate(self.obj) objectify.xsiannotate(self.obj) - return() + return(None) def removeDefaults(self): self.parseRaw() - return() + return(None) def stripNS(self, obj = None): # https://stackoverflow.com/questions/30232031/how-can-i-strip-namespaces-out-of-an-lxml-tree/30233635#30233635 @@ -110,7 +110,7 @@ class Config(object): return(obj) else: raise ValueError('Did not know how to parse obj parameter') - return() + return(None) def toString(self, stripped = False, obj = None): if isinstance(obj, (etree._Element, etree._ElementTree)): @@ -142,7 +142,7 @@ class Config(object): if not self.xsd: self.getXSD() self.xsd.assertValid(self.namespaced_tree) - return() + return(None) class LocalFile(Config): @@ -157,7 +157,7 @@ class LocalFile(Config): raise ValueError('{0} does not exist'.format(self.source)) with open(self.source, 'rb') as fh: self.raw = fh.read() - return() + return(None) class RemoteFile(Config): @@ -171,7 +171,7 @@ class RemoteFile(Config): if not r.ok(): raise RuntimeError('Could not download XML') self.raw = r.content - return() + return(None) class ConfigStr(Config): @@ -182,7 +182,7 @@ class ConfigStr(Config): def fetch(self): self.raw = self.source.encode('utf-8') - return() + return(None) class ConfigBin(Config): @@ -193,7 +193,7 @@ class ConfigBin(Config): def fetch(self): self.raw = self.source - return() + return(None) detector = {'raw': (re.compile(r'^\s*(?P<(\?xml|aif)\s+.*)\s*$', re.DOTALL | re.MULTILINE), ConfigStr), diff --git a/aif/disk/block.py b/aif/disk/block.py index 522b404..bf5cf35 100644 --- a/aif/disk/block.py +++ b/aif/disk/block.py @@ -86,7 +86,7 @@ class Partition(object): else: continue self.flags.append(_BlockDev.PartFlag(flag_id)) - return() + return(None) def _initFstype(self): _err = ('{0} is not a valid partition filesystem type; ' @@ -102,7 +102,7 @@ class Partition(object): raise ValueError(_err) if self.fs_type not in aif.constants.GPT_GUID_IDX.keys(): raise ValueError(_err) - return() + return(None) def format(self): # This is a safeguard. We do *not* want to partition a disk that is mounted. @@ -119,7 +119,7 @@ class Partition(object): if self.flags: for f in self.flags: _BlockDev.part.set_part_flag(self.device, self.devpath, f, True) - return() + return(None) # # def detect(self): @@ -155,7 +155,7 @@ class Disk(object): self.is_hiformatted = False self.is_partitioned = False self.partitions = [] - return() + return(None) def diskFormat(self): if self.is_lowformatted: @@ -170,7 +170,7 @@ class Disk(object): _BlockDev.part.create_table(self.devpath, self.table_type, True) self.is_lowformatted = True self.is_partitioned = False - return() + return(None) def getPartitions(self): # For GPT, this *technically* should be 34 -- or, more precisely, 2048 (see FAQ in manual), but the alignment @@ -196,11 +196,11 @@ class Disk(object): p = Partition(part, self.disk, start_sector, partnum, self.table_type, part_type = parttype) start_sector = p.end + 1 self.partitions.append(p) - return() + return(None) def partFormat(self): if self.is_partitioned: - return() + return(None) if not self.is_lowformatted: self.diskFormat() # This is a safeguard. We do *not* want to partition a disk that is mounted. @@ -208,7 +208,7 @@ class Disk(object): if not self.partitions: self.getPartitions() if not self.partitions: - return() + return(None) for p in self.partitions: p.format() p.is_hiformatted = True diff --git a/aif/disk/block_fallback.py b/aif/disk/block_fallback.py index d85e408..1783502 100644 --- a/aif/disk/block_fallback.py +++ b/aif/disk/block_fallback.py @@ -144,18 +144,18 @@ class Disk(object): self.is_hiformatted = False self.is_partitioned = False self.partitions = [] - return() + return(None) def diskFormat(self): if self.is_lowformatted: - return() + return(None) # This is a safeguard. We do *not* want to low-format a disk that is mounted. aif.utils.checkMounted(self.devpath) self.disk.deleteAllPartitions() self.disk.commit() self.is_lowformatted = True self.is_partitioned = False - return() + return(None) def getPartitions(self): # For GPT, this *technically* should be 34 -- or, more precisely, 2048 (see FAQ in manual), but the alignment @@ -181,11 +181,11 @@ class Disk(object): p = Partition(part, self.disk, start_sector, partnum, self.table_type, part_type = parttype) start_sector = p.end + 1 self.partitions.append(p) - return() + return(None) def partFormat(self): if self.is_partitioned: - return() + return(None) if not self.is_lowformatted: self.diskFormat() # This is a safeguard. We do *not* want to partition a disk that is mounted. @@ -193,11 +193,11 @@ class Disk(object): if not self.partitions: self.getPartitions() if not self.partitions: - return() + return(None) for p in self.partitions: self.disk.addPartition(partition = p, constraint = self.device.optimalAlignedConstraint) self.disk.commit() p.devpath = p.partition.path p.is_hiformatted = True self.is_partitioned = True - return() + return(None) diff --git a/aif/disk/filesystem.py b/aif/disk/filesystem.py index d49739c..56a49dd 100644 --- a/aif/disk/filesystem.py +++ b/aif/disk/filesystem.py @@ -56,7 +56,7 @@ class FS(object): cmd.append(self.devpath) subprocess.run(cmd) self.formatted = True - return() + return(None) class Mount(object): @@ -86,7 +86,7 @@ class Mount(object): def mount(self): if self.mounted: - return() + return(None) os.makedirs(self.target, exist_ok = True) opts = self._parseOpts() _BlockDev.fs.mount(self.source, @@ -94,21 +94,21 @@ class Mount(object): self.fs.fstype, (','.join(opts) if opts else None)) self.mounted = True - return() + return(None) def unmount(self, lazy = False, force = False): self.updateMount() if not self.mounted and not force: - return() + return(None) _BlockDev.fs.unmount(self.target, lazy, force) self.mounted = False - return() + return(None) def updateMount(self): if self.source in [p.device for p in psutil.disk_partitions(all = True)]: self.mounted = True else: self.mounted = False - return() + return(None) diff --git a/aif/disk/filesystem_fallback.py b/aif/disk/filesystem_fallback.py index ee1bfa3..2cd37a8 100644 --- a/aif/disk/filesystem_fallback.py +++ b/aif/disk/filesystem_fallback.py @@ -47,7 +47,7 @@ class FS(object): cmd.append(self.devpath) subprocess.run(cmd) self.formatted = True - return() + return(None) class Mount(object): @@ -76,7 +76,7 @@ class Mount(object): def mount(self): if self.mounted: - return() + return(None) os.makedirs(self.target, exist_ok = True) opts = self._parseOpts() # TODO: logging @@ -87,12 +87,12 @@ class Mount(object): cmd.extend([self.source, self.target]) subprocess.run(cmd) self.mounted = True - return() + return(None) def unmount(self, lazy = False, force = False): self.updateMount() if not self.mounted and not force: - return() + return(None) # TODO: logging cmd = ['/usr/bin/umount'] if lazy: @@ -102,11 +102,11 @@ class Mount(object): cmd.append(self.target) subprocess.run(cmd) self.mounted = False - return() + return(None) def updateMount(self): if self.source in [p.device for p in psutil.disk_partitions(all = True)]: self.mounted = True else: self.mounted = False - return() + return(None) diff --git a/aif/disk/luks.py b/aif/disk/luks.py index 2b2c884..b4255f6 100644 --- a/aif/disk/luks.py +++ b/aif/disk/luks.py @@ -40,7 +40,7 @@ class LuksSecretFile(LuksSecret): self.passphrase = secrets.token_bytes(self.size) if not isinstance(self.passphrase, bytes): self.passphrase = self.passphrase.encode('utf-8') - return() + return(None) class LUKS(object): @@ -72,7 +72,7 @@ class LUKS(object): '(aif.disk.luks.LuksSecretPassphrase or ' 'aif.disk.luks.LuksSecretFile)') self.secrets.append(secretobj) - return() + return(None) def createSecret(self, secrets_xml = None): if not secrets_xml: # Find all of them from self @@ -116,11 +116,11 @@ class LUKS(object): passphrase = None, bytesize = kf.attrib.get('size', 4096)) self.secrets.append(secretobj) - return() + return(None) def create(self): if self.created: - return() + return(None) if not self.secrets: raise RuntimeError('Cannot create a LUKS volume with no secrets added') for idx, secret in enumerate(self.secrets): @@ -138,28 +138,28 @@ class LUKS(object): self.secrets[0].passphrase, secret.passphrase) self.created = True - return() + return(None) def lock(self): if not self.created: raise RuntimeError('Cannot lock a LUKS volume before it is created') if self.locked: - return() + return(None) _BlockDev.crypto.luks_close(self.name) self.locked = True - return() + return(None) def unlock(self, passphrase = None): if not self.created: raise RuntimeError('Cannot unlock a LUKS volume before it is created') if not self.locked: - return() + return(None) _BlockDev.crypto.luks_open_blob(self.source, self.name, self.secrets[0].passphrase, False) # read-only self.locked = False - return() + return(None) def updateInfo(self): if self.locked: @@ -177,7 +177,7 @@ class LUKS(object): info[k] = v info['_cipher'] = '{cipher}-{mode}'.format(**info) self.info = info - return() + return(None) def writeConf(self, conf = '/etc/crypttab'): if not self.secrets: @@ -204,4 +204,4 @@ class LUKS(object): if luksinfo not in conflines: with open(conf, 'a') as fh: fh.write('{0}\n'.format(luksinfo)) - return() + return(None) diff --git a/aif/disk/luks_fallback.py b/aif/disk/luks_fallback.py index 0ab05cf..fbacfec 100644 --- a/aif/disk/luks_fallback.py +++ b/aif/disk/luks_fallback.py @@ -40,7 +40,7 @@ class LuksSecretFile(LuksSecret): self.passphrase = secrets.token_bytes(self.size) if not isinstance(self.passphrase, bytes): self.passphrase = self.passphrase.encode('utf-8') - return() + return(None) class LUKS(object): @@ -71,7 +71,7 @@ class LUKS(object): '(aif.disk.luks.LuksSecretPassphrase or ' 'aif.disk.luks.LuksSecretFile)') self.secrets.append(secretobj) - return() + return(None) def createSecret(self, secrets_xml = None): if not secrets_xml: # Find all of them from self @@ -115,11 +115,11 @@ class LUKS(object): passphrase = None, bytesize = kf.attrib.get('size', 4096)) self.secrets.append(secretobj) - return() + return(None) def create(self): if self.created: - return() + return(None) if not self.secrets: raise RuntimeError('Cannot create a LUKS volume with no secrets added') for idx, secret in enumerate(self.secrets): @@ -147,13 +147,13 @@ class LUKS(object): subprocess.run(cmd, input = self.secrets[0].passphrase) os.remove(tmpfile[1]) self.created = True - return() + return(None) def lock(self): if not self.created: raise RuntimeError('Cannot lock a LUKS volume before it is created') if self.locked: - return() + return(None) # TODO: logging cmd = ['cryptsetup', '--batch-mode', @@ -161,13 +161,13 @@ class LUKS(object): self.name] subprocess.run(cmd) self.locked = True - return() + return(None) def unlock(self, passphrase = None): if not self.created: raise RuntimeError('Cannot unlock a LUKS volume before it is created') if not self.locked: - return() + return(None) cmd = ['cryptsetup', '--batch-mode', 'luksOpen', @@ -176,7 +176,7 @@ class LUKS(object): self.name] subprocess.run(cmd, input = self.secrets[0].passphrase) self.locked = False - return() + return(None) def updateInfo(self): if self.locked: @@ -225,7 +225,7 @@ class LUKS(object): elif k == 'uuid': v = uuid.UUID(hex = v) self.info = info - return() + return(None) def writeConf(self, conf = '/etc/crypttab'): if not self.secrets: @@ -252,4 +252,4 @@ class LUKS(object): if luksinfo not in conflines: with open(conf, 'a') as fh: fh.write('{0}\n'.format(luksinfo)) - return() + return(None) diff --git a/aif/disk/lvm.py b/aif/disk/lvm.py index c905bbe..deba1d9 100644 --- a/aif/disk/lvm.py +++ b/aif/disk/lvm.py @@ -42,7 +42,7 @@ class PV(object): except _BlockDev.LVMError: self.meta = None self.is_pooled = False - return() + return(None) for k in dir(_meta): if k.startswith('_'): continue @@ -52,7 +52,7 @@ class PV(object): meta[k] = v self.meta = meta self.is_pooled = True - return() + return(None) def prepare(self): try: @@ -97,7 +97,7 @@ class PV(object): 0, opts) self._parseMeta() - return() + return(None) class VG(object): @@ -130,7 +130,7 @@ class VG(object): raise ValueError('pvobj must be of type aif.disk.lvm.PV') pvobj.prepare() self.pvs.append(pvobj) - return() + return(None) def create(self): if not self.pvs: @@ -149,7 +149,7 @@ class VG(object): pv._parseMeta() self.created = True self.updateInfo() - return() + return(None) def createLV(self, lv_xml = None): if not self.created: @@ -165,21 +165,21 @@ class VG(object): lv.create() # self.lvs.append(lv) self.updateInfo() - return() + return(None) def start(self): _BlockDev.lvm.vgactivate(self.name) self.updateInfo() - return() + return(None) def stop(self): _BlockDev.lvm.vgdeactivate(self.name) self.updateInfo() - return() + return(None) def updateInfo(self): if not self.created: - return() + return(None) _info = _BlockDev.lvm.vginfo(self.name) # TODO: parity with lvm_fallback.VG.updateInfo # key names currently (probably) don't match and need to confirm the information's all present @@ -192,7 +192,7 @@ class VG(object): v = getattr(_info, k) info[k] = v self.info = info - return() + return(None) class LV(object): @@ -247,7 +247,7 @@ class LV(object): target = 'B')) if self.size >= _sizes['total']: self.size = 0 - return() + return(None) def create(self): if not self.pvs: @@ -268,7 +268,7 @@ class LV(object): self.created = True self.updateInfo() self.vg.updateInfo() - return() + return(None) def start(self): _BlockDev.lvm.lvactivate(self.vg.name, @@ -276,18 +276,18 @@ class LV(object): True, None) self.updateInfo() - return() + return(None) def stop(self): _BlockDev.lvm.lvdeactivate(self.vg.name, self.name, None) self.updateInfo() - return() + return(None) def updateInfo(self): if not self.created: - return() + return(None) _info = _BlockDev.lvm.lvinfo(self.vg.name, self.name) # TODO: parity with lvm_fallback.LV.updateInfo # key names currently (probably) don't match and need to confirm the information's all present @@ -300,4 +300,4 @@ class LV(object): v = getattr(_info, k) info[k] = v self.info = info - return() + return(None) diff --git a/aif/disk/lvm_fallback.py b/aif/disk/lvm_fallback.py index 6f038e1..4e61719 100644 --- a/aif/disk/lvm_fallback.py +++ b/aif/disk/lvm_fallback.py @@ -43,7 +43,7 @@ class PV(object): if _meta.returncode != 0: self.meta = None self.is_pooled = False - return() + return(None) _meta = json.loads(_meta.stdout.decode('utf-8'))['report'][0]['pv'][0] for k, v in _meta.items(): # We *could* regex this but the pattern would be a little more complex than idea, @@ -64,7 +64,7 @@ class PV(object): meta[k] = v self.meta = meta self.is_pooled = True - return() + return(None) def prepare(self): if not self.meta: @@ -80,7 +80,7 @@ class PV(object): self.devpath] subprocess.run(cmd) self._parseMeta() - return() + return(None) class VG(object): @@ -113,7 +113,7 @@ class VG(object): raise ValueError('pvobj must be of type aif.disk.lvm.PV') pvobj.prepare() self.pvs.append(pvobj) - return() + return(None) def create(self): if not self.pvs: @@ -129,7 +129,7 @@ class VG(object): pv._parseMeta() self.created = True self.updateInfo() - return() + return(None) def createLV(self, lv_xml = None): if not self.created: @@ -145,7 +145,7 @@ class VG(object): lv.create() # self.lvs.append(lv) self.updateInfo() - return() + return(None) def start(self): cmd = ['vgchange', @@ -154,7 +154,7 @@ class VG(object): self.name] subprocess.run(cmd) self.updateInfo() - return() + return(None) def stop(self): cmd = ['vgchange', @@ -163,7 +163,7 @@ class VG(object): self.name] subprocess.run(cmd) self.updateInfo() - return() + return(None) def updateInfo(self): info = {} @@ -178,7 +178,7 @@ class VG(object): if _info.returncode != 0: self.info = None self.created = False - return() + return(None) _info = json.loads(_info.stdout.decode('utf-8'))['report'][0]['vg'][0] for k, v in _info.items(): # ints @@ -196,7 +196,7 @@ class VG(object): v = None info[k] = v self.info = info - return() + return(None) class LV(object): @@ -250,7 +250,7 @@ class LV(object): target = 'B')) if self.size >= _sizes['total']: self.size = 0 - return() + return(None) def create(self): if not self.pvs: @@ -267,7 +267,7 @@ class LV(object): self.created = True self.updateInfo() self.vg.updateInfo() - return() + return(None) def start(self): cmd = ['lvchange', @@ -276,7 +276,7 @@ class LV(object): self.qualified_name] subprocess.run(cmd) self.updateInfo() - return() + return(None) def stop(self): cmd = ['lvchange', @@ -285,7 +285,7 @@ class LV(object): self.qualified_name] subprocess.run(cmd) self.updateInfo() - return() + return(None) def updateInfo(self): info = {} @@ -300,7 +300,7 @@ class LV(object): if _info.returncode != 0: self.info = None self.created = False - return() + return(None) _info = json.loads(_info.stdout.decode('utf-8'))['report'][0]['vg'][0] for k, v in _info.items(): # ints @@ -330,4 +330,4 @@ class LV(object): v = None info[k] = v self.info = info - return() + return(None) diff --git a/aif/disk/mdadm.py b/aif/disk/mdadm.py index 072f503..b391aaa 100644 --- a/aif/disk/mdadm.py +++ b/aif/disk/mdadm.py @@ -44,7 +44,7 @@ class Member(object): except _BlockDev.MDRaidError: self.is_superblocked = False self.superblock = None - return() + return(None) for k in dir(_block): if k.startswith('_'): continue @@ -60,7 +60,7 @@ class Member(object): block[k] = v self.superblock = block self.is_superblocked = True - return() + return(None) def prepare(self): try: @@ -69,7 +69,7 @@ class Member(object): pass _BlockDev.md.destroy(self.devpath) self._parseDeviceBlock() - return() + return(None) class Array(object): @@ -121,7 +121,7 @@ class Array(object): raise ValueError('memberobj must be of type aif.disk.mdadm.Member') memberobj.prepare() self.members.append(memberobj) - return() + return(None) def create(self): if not self.members: @@ -147,7 +147,7 @@ class Array(object): self.writeConf() self.devpath = self.info['device'] self.state = 'new' - return() + return(None) def start(self, scan = False): if not any((self.members, self.devpath)): @@ -162,12 +162,12 @@ class Array(object): True, None) self.state = 'assembled' - return() + return(None) def stop(self): _BlockDev.md.deactivate(self.name) self.state = 'disassembled' - return() + return(None) def updateStatus(self): _status = _BlockDev.md.detail(self.name) @@ -189,7 +189,7 @@ class Array(object): v = uuid.UUID(hex = v) info[k] = v self.info = info - return() + return(None) def writeConf(self, conf = '/etc/mdadm.conf'): conf = os.path.realpath(conf) @@ -214,4 +214,4 @@ class Array(object): if nodev: with open(conf, 'a') as fh: fh.write('{0}\n'.format(arrayinfo)) - return() + return(None) diff --git a/aif/disk/mdadm_fallback.py b/aif/disk/mdadm_fallback.py index daa90e6..05bd844 100644 --- a/aif/disk/mdadm_fallback.py +++ b/aif/disk/mdadm_fallback.py @@ -49,7 +49,7 @@ class Member(object): # TODO: logging? self.is_superblocked = False self.superblock = None - return() + return(None) block = {} for idx, line in enumerate(super.stdout.decode('utf-8').splitlines()): line = line.strip() @@ -116,7 +116,7 @@ class Member(object): block[k] = v self.superblock = block self.is_superblocked = True - return() + return(None) def prepare(self): if self.is_superblocked: @@ -124,7 +124,7 @@ class Member(object): subprocess.run(['mdadm', '--misc', '--zero-superblock', self.devpath]) self.is_superblocked = False self._parseDeviceBlock() - return() + return(None) class Array(object): @@ -174,7 +174,7 @@ class Array(object): raise ValueError('memberobj must be of type aif.disk.mdadm.Member') memberobj.prepare() self.members.append(memberobj) - return() + return(None) def create(self): if not self.members: @@ -199,7 +199,7 @@ class Array(object): self.updateStatus() self.writeConf() self.state = 'new' - return() + return(None) def start(self, scan = False): if not any((self.members, self.devpath)): @@ -214,13 +214,13 @@ class Array(object): subprocess.run(cmd) self.updateStatus() self.state = 'assembled' - return() + return(None) def stop(self): # TODO: logging subprocess.run(['mdadm', '--stop', self.devpath]) self.state = 'disassembled' - return() + return(None) def updateStatus(self): _info = mdstat.parse() @@ -228,7 +228,7 @@ class Array(object): if k != self.name: del(_info['devices'][k]) self.info = copy.deepcopy(_info) - return() + return(None) def writeConf(self, conf = '/etc/mdadm.conf'): conf = os.path.realpath(conf) @@ -250,4 +250,4 @@ class Array(object): if nodev: with open(conf, 'a') as fh: fh.write('{0}\n'.format(arrayinfo)) - return() + return(None) diff --git a/aif/network/_common.py b/aif/network/_common.py index ba61e3e..5d17e92 100644 --- a/aif/network/_common.py +++ b/aif/network/_common.py @@ -204,19 +204,19 @@ class BaseConnection(object): addrset = convertIpTuples(a) if addrset not in self.addrs[addrtype]: self.addrs[addrtype].append(addrset) - return() + return(None) def _initCfg(self): # A dummy method; this is overridden by the subclasses. # It's honestly here to make my IDE stop complaining. :) pass - return() + return(None) def _initConnCfg(self): # A dummy method; this is overridden by the subclasses. # It's honestly here to make my IDE stop complaining. :) pass - return() + return(None) def _initResolvers(self): resolvers_xml = self.xml.find('resolvers') @@ -225,7 +225,7 @@ class BaseConnection(object): resolver = ipaddress.ip_address(r.text.strip()) if resolver not in self.resolvers: self.resolvers.append(resolver) - return() + return(None) def _initRoutes(self): routes_xml = self.xml.find('routes') @@ -235,9 +235,9 @@ class BaseConnection(object): addrset = convertIpTuples(a) if addrset not in self.routes[addrtype]: self.routes[addrtype].append(addrset) - return() + return(None) def _writeConnCfg(self, chroot_base): # Dummy method. pass - return() + return(None) diff --git a/aif/network/netctl.py b/aif/network/netctl.py index 93ed895..1d42841 100644 --- a/aif/network/netctl.py +++ b/aif/network/netctl.py @@ -105,7 +105,7 @@ class Connection(_common.BaseConnection): # Weird hack because netctl doesn't natively support assigning add'l addrs to a dhcp/dhcp6/slaac iface. if 'IPCustom' in self._cfg['BASE'].keys() and isinstance(self._cfg['BASE']['IPCustom'], list): self._cfg['BASE']['IPCustom'] = '({0})'.format(' '.join(self._cfg['BASE']['IPCustom'])) - return() + return(None) def writeConf(self, chroot_base): systemd_base = os.path.join(chroot_base, 'etc', 'systemd', 'system') @@ -260,7 +260,7 @@ class Connection(_common.BaseConnection): fh.write(line) os.chmod(netctl_file, 0o0600) os.chown(netctl_file, 0, 0) - return() + return(None) class Ethernet(Connection): @@ -300,4 +300,4 @@ class Wireless(Connection): # if crypto['type'] in ('wep', 'wpa', 'wpa2', 'wpa3'): if crypto['type'] in ('wpa', 'wpa2'): self._cfg['BASE']['Key'] = crypto['auth']['psk'] - return() + return(None) diff --git a/aif/network/networkd.py b/aif/network/networkd.py index 791e759..c4e2e93 100644 --- a/aif/network/networkd.py +++ b/aif/network/networkd.py @@ -90,13 +90,13 @@ class Connection(_common.BaseConnection): if 'IPv6AcceptRA' not in self._cfg.keys(): self._cfg['IPv6AcceptRA'] = {'UseDNS': ('true' if self.auto['resolvers']['ipv6'] else 'false')} self._initConnCfg() - return() + return(None) def _initJ2(self): self.j2_env = jinja2.Environment(loader = jinja2.FileSystemLoader(searchpath = './')) self.j2_env.filters.update(aif.utils.j2_filters) self.j2_tpl = self.j2_env.get_template('networkd.conf.j2') - return() + return(None) def writeConf(self, chroot_base): cfgroot = os.path.join(chroot_base, 'etc', 'systemd', 'network') @@ -109,7 +109,7 @@ class Connection(_common.BaseConnection): os.chmod(cfgfile, 0o0644) os.chown(cfgfile, 0, 0) self._writeConnCfg(chroot_base) - return() + return(None) class Ethernet(Connection): @@ -155,7 +155,7 @@ class Wireless(Connection): 'multi-user.target.wants/' 'wpa_supplicant@' '{0}.service').format(self.device) - return() + return(None) def _writeConnCfg(self, chroot_base): cfgroot = os.path.join(chroot_base, 'etc', 'wpa_supplicant') @@ -167,4 +167,4 @@ class Wireless(Connection): fh.write(self.wpasupp_tpl.render(wpa = self._wpasupp)) os.chown(cfgfile, 0, 0) os.chmod(cfgfile, 0o0640) - return() + return(None) diff --git a/aif/network/networkmanager.py b/aif/network/networkmanager.py index 7a99271..a4a2124 100644 --- a/aif/network/networkmanager.py +++ b/aif/network/networkmanager.py @@ -89,7 +89,7 @@ class Connection(_common.BaseConnection): str(net.prefixlen), str(gw)) self._initConnCfg() - return() + return(None) def writeConf(self, chroot_base): cfgroot = os.path.join(chroot_base, 'etc', 'NetworkManager') @@ -109,7 +109,7 @@ class Connection(_common.BaseConnection): os.chmod(cfgroot, 0o0755) os.chmod(cfgdir, 0o0700) os.chmod(cfgpath, 0o0600) - return() + return(None) class Ethernet(Connection): @@ -120,7 +120,7 @@ class Ethernet(Connection): def _initConnCfg(self): self._cfg[self.connection_type] = {'mac-address-blacklist': ''} - return() + return(None) class Wireless(Connection): @@ -153,4 +153,4 @@ class Wireless(Connection): # if crypto['type'] in ('wep', 'wpa', 'wpa2', 'wpa3'): if crypto['type'] in ('wpa', 'wpa2'): self._cfg['wifi-security']['psk'] = crypto['auth']['psk'] - return() + return(None) diff --git a/aif/system/__init__.py b/aif/system/__init__.py index 6f339b1..08b7c0b 100644 --- a/aif/system/__init__.py +++ b/aif/system/__init__.py @@ -18,4 +18,4 @@ class Sys(object): self.tz.apply() self.user.writeConf() self.services.apply() - return() + return(None) diff --git a/aif/system/console.py b/aif/system/console.py index 7cc5774..8de1cf6 100644 --- a/aif/system/console.py +++ b/aif/system/console.py @@ -96,4 +96,4 @@ class Console(object): fh.write(line) os.chmod(cfg, 0o0644) os.chown(cfg, 0, 0) - return() + return(None) diff --git a/aif/system/locales.py b/aif/system/locales.py index 80ac749..23abcfa 100644 --- a/aif/system/locales.py +++ b/aif/system/locales.py @@ -31,7 +31,7 @@ class Locale(object): self.userlocales.append(locale) if not self.userlocales: self.userlocales = ['en_US', 'en_US.UTF-8'] - return() + return(None) def _verify(self): localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen') # This *should* be brand new. @@ -50,7 +50,7 @@ class Locale(object): sysl = set(self.syslocales.keys()) if (userl - sysl): raise ValueError('non-existent locale specified') - return() + return(None) def writeConf(self): # We basically recreate locale-gen in python here, more or less. @@ -106,7 +106,7 @@ class Locale(object): fh.write(line) os.chmod(cfg, 0o0644) os.chown(cfg, 0, 0) - return() + return(None) class Timezone(object): @@ -127,4 +127,4 @@ class Timezone(object): if os.path.isfile(tzdestfile): os.remove(tzdestfile) os.symlink(tzsrcfile, tzdestfile) - return() + return(None) diff --git a/aif/system/services.py b/aif/system/services.py index 26a9032..6f495ed 100644 --- a/aif/system/services.py +++ b/aif/system/services.py @@ -57,4 +57,4 @@ class ServiceDB(object): else: if os.path.exists(dest_path): os.remove(dest_path) - return() + return(None) diff --git a/aif/system/users.py b/aif/system/users.py index a0305c5..5849b7b 100644 --- a/aif/system/users.py +++ b/aif/system/users.py @@ -61,7 +61,7 @@ class Group(object): (self.password.hash if self.password.hash else '!!'), # Password hash (if it has one) ','.join(self.admins), # Users with administrative control of group ','.join(self.members)] # Comma-separated members of group - return() + return(None) def parseGroupLine(self, line): groupdict = dict(zip(['name', 'password', 'gid', 'members'], @@ -71,7 +71,7 @@ class Group(object): self.members = set(members) self.gid = int(groupdict['gid']) self.name = groupdict['name'] - return() + return(None) def parseGshadowLine(self, line): groupdict = dict(zip(['name', 'password', 'admins', 'members'], @@ -85,7 +85,7 @@ class Group(object): self.admins = set(admins) if members: self.members = set(members) - return() + return(None) class Password(object): @@ -133,7 +133,7 @@ class Password(object): self.hash_type = re.sub(r'_crypt$', '', self._pass_context.identify(self.hash)) if not self.hash_type: warnings.warn('Could not determine hash type') - return() + return(None) class User(object): @@ -161,7 +161,7 @@ class User(object): def _initVals(self): if self.xml is None: # We manually assign these. - return() + return(None) self.name = self.xml.attrib['name'] # XML declared users are always new. self.new = True @@ -206,7 +206,7 @@ class User(object): g = Group(group_xml) g.members.add(self.name) self.groups.append(g) - return() + return(None) def genFileLine(self): if not all((self.uid, self.primary_group.gid)): @@ -230,7 +230,7 @@ class User(object): (str(self.inactive_period) if self.inactive_period else ''), # Password inactivity period (str((self.expire_date - _epoch).days) if self.expire_date else ''), # Expiration date ''] # "Reserved" - return() + return(None) def parseShadowLine(self, line): shadowdict = dict(zip(['name', 'password', 'last_change', 'minimum_age', 'maximum_age', 'warning_period', @@ -260,7 +260,7 @@ class User(object): for k in ('home', 'shell'): if userdict[k].strip() != '': setattr(self, k, userdict[k]) - return() + return(None) class UserDB(object): @@ -322,7 +322,7 @@ class UserDB(object): if k in self.login_defaults.keys(): v = self.login_defaults[k].lower() self.login_defaults[k] = (True if v == 'yes' else False) - return() + return(None) def _parseShadow(self): sys_shadow = {} @@ -364,7 +364,7 @@ class UserDB(object): rootuser = users['root'] rootuser.password = self.rootpass rootuser.password.detectHashType() - return() + return(None) def _parseXML(self): for user_xml in self.xml.findall('user'): @@ -393,7 +393,7 @@ class UserDB(object): if not g.create: u.groups[idx] = new_group[0] self.new_users.append(u) - return() + return(None) def getAvailUID(self, system = False): if not self.login_defaults: @@ -490,4 +490,4 @@ class UserDB(object): ('NOPASSWD: ' if not u.sudoPassword else ''))) os.chown(sudo_file, 0, 0) os.chmod(sudo_file, 0o0440) - return() + return(None) diff --git a/aif/utils/__init__.py b/aif/utils/__init__.py index 279fbea..07f1ee4 100644 --- a/aif/utils/__init__.py +++ b/aif/utils/__init__.py @@ -15,7 +15,7 @@ from . import hash_handler def checkMounted(devpath): if devpath in [p.device for p in psutil.disk_partitions(all = True)]: raise RuntimeError('{0} is mounted; we are cowardly refusing to destructive operations on it'.format(devpath)) - return() + return(None) def collapseKeys(d, keylist = None): diff --git a/aif/utils/file_handler.py b/aif/utils/file_handler.py index b2c0847..d10c699 100644 --- a/aif/utils/file_handler.py +++ b/aif/utils/file_handler.py @@ -40,4 +40,4 @@ class Directory(object): self.dirs.append(dirs) self.dirs.sort() self.files.sort() - return() + return(None) diff --git a/aif/utils/gpg_handler.py b/aif/utils/gpg_handler.py index 0dc23d4..70eb2f9 100644 --- a/aif/utils/gpg_handler.py +++ b/aif/utils/gpg_handler.py @@ -30,7 +30,7 @@ class GPG(object): self.primary_key = self.createKey('AIF-NG File Verification Key', sign = True, force = True) else: self.primary_key = self.getKey(self.primary_key, secret = True) - return() + return(None) def clean(self): # This is mostly just to cleanup the stuff we did before. @@ -39,7 +39,7 @@ class GPG(object): self.primary_key = None shutil.rmtree(self.homedir) self.gpg = None - return() + return(None) def createKey(self, userid, *args, **kwargs): # algorithm=None, expires_in=0, expires=True, sign=False, encrypt=False, certify=False, @@ -85,7 +85,7 @@ class GPG(object): except gpg.errors.KeyNotFound: key = None return(key) - return() + return(None) def getKeyFile(self, keyfile, keyring_import = False): keyfile = os.path.abspath(os.path.expanduser(keyfile)) @@ -115,7 +115,7 @@ class GPG(object): if not isinstance(keydata, list): keydata = [keydata] self.gpg.op_import_keys(keydata) - return() + return(None) def verifyData(self, data, keys = None, strict = False, detached = None, *args, **kwargs): results = {} diff --git a/extras/genPSK.py b/extras/genPSK.py index 32a9f25..f828a35 100755 --- a/extras/genPSK.py +++ b/extras/genPSK.py @@ -75,7 +75,7 @@ def main(): 'Please ensure you have provided the correct passphrase.')) psk = pskGen(args.ssid, args.passphrase) print('PSK for network "{0}": {1}'.format(args.ssid, psk)) - return() + return(None) if __name__ == '__main__':