diff options
Diffstat (limited to 'ganarchy/__init__.py')
-rw-r--r-- | ganarchy/__init__.py | 49 |
1 files changed, 1 insertions, 48 deletions
diff --git a/ganarchy/__init__.py b/ganarchy/__init__.py index 6d24994..42ff1ea 100644 --- a/ganarchy/__init__.py +++ b/ganarchy/__init__.py @@ -32,7 +32,7 @@ import requests from collections import defaultdict from urllib.parse import urlparse -import ganarchy.config as m_ganarchy_config +import ganarchy as m_ganarchy MIGRATIONS = { "toml-config": ( @@ -437,53 +437,6 @@ class GAnarchy: else: self.projects = None -class Config: - def __init__(self, toml_file, base=None, remove=True): - self.projects = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(dict)))) - config_data = qtoml.load(toml_file) - self.remote_configs = config_data.get('config_srcs', []) - self.title = config_data.get('title', '') - self.base_url = config_data.get('base_url', '') - # TODO blocked domains (but only read them from config_data if remove is True) - self.blocked_domains = [] - self.blocked_domain_suffixes = [] - self.blocked_domains.sort() - self.blocked_domain_suffixes.sort(key=lambda x: x[::-1]) - # FIXME remove duplicates and process invalid entries - self.blocked_domains = tuple(self.blocked_domains) - self.blocked_domain_suffixes = tuple(self.blocked_domain_suffixes) # MUST be tuple - # TODO re.compile("(^" + "|^".join(map(re.escape, domains)) + "|" + "|".join(map(re.escape, suffixes) + ")$") - if base: - # FIXME is remove=remove the right thing to do? - self._update_projects({'projects': base.projects}, remove=remove, sanitize=False) # already sanitized - self._update_projects(config_data, remove=remove) - - def _update_projects(self, projects, remove, sanitize=True): - m = (m_ganarchy_config.CONFIG_REPOS_SANITIZE if sanitize else m_ganarchy_config.CONFIG_REPOS).match(projects) - for v in m: - commit, repo_url, branchname, options = v['commit'][0], v['url'][0], v['branch'][0], v['branch'][1] - try: - u = urlparse(repo_url) - if not u: - raise ValueError - # also raises for invalid ports, see https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse - # "Reading the port attribute will raise a ValueError if an invalid port is specified in the URL. [...]" - if u.port == 0: - raise ValueError - if u.scheme not in ('http', 'https'): - raise ValueError - if (u.hostname in self.blocked_domains) or (u.hostname.endswith(self.blocked_domain_suffixes)): - raise ValueError - except ValueError: - continue - if branchname == "HEAD": - branchname = None - active = options.get('active', None) - if active not in (True, False): - continue - branch = self.projects[commit][repo_url][branchname] - branch['active'] = active or (branch.get('active', False) and not remove) - @ganarchy.command() @click.option('--skip-errors/--no-skip-errors', default=False) @click.argument('files', type=click.File('r', encoding='utf-8'), nargs=-1) |