Fix mutable default arguments

https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
This commit is contained in:
Dylan Taylor 2021-05-15 15:24:34 -04:00
parent f7642786c9
commit 96a48664e2
3 changed files with 14 additions and 4 deletions

View File

@ -89,7 +89,9 @@ class sys_command:
Stolen from archinstall_gui
"""
def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars={}, *args, **kwargs):
def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars=None, *args, **kwargs):
if environment_vars is None:
environment_vars = {}
kwargs.setdefault("worker_id", gen_uid())
kwargs.setdefault("emulate", False)
kwargs.setdefault("suppress_errors", False)

View File

@ -34,7 +34,11 @@ class Installer:
"""
def __init__(self, target, *, base_packages=__packages__[:3], kernels=['linux']):
def __init__(self, target, *, base_packages=None, kernels=None):
if base_packages is None:
base_packages = __packages__[:3]
if kernels is None:
kernels = ['linux']
self.target = target
self.init_time = time.strftime('%Y-%m-%d_%H-%M-%S')
self.milliseconds = int(str(time.time()).split('.')[1])
@ -476,7 +480,9 @@ class Installer:
sudoers.write(f'{"%" if group else ""}{entity} ALL=(ALL) ALL\n')
return True
def user_create(self, user: str, password=None, groups=[], sudo=False):
def user_create(self, user: str, password=None, groups=None, sudo=False):
if groups is None:
groups = []
self.log(f'Creating user {user}', level=logging.INFO)
o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.target} useradd -m -G wheel {user}'))
if password:

View File

@ -163,8 +163,10 @@ class Script:
class Profile(Script):
def __init__(self, installer, path, args={}):
def __init__(self, installer, path, args=None):
super(Profile, self).__init__(path, installer)
if args is None:
args = {}
def __dump__(self, *args, **kwargs):
return {'path': self.path}