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 18c08aa
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions code_manager/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import re

import requests

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

Expand Down Expand Up @@ -122,6 +124,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 +147,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 Down Expand Up @@ -171,9 +185,17 @@ def set_configuration(config, install_scripts_dir, cache_file, opt, extra_config

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

0 comments on commit 18c08aa

Please sign in to comment.