Skip to content

Commit

Permalink
Set up the remote packages.json support
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaudov, Stanislav Tomov committed Jun 15, 2020
1 parent 8c632ab commit 494d740
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
35 changes: 30 additions & 5 deletions code_manager/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import os
import re

import requests

from code_manager.utils.utils import flatten
from code_manager.utils.utils import recursive_items
from code_manager.utils.utils import sanitize_input_variable


class CofigurationResolver:
Expand Down Expand Up @@ -122,6 +125,9 @@ def resolve_nodes(self, config):


class ConfigurationAware:

URL_REGEX = re.compile(r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))")

@staticmethod
def _load_extra_pack(primary_config, config):
primary_config.setdefault('vars', {})
Expand All @@ -142,6 +148,15 @@ def _load_extra_pack(primary_config, config):

return primary_config

@staticmethod
def _load_pack_form_link(link):
r = requests.get(link)
try:
config = json.loads(r.content)
except json.JSONDecodeError:
return None
return config

@staticmethod
def var(name):
if name in ConfigurationAware.resovler.variables.keys():
Expand All @@ -163,17 +178,27 @@ def variables():
@staticmethod
def set_configuration(config, install_scripts_dir, cache_file, opt, 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.usr_dir = os.path.expandvars(opt['Config']['usr'])
ConfigurationAware.code_dir = os.path.expandvars(opt['Config']['code'])

ConfigurationAware.resolver = CofigurationResolver()

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)

if re.match(pack, ConfigurationAware.URL_REGEX):
con = ConfigurationAware._load_pack_form_link(pack)
elif os.path.exists(pack):
with open(pack) as config_file:
con = json.load(config_file)
else:
con = None

if con is not None:
config = ConfigurationAware._load_extra_pack(config, con)

ConfigurationAware.config = ConfigurationAware.resolver.configuration_dict(
config,
Expand Down
5 changes: 3 additions & 2 deletions code_manager/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from code_manager.core.installation import Installation
from code_manager.utils.utils import flatten

# TODO: extract each step in function per package


class Manager(ConfigurationAware):

Expand Down Expand Up @@ -279,3 +277,6 @@ def remove_package(self, packs):
cache.set_root(pack, '')
cache.set_built(pack, False)
cache.set_installed(pack, False)

def run_command(self, command, args):
pass

0 comments on commit 494d740

Please sign in to comment.