From 4a23fbfbccd30292f0fc6dcc6f7080752793cc87 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 20 Apr 2019 17:12:39 -0300 Subject: [PATCH] Parse project commit --- README.md | 5 +--- ganarchy.py | 81 ++++++++++++++++++++++++++--------------------------- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 8c05758..b8cdc58 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,9 @@ First, initialize the database with `ganarchy.py initdb`. The database is stored Then, set the project commit with `ganarchy.py set-commit COMMIT`, where `COMMIT` is the full commit hash. The commit *must* start with `[Project]` followed by the project name, and may have an optional description. -(Note: This requirement isn't currently checked, but will be in the future. This is important for a future federation +(Note: This requirement isn't properly checked, but will be in the future. This is important for a future federation protocol that allows for automatically discovering forks based on the project commit.) -Currently, you also need to set the project title manually using `ganarchy.py set-project-title PROJECT-TITLE`. This will -be replaced with the above mechanism in the future. - Once everything is initialized, add some repos with `ganarchy.py repo add URL`, and enable them with `ganarchy.py repo enable URL` (they come disabled by default). You are now ready to go. diff --git a/ganarchy.py b/ganarchy.py index 0737aa6..e6fe620 100755 --- a/ganarchy.py +++ b/ganarchy.py @@ -26,35 +26,36 @@ import jinja2 # default HTML, can be overridden in $XDG_DATA_HOME/ganarchy/template.html or the $XDG_DATA_DIRS (TODO) TEMPLATE = """ - - - -{{ project_title }} - - - -Powered by GAnarchy. AGPLv3-licensed. Source Code. - + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + --> + {{ project_title|e }} + {% if project_desc %}{% endif %} + + + + Powered by GAnarchy. AGPLv3-licensed. Source Code. + """ @@ -88,8 +89,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, project_title TEXT)''') - c.execute('''INSERT INTO config VALUES ('', '')''') + c.execute('''CREATE TABLE config (git_commit TEXT)''') + c.execute('''INSERT INTO config VALUES ('')''') conn.commit() conn.close() @@ -106,17 +107,6 @@ def set_commit(commit): conn.commit() conn.close() -@ganarchy.command() -@click.argument('project-title') -def set_project_title(project_title): - """Sets the project title""" - import re - conn = sqlite3.connect(data_home + "/ganarchy.db") - c = conn.cursor() - c.execute('''UPDATE config SET project_title=?''', (project_title,)) - conn.commit() - conn.close() - @ganarchy.group() def repo(): """Modifies repos to track""" @@ -194,8 +184,8 @@ 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, project_title FROM config''') - (project_commit, project_title) = c.fetchone() + c.execute('''SELECT git_commit FROM config''') + (project_commit,) = c.fetchone() 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 @@ -220,7 +210,14 @@ def cron_target(): # TODO process history into SVG html_entries.append((url, msg, "")) template = jinja2.Template(TEMPLATE) - click.echo(template.render(project_title = project_title, repos = html_entries)) + import re + project = subprocess.check_output(["git", "-C", cache_home, "show", project_commit, "-s", "--format=%B", "--"], stderr=subprocess.DEVNULL).decode("utf-8", "replace") + project_title, project_desc = (lambda x: x.groups() if x is not None else ('', None))(re.fullmatch('^\\[Project\\]\s+(.+?)(?:\n\n(.+))?$', project, flags=re.ASCII|re.DOTALL|re.IGNORECASE)) + if not project_title.strip(): + project_title, project_desc = ("Error parsing project commit",)*2 + if project_desc: + project_desc = project_desc.strip() + click.echo(template.render(project_title = project_title, project_desc = project_desc, repos = html_entries)) if __name__ == "__main__": ganarchy()