diff options
Diffstat (limited to 'ganarchy')
-rw-r--r-- | ganarchy/data.py | 15 | ||||
-rw-r--r-- | ganarchy/db.py | 39 | ||||
-rw-r--r-- | ganarchy/templating/templates.py | 2 |
3 files changed, 51 insertions, 5 deletions
diff --git a/ganarchy/data.py b/ganarchy/data.py index 1f4cd19..36c32d9 100644 --- a/ganarchy/data.py +++ b/ganarchy/data.py @@ -71,6 +71,7 @@ class CommitPredicate(abdl.predicates.Predicate): # sanitize = skip invalid entries # validate = error on invalid entries # LEGACY. DO NOT USE. +# TODO remove CONFIG_REPOS_SANITIZE = abdl.compile("""->'projects'?:?$dict ->commit[:?$str:?$commit]:?$dict ->url[:?$str:?$uri]:?$dict @@ -86,7 +87,9 @@ CONFIG_BASE_URL_SANITIZE = abdl.compile("""->base_url'base_url'?:?$str:?$uri""", _MATCHER_REPOS = abdl.compile("""->'projects':$dict ->commit[:?$str:?$commit]:?$dict ->url[:?$str:?$uri]:?$dict - ->branch:?$dict(->'active'?:?$bool)""", + ->branch:?$dict + (->active'active'?:?$bool) + (->federate'federate'?:?$bool)?""", dict(bool=bool, dict=dict, str=str, uri=URIPredicate(), commit=CommitPredicate())) _MATCHER_REPO_LIST_SRCS = abdl.compile("""->'repo_list_srcs':$dict ->src[:?$str:?$uri]:?$dict @@ -150,6 +153,10 @@ class PCTP(OverridableProperty): def as_key(self): return (self.project_commit, self.uri, self.branch, ) + @property + def federate(self): + return self.options.get('federate', True) + class RepoListSource(OverridableProperty): """A source for a repo list. @@ -266,7 +273,7 @@ class ObjectDataSource(DataSource): _SUPPORTED_PROPERTIES = { DataProperty.INSTANCE_TITLE: lambda obj: (d['title'][1] for d in _MATCHER_TITLE.match(obj)), DataProperty.INSTANCE_BASE_URL: lambda obj: (d['base_url'][1] for d in _MATCHER_BASE_URL.match(obj)), - DataProperty.VCS_REPOS: lambda obj: (PCTP(r['commit'][0], r['url'][0], r['branch'][0], r['branch'][1]) for r in _MATCHER_REPOS.match(obj)), + DataProperty.VCS_REPOS: lambda obj: (PCTP(r['commit'][0], r['url'][0], r['branch'][0], {k: v[1] for k, v in r.items() if k in {'active', 'federate'}}) for r in _MATCHER_REPOS.match(obj)), DataProperty.REPO_LIST_SOURCES: lambda obj: (RepoListSource(d['src'][0], d['src'][1]) for d in _MATCHER_REPO_LIST_SRCS.match(obj)), } @@ -504,6 +511,10 @@ class RepoListManager(DataSource): else: for pctp in iterator: # but repo lists aren't allowed to override anything + try: + del pctp.options['federate'] + except KeyError: + pass if pctp.active: yield pctp diff --git a/ganarchy/db.py b/ganarchy/db.py index 328b682..b7aa29b 100644 --- a/ganarchy/db.py +++ b/ganarchy/db.py @@ -163,7 +163,8 @@ class Database: "url" TEXT, "active" INT, "branch" TEXT, - "project" TEXT + "project" TEXT, + "federate" INT ) ''') c.execute(''' @@ -183,8 +184,8 @@ class Database: ): if repo.active: c.execute( - '''INSERT INTO "repos" VALUES (?, ?, ?, ?)''', - (repo.uri, 1, repo.branch, repo.project_commit) + '''INSERT INTO "repos" VALUES (?, ?, ?, ?, ?)''', + (repo.uri, 1, repo.branch, repo.project_commit, int(repo.federate)) ) self.conn.commit() c.close() @@ -319,6 +320,38 @@ class Database: c.close() return history + def should_repo_federate(self, project_commit, uri, branch): + """Returns whether a repo should federate. + + Args: + project_commit: The project commit. + uri: The repo uri. + branch: The branch. + + Returns: + bool, optional: Whether the repo should federate, or None if it + doesn't exist. + """ + c = self.conn.cursor() + federate = c.execute( + ''' + SELECT "federate" + FROM "repos" + WHERE + "url" = ? + AND "branch" IS ? + AND "project" IS ? + ''', + (uri, branch, project_commit) + ).fetchall() + try: + ((federate,),) = federate + federate = bool(federate) + except ValueError: + federate = None + c.close() + return federate + def close(self): """Closes the database. """ diff --git a/ganarchy/templating/templates.py b/ganarchy/templating/templates.py index 1435940..1b069b2 100644 --- a/ganarchy/templating/templates.py +++ b/ganarchy/templating/templates.py @@ -70,7 +70,9 @@ def get_template_loader(): {%- for project in database.list_projects() %} [projects.{{project}}] {%- for repo_url, branch, _head_commit in database.list_repobranches(project) %} +{%- if database.should_repo_federate(project, repo_url, branch) %} "{{repo_url|tomle}}".{% if not branch %}HEAD{% else %}"{{branch|tomle}}"{% endif %} = { active=true } +{%- endif %} {%- endfor %} {% endfor -%} """, |