Skip to content

Commit

Permalink
Adding support for secondary packages.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaudov, Stanislav Tomov committed Jun 15, 2020
1 parent 0de74db commit 8c632ab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
27 changes: 26 additions & 1 deletion code_manager/core/configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import os
import re
Expand Down Expand Up @@ -121,6 +122,26 @@ def resolve_nodes(self, config):


class ConfigurationAware:
@staticmethod
def _load_extra_pack(primary_config, config):
primary_config.setdefault('vars', {})
for var, value in config.get('vars', {}).items():
primary_config['vars'][var] = value

primary_config.setdefault('packages_list', {})
for group_name, group_list in config.get('packages_list', {}).items():
primary_config['packages_list'].setdefault(group_name, group_list)

primary_config.setdefault('debian_packages', {})
for list_name, list_list in config.get('debian_packages', {}).items():
primary_config['debian_packages'].setdefault(list_name, list_list)

primary_config.setdefault('packages', {})
for pack_name, pack_node in config.get('packages', {}).items():
primary_config['packages'].setdefault(pack_name, pack_node)

return primary_config

@staticmethod
def var(name):
if name in ConfigurationAware.resovler.variables.keys():
Expand Down Expand Up @@ -148,7 +169,11 @@ def set_configuration(config, install_scripts_dir, cache_file, opt, extra_config

ConfigurationAware.resolver = CofigurationResolver()

# TODO: merge the dicts here "somehow"
if extra_configs:
for pack in extra_configs:
with open(pack) as config_file:
con = json.load(config_file)
config = ConfigurationAware._load_extra_pack(config, con)

ConfigurationAware.config = ConfigurationAware.resolver.configuration_dict(
config,
Expand Down
17 changes: 13 additions & 4 deletions code_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ def get_arg_parser():
dest='packages_file',
action='store',
help='File to read the packages from',
metavar='packages.json',
metavar='PACK_FILE',
)

parser.add_argument(
'--pack',
'-p',
dest='packs',
action='append',
default=[],
help='Extra packages.json files to load packages from.',
)

parser.add_argument(
Expand Down Expand Up @@ -195,7 +204,7 @@ def get_arg_parser():
parser_remove = subparsers.add_parser(
'remove',
description='Remove a package',
help='Remove a package and its sources from the code directory',
help='Remove a package and its sources',
)

parser_remove.add_argument(
Expand Down Expand Up @@ -490,7 +499,7 @@ def venv_check(args, opt):
def venv_setup(args, opt):

python_ver = promt('Python executable', 'python3')
env_root = promt('Python executable', sanitize_input_variable(opt['Config']['venv']))
env_root = promt('Virtual environment location', sanitize_input_variable(opt['Config']['venv']))
opt['Config']['venv'] = env_root

if not os.path.isdir(os.path.abspath(os.path.join(env_root, os.pardir))):
Expand Down Expand Up @@ -558,7 +567,7 @@ def main():

commands = get_commands_map()

ConfigurationAware.set_configuration(CONFIG, INSTALL_SCRIPTS_DIR, CACHE, opt)
ConfigurationAware.set_configuration(CONFIG, INSTALL_SCRIPTS_DIR, CACHE, opt, extra_configs=args.packs)

logging.debug('Code dir: %s', CODE_DIR)
logging.debug('Usr dir: %s', USR_DIR)
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[metadata]
description-file = README.md


[pep8]
ignore=E111,E114,E501
max-line-length=100
Expand Down

0 comments on commit 8c632ab

Please sign in to comment.