Skip to content

Commit

Permalink
Finishing up the cp installer
Browse files Browse the repository at this point in the history
  • Loading branch information
palikar committed Nov 14, 2019
1 parent 7a4f04a commit 11984ae
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions code_manager/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ def set_configuration(config, install_scripts_dir, cache_file, opt):

def __getattr__(self, item):
opt = ConfigurationAware.opt
# if item in opt.get("Common", {}).keys():
# return opt["Common"][item]
if item in opt.get("Common", {}).keys():
return opt["Common"][item]
return None
15 changes: 8 additions & 7 deletions code_manager/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def _invoke_install(self):
logging.info("Trying to install \'%s\'", pack)
if self.dep_depender.check(pack) != 0:
raise SystemExit
else:
logging.debug('No missing debian packages.')
logging.debug('No missing debian packages.')
if self.installation.install(pack, cache.get_root(pack)) == 0:
logging.info("\'%s\' was installed", pack)
cache.set_installed(pack, True)
Expand Down Expand Up @@ -186,15 +185,17 @@ def get_cache_content(self):
cache_content = []
for pack in self.packages.keys():
if self.cache.in_cache(pack):
cache_content.append({'name' : pack,
'fetched' : self.cache.is_fetched(pack),
'built' : self.cache.is_built(pack),
'installed' : self.cache.is_installed(pack),
'root' : self.cache.get_root(pack)})
cache_content.append({'name': pack,
'fetched': self.cache.is_fetched(pack),
'built': self.cache.is_built(pack),
'installed': self.cache.is_installed(pack),
'root': self.cache.get_root(pack)})
return cache_content

def get_group_packages(self, group):
if group not in self.packages_list.keys():
return []
return self.packages_list[group]

def get_groups(self):
return list(self.packages_list.keys())
25 changes: 15 additions & 10 deletions code_manager/installers/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from code_manager.core.installation import BasicInstaller
from code_manager.core.configuration import ConfigurationAware
from code_manager.utils.utils import sanitize_input_variable
from code_manager.utils.process import execute_sanitized


class CopyInstaller(BasicInstaller, ConfigurationAware):
Expand All @@ -18,22 +19,26 @@ def execute(self, name):
assert name is not None

cp_node = self.node['cp']

assert isinstance(cp_node, list)

for copy in cp_node:
dest = sanitize_input_variable(copy['dest'])
source = sanitize_input_variable(copy['source'])
cp_command = ['cp', '-a', '-v']
if isinstance(copy['source'], str):
source = sanitize_input_variable(copy['source'])
cp_command += [source]
else:
source = map(sanitize_input_variable, copy['source'])
cp_command += source

if not os.path.exists():
os.makedirs(dst)

cp_command = ['cp', '-a', '-v', source, dest]
dest = sanitize_input_variable(copy['dest'])
if not os.path.exists(dest):
os.makedirs(dest)
cp_command += [dest]


logging.debug('Running copy command: %s', cp_command)

if execute_sanitized('cp', cp_command, self.root) is None:
return None


return 0

def update(self, name):
Expand Down
5 changes: 2 additions & 3 deletions code_manager/installers/emacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ def execute(self, name):

el_files = self.node['el_files']
emacs_load_file = get_emacs_load_file()
logging.debug('Emacs file:', emacs_load_file)
logging.debug('Emacs file: %s', emacs_load_file)

with open(emacs_load_file, 'r') as load_file:
emacs_load_file_lines = load_file.readlines()

with open(emacs_load_file, 'a') as load_file:
load_file.write(';; Files from package {}\n'.format(name))

for el_f in el_files:
path = os.path.join(self.root, el_f)
line = '(load-file \"{}\")\n'.format(path)

if line not in emacs_load_file_lines:
logging.debug('Adding %s to the Emacs load file', path)
load_file.write(';; Files from package {}\n'.format(name))
load_file.write(line)

return 0
Expand Down
4 changes: 0 additions & 4 deletions code_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def get_arg_parser():
packege in the cache",
)


list_cache_parser.add_argument(
'-p',
"--plain",
Expand All @@ -230,7 +229,6 @@ def get_arg_parser():
help="Don't print the first line when printing packages with --plain",
)


list_cache_parser.add_argument(
"--no-pager",
action="store_true",
Expand Down Expand Up @@ -311,7 +309,6 @@ def list_groups(args, core):
print(string)



def clear_cache(_, core):
logging.info("Clearing cache file %s", CACHE)
if promt_yes_no("Are you sure you want to clear the cache?"):
Expand All @@ -330,7 +327,6 @@ def get_commands_map():
commands["clear-cache"] = clear_cache
commands["list-groups"] = list_groups


return commands


Expand Down
6 changes: 3 additions & 3 deletions code_manager/utils/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ def import_file(path, name, core_package="code_manager"):

if sys.version_info > (3, 5):
# python 3.5 - 3.7
import importlib.util # pylint: disable=C0415
import importlib.util # pylint: disable=C0415
spec = importlib.util.spec_from_file_location(
'{}.{}'.format(core_package, name), path)
imported = importlib.util.module_from_spec(spec)
spec.loader.exec_module(imported)
elif sys.version_info >= (3, 3):
# python 3.3 - 3.4
from importlib.machinery import SourceFileLoader # pylint: disable=C0415
from importlib.machinery import SourceFileLoader # pylint: disable=C0415
imported = SourceFileLoader('code_manager.{}'.format(name), path).load_module() # pylint: disable=W1505,E1120
else:
# python 2
import imp # pylint: disable=C0415
import imp # pylint: disable=C0415
imported = imp.load_source('{0}.{1}'.format(core_package, name), path)
return imported

Expand Down
1 change: 1 addition & 0 deletions code_manager/utils/printing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from subprocess import Popen, PIPE


def less(data):
process = Popen(["less"], stdin=PIPE)
try:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pyflakes==2.1.1
pylint==2.4.4
pytest-cov==2.7.1
pytest==5.0.0
termtables==0.1.1

0 comments on commit 11984ae

Please sign in to comment.