Skip to content

Commit

Permalink
Add support for automatic apt packages installation
Browse files Browse the repository at this point in the history
  • Loading branch information
palikar committed Jun 16, 2020
1 parent c39fd6a commit 40d3f62
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions code_manager/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def _load_extra_pack(primary_config, config):
@staticmethod
def _load_pack_form_link(link):
r = requests.get(link)
breakpoint()
try:
config = json.loads(r.content)
except json.JSONDecodeError:
Expand All @@ -177,13 +176,14 @@ def variables():
return ConfigurationAware.config['vars']

@staticmethod
def set_configuration(config, install_scripts_dir, cache_file, opt, extra_configs=[]):
def set_configuration(config, install_scripts_dir, cache_file, opt, args, extra_configs=[]):

ConfigurationAware.config_dir = sanitize_input_variable('${HOME}/.config/code_manager/')
ConfigurationAware.usr_dir = sanitize_input_variable(opt['Config']['usr'])
ConfigurationAware.code_dir = sanitize_input_variable(opt['Config']['code'])

ConfigurationAware.opt = opt
ConfigurationAware.args = args

ConfigurationAware.resolver = CofigurationResolver()

Expand Down
18 changes: 14 additions & 4 deletions code_manager/core/deb_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def check(self, package):
assert package is not None

dependencies = self.packages[package].get('deb_packages', [])

if not dependencies:
return 0
return self.install_deb_packages(dependencies)
Expand All @@ -52,7 +53,16 @@ def install(self, deb): # pylint: disable=R0201
if not deb:
return 0

print('\n\tRun \'sudo apt-get install -y {}\'\n'.format(' '.join(deb)))
return 1
# options = "--allow-unauthenticated --allow-change-held-packages"
# return os.system("sudo apt-get install -y {} {}".format(deb, options))
if not self.args.apt:
print(
'\n\tRun \'sudo apt-get install -y --allow-unauthenticated\
--allow-change-held-packages {}\'\n'.format(' '.join(deb)),
)
return 1

command = 'sudo apt-get install -y {}'.format(' '.join(deb))
logging.log('Installing apt packages: %s', command)
child = subprocess.Popen(command, shell=True)
_ = child.communicate()[0]
ret_code = child.returncode
return ret_code
5 changes: 3 additions & 2 deletions code_manager/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ def _invoke_install(self):

self._do_fetch(pack, root=root, node=node)

if self.dep_depender.check(pack) != 0:
raise SystemExit

with self.cache as cache:
# if the package is not installed - install it
# installation means 'for the first time'
if not cache.is_installed(pack):
logging.info("Trying to install \'%s\'", pack)
if self.dep_depender.check(pack) != 0:
raise SystemExit
logging.debug('No missing debian packages.')
if self.installation.install(pack, cache.get_root(pack), node) == 0:
logging.info("\'%s\' was installed", pack)
Expand Down
14 changes: 13 additions & 1 deletion code_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,18 @@ def get_arg_parser():
help='Installs packages \
(fetch, build and install)',
)

parser_install.add_argument(
'packages', nargs='*', default=None, help='A list of packages to install',
)

parser_install.add_argument(
'--reinstall',
dest='reinstall',
action='store_true',
help='Should the packages be reinstalled',
)

parser_install.add_argument(
'--group',
action='store',
Expand All @@ -148,6 +151,15 @@ def get_arg_parser():
help='Should the packages be reinstalled',
)

parser_install.add_argument(
'-n',
'--no-apt',
action='store_false',
dest='apt',
default=True,
help='If given, don\'t install apt packages automaticall but give a command to be executed.',
)

parser_fetch = subparsers.add_parser(
'fetch',
description='Downloads packages but\
Expand Down Expand Up @@ -567,7 +579,7 @@ def main():

commands = get_commands_map()

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

logging.debug('Code dir: %s', CODE_DIR)
logging.debug('Usr dir: %s', USR_DIR)
Expand Down

0 comments on commit 40d3f62

Please sign in to comment.