From 828d0ac9cf2a6801ce59809c2e05b98085669035 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Mon, 22 Apr 2019 18:59:02 -0300 Subject: [PATCH] Prepare for future web+ganarchy URI handlers --- ganarchy.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/ganarchy.py b/ganarchy.py index f44a71f..ea93613 100755 --- a/ganarchy.py +++ b/ganarchy.py @@ -50,14 +50,19 @@ TEMPLATE = """

{{ project_title|e }}

-

Tracking {{ project_commit }}

+

Tracking {{ project_commit }}

{{ project_body|e|replace("\n\n", "

") }}

- Powered by GAnarchy. AGPLv3-licensed. Source Code. +

Powered by GAnarchy. AGPLv3-licensed. Source Code.

+

+ Main page. + + +

""" @@ -92,8 +97,8 @@ def initdb(): c.execute('''CREATE INDEX active_key ON repos (active)''') c.execute('''CREATE TABLE repo_history (entry INTEGER PRIMARY KEY ASC AUTOINCREMENT, url TEXT, count INTEGER, head_commit TEXT)''') c.execute('''CREATE INDEX url_key ON repo_history (url)''') - c.execute('''CREATE TABLE config (git_commit TEXT)''') - c.execute('''INSERT INTO config VALUES ('')''') + c.execute('''CREATE TABLE config (git_commit TEXT, base_url TEXT)''') + c.execute('''INSERT INTO config VALUES ('', '')''') conn.commit() conn.close() @@ -110,6 +115,16 @@ def set_commit(commit): conn.commit() conn.close() +@ganarchy.command() +@click.argument('base-url') +def set_base_url(base_url): + """Sets the GAnarchy instance's base URL""" + conn = sqlite3.connect(data_home + "/ganarchy.db") + c = conn.cursor() + c.execute('''UPDATE config SET base_url=?''', (base_url,)) + conn.commit() + conn.close() + @ganarchy.group() def repo(): """Modifies repos to track""" @@ -187,8 +202,11 @@ def cron_target(): subprocess.call(["git", "-C", cache_home, "init", "-q"]) conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() - c.execute('''SELECT git_commit FROM config''') - (project_commit,) = c.fetchone() + c.execute('''SELECT git_commit, base_url FROM config''') + (project_commit, base_url) = c.fetchone() + if not base_url or not project_commit: + click.echo("No base URL or project commit specified", err=True) + return entries = [] generate_html = [] for (e, url,) in c.execute("""SELECT max(e), url FROM (SELECT max(T1.entry) e, T1.url FROM repo_history T1 @@ -224,7 +242,8 @@ def cron_target(): project_desc = project_desc, project_body = project, project_commit = project_commit, - repos = html_entries)) + repos = html_entries, + base_url = base_url)) if __name__ == "__main__": ganarchy()