summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--TODO.md1
-rw-r--r--ganarchy/data.py15
-rw-r--r--ganarchy/db.py39
-rw-r--r--ganarchy/templating/templates.py2
5 files changed, 60 insertions, 12 deletions
diff --git a/README.md b/README.md
index 5e52034..1029339 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ is stored in the XDG data home, as per the XDG Base Directory specification.
 Then create or edit the file `$XDG_CONFIG_HOME/ganarchy/config.toml`. It
 can contain the following items, some of which are required:
 
-```
+```toml
 # Example GAnarchy config
 
 # The base_url is the web address of the GAnarchy instance.
@@ -34,24 +34,27 @@ title = "GAnarchy on autistic.space"
 # used.
 [repo_list_srcs]
 # Each repo list src is an URL that points to the repo list.
-# Restrictions: active MUST be present. MUST be https.
+# Restrictions: active MUST be present. MUST be https or file.
 "https://ganarchy.autistic.space/index.toml" = { active=true }
 # active=false won't be processed.
-"https://ganarchy.github.io/index.toml" = { active=true }
+"https://ganarchy.github.io/index.toml" = { active=false }
 
 # The projects table is made up of "project commit" hashes (see below for
 # what a project commit is)
 [projects.385e734a52e13949a7a5c71827f6de920dbfea43]
 # Each project is made up of repos and branches
 # HEAD is special and refers to the default branch
-# Restrictions: active MUST be present, file URLs are disallowed.
+# Restrictions: active MUST be present. MUST be https.
 "https://cybre.tech/SoniEx2/ganarchy".HEAD = { active=true }
 # repos/branches with active=false will not be shown or updated.
 "https://cybre.tech/SoniEx2/ganarchy".broken = { active=false }
+# federate=false won't be shared with other instances, but will be shown and
+# updated. (handy if you don't fully trust a repo yet.)
+"https://soniex2.autistic.space/git-repos/ganarchy.git"."feature/new-config" = { active=true, federate=false }
 ```
 
-A project commit is a commit that *must* start with `[Project]` followed by the
-project name, and may have an optional description.
+A project commit is a commit whose message MUST start with `[Project]`
+followed by the project name, and may have an optional description.
 
 Example project commit:
 
diff --git a/TODO.md b/TODO.md
index 94e8d42..d7ccefe 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,5 +2,4 @@ Wishlist/TODO
 =============
 
 1. There needs to be weights and thresholds for federated repo lists.
-2. There needs to be non-federated entries for repos in a project.
 3. There needs to be a way to mark projects as containing sexual references.
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 -%}
 """,