mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-27 05:06:39 +00:00
genrandconfig: replace kwargs with explicit arguments
kwargs is a left-over from the use of docopt, it's better to use argparse's Namespace object directly. In addition, most functions use just one or two fields of args, so these can just as well be passed directly as arguments to the function. Particularly for outputdir it doesn't make sense to reconstruct it all the time. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
This commit is contained in:
parent
30f7fec0a8
commit
22978c7399
@ -125,13 +125,12 @@ class SystemInfo:
|
|||||||
return not missing_requirements
|
return not missing_requirements
|
||||||
|
|
||||||
|
|
||||||
def get_toolchain_configs(**kwargs):
|
def get_toolchain_configs(toolchains_url):
|
||||||
"""Fetch and return the possible toolchain configurations
|
"""Fetch and return the possible toolchain configurations
|
||||||
|
|
||||||
This function returns an array of toolchain configurations. Each
|
This function returns an array of toolchain configurations. Each
|
||||||
toolchain configuration is itself an array of lines of the defconfig.
|
toolchain configuration is itself an array of lines of the defconfig.
|
||||||
"""
|
"""
|
||||||
toolchains_url = kwargs['toolchains_url']
|
|
||||||
|
|
||||||
with urlopen_closing(toolchains_url) as r:
|
with urlopen_closing(toolchains_url) as r:
|
||||||
toolchains_csv = decode_byte_list(r.readlines())
|
toolchains_csv = decode_byte_list(r.readlines())
|
||||||
@ -172,19 +171,14 @@ def get_toolchain_configs(**kwargs):
|
|||||||
return configs
|
return configs
|
||||||
|
|
||||||
|
|
||||||
def is_toolchain_usable(**kwargs):
|
def is_toolchain_usable(outputdir, config):
|
||||||
"""Check if the toolchain is actually usable."""
|
"""Check if the toolchain is actually usable."""
|
||||||
|
|
||||||
idir = "instance-%d" % kwargs['instance']
|
|
||||||
sysinfo = kwargs['sysinfo']
|
|
||||||
log = kwargs['log']
|
|
||||||
|
|
||||||
outputdir = os.path.join(idir, "output")
|
|
||||||
with open(os.path.join(outputdir, ".config")) as configf:
|
with open(os.path.join(outputdir, ".config")) as configf:
|
||||||
configlines = configf.readlines()
|
configlines = configf.readlines()
|
||||||
|
|
||||||
# Check that the toolchain configuration is still present
|
# Check that the toolchain configuration is still present
|
||||||
for toolchainline in kwargs['config']:
|
for toolchainline in config:
|
||||||
if toolchainline not in configlines:
|
if toolchainline not in configlines:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -203,7 +197,7 @@ def is_toolchain_usable(**kwargs):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def fixup_config(**kwargs):
|
def fixup_config(outputdir, sysinfo):
|
||||||
"""Finalize the configuration and reject any problematic combinations
|
"""Finalize the configuration and reject any problematic combinations
|
||||||
|
|
||||||
This function returns 'True' when the configuration has been
|
This function returns 'True' when the configuration has been
|
||||||
@ -212,10 +206,6 @@ def fixup_config(**kwargs):
|
|||||||
generated).
|
generated).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
idir = "instance-%d" % kwargs['instance']
|
|
||||||
sysinfo = kwargs['sysinfo']
|
|
||||||
|
|
||||||
outputdir = os.path.join(idir, "output")
|
|
||||||
with open(os.path.join(outputdir, ".config")) as configf:
|
with open(os.path.join(outputdir, ".config")) as configf:
|
||||||
configlines = configf.readlines()
|
configlines = configf.readlines()
|
||||||
|
|
||||||
@ -334,7 +324,7 @@ def fixup_config(**kwargs):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def gen_config(**kwargs):
|
def gen_config(args):
|
||||||
"""Generate a new random configuration
|
"""Generate a new random configuration
|
||||||
|
|
||||||
This function generates the configuration, by choosing a random
|
This function generates the configuration, by choosing a random
|
||||||
@ -342,8 +332,7 @@ def gen_config(**kwargs):
|
|||||||
packages.
|
packages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
idir = "instance-%d" % kwargs['instance']
|
idir = "instance-%d" % args.instance
|
||||||
log = kwargs['log']
|
|
||||||
|
|
||||||
# We need the absolute path to use with O=, because the relative
|
# We need the absolute path to use with O=, because the relative
|
||||||
# path to the output directory here is not relative to the
|
# path to the output directory here is not relative to the
|
||||||
@ -352,11 +341,11 @@ def gen_config(**kwargs):
|
|||||||
outputdir = os.path.abspath(os.path.join(idir, "output"))
|
outputdir = os.path.abspath(os.path.join(idir, "output"))
|
||||||
srcdir = os.path.join(idir, "buildroot")
|
srcdir = os.path.join(idir, "buildroot")
|
||||||
|
|
||||||
log_write(log, "INFO: generate the configuration")
|
log_write(args.log, "INFO: generate the configuration")
|
||||||
|
|
||||||
# Select a random toolchain configuration
|
# Select a random toolchain configuration
|
||||||
try:
|
try:
|
||||||
configs = get_toolchain_configs(**kwargs)
|
configs = get_toolchain_configs(args.toolchains_url)
|
||||||
except Exception:
|
except Exception:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@ -390,10 +379,10 @@ def gen_config(**kwargs):
|
|||||||
"olddefconfig"],
|
"olddefconfig"],
|
||||||
stdout=devnull, stderr=devnull)
|
stdout=devnull, stderr=devnull)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
log_write(log, "ERROR: cannot oldconfig")
|
log_write(args.log, "ERROR: cannot oldconfig")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
if not is_toolchain_usable(config=config, **kwargs):
|
if not is_toolchain_usable(outputdir, config):
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# Now, generate the random selection of packages, and fixup
|
# Now, generate the random selection of packages, and fixup
|
||||||
@ -403,7 +392,7 @@ def gen_config(**kwargs):
|
|||||||
bounded_loop = 100
|
bounded_loop = 100
|
||||||
while True:
|
while True:
|
||||||
if bounded_loop == 0:
|
if bounded_loop == 0:
|
||||||
log_write(log, "ERROR: cannot generate random configuration after 100 iterations")
|
log_write(args.log, "ERROR: cannot generate random configuration after 100 iterations")
|
||||||
return -1
|
return -1
|
||||||
bounded_loop -= 1
|
bounded_loop -= 1
|
||||||
ret = subprocess.call(["make", "O=%s" % outputdir, "-C", srcdir,
|
ret = subprocess.call(["make", "O=%s" % outputdir, "-C", srcdir,
|
||||||
@ -411,23 +400,23 @@ def gen_config(**kwargs):
|
|||||||
"randpackageconfig"],
|
"randpackageconfig"],
|
||||||
stdout=devnull, stderr=devnull)
|
stdout=devnull, stderr=devnull)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
log_write(log, "ERROR: cannot generate random configuration")
|
log_write(args.log, "ERROR: cannot generate random configuration")
|
||||||
return -1
|
return -1
|
||||||
if fixup_config(**kwargs):
|
if fixup_config(outputdir, args.sysinfo):
|
||||||
break
|
break
|
||||||
|
|
||||||
ret = subprocess.call(["make", "O=%s" % outputdir, "-C", srcdir,
|
ret = subprocess.call(["make", "O=%s" % outputdir, "-C", srcdir,
|
||||||
"olddefconfig"],
|
"olddefconfig"],
|
||||||
stdout=devnull, stderr=devnull)
|
stdout=devnull, stderr=devnull)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
log_write(log, "ERROR: cannot oldconfig")
|
log_write(args.log, "ERROR: cannot oldconfig")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
ret = subprocess.call(["make", "O=%s" % outputdir, "-C", srcdir,
|
ret = subprocess.call(["make", "O=%s" % outputdir, "-C", srcdir,
|
||||||
"savedefconfig"],
|
"savedefconfig"],
|
||||||
stdout=devnull, stderr=devnull)
|
stdout=devnull, stderr=devnull)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
log_write(log, "ERROR: cannot savedefconfig")
|
log_write(args.log, "ERROR: cannot savedefconfig")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -457,8 +446,7 @@ if __name__ == '__main__':
|
|||||||
# gen_config expects "buildroot" directory under idir
|
# gen_config expects "buildroot" directory under idir
|
||||||
os.symlink("..", os.path.join(idir, "buildroot"))
|
os.symlink("..", os.path.join(idir, "buildroot"))
|
||||||
|
|
||||||
# gen_config expects a dict, but args is a class object
|
ret = gen_config(args)
|
||||||
ret = gen_config(**args.__dict__)
|
|
||||||
|
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
parser.exit(1)
|
parser.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user