Parse project commit

This commit is contained in:
SoniEx2 2019-04-20 17:12:39 -03:00
parent 278c46a106
commit 4a23fbfbcc
2 changed files with 40 additions and 46 deletions

View File

@ -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. 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. 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.) 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` 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. (they come disabled by default). You are now ready to go.

View File

@ -26,35 +26,36 @@ import jinja2
# default HTML, can be overridden in $XDG_DATA_HOME/ganarchy/template.html or the $XDG_DATA_DIRS (TODO) # default HTML, can be overridden in $XDG_DATA_HOME/ganarchy/template.html or the $XDG_DATA_DIRS (TODO)
TEMPLATE = """<!DOCTYPE html> TEMPLATE = """<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<!-- <!--
GAnarchy - project homepage generator GAnarchy - project homepage generator
Copyright (C) 2019 Soni L. Copyright (C) 2019 Soni L.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<title>{{ project_title }}</title> <title>{{ project_title|e }}</title>
</head> {% if project_desc %}<meta name="description" content="{{ project_desc|e }}" />{% endif %}
<body> </head>
<ul> <body>
{% for url, msg, img in repos %} <ul>
{% for url, msg, img in repos -%}
<li><a href="{{ url|e }}">{{ url|e }}</a>: {{ msg|e }}</li> <li><a href="{{ url|e }}">{{ url|e }}</a>: {{ msg|e }}</li>
{% endfor %} {%- endfor %}
</ul> </ul>
Powered by <a href="https://ganarchy.autistic.space/">GAnarchy</a>. AGPLv3-licensed. <a href="https://cybre.tech/SoniEx2/ganarchy">Source Code</a>. Powered by <a href="https://ganarchy.autistic.space/">GAnarchy</a>. AGPLv3-licensed. <a href="https://cybre.tech/SoniEx2/ganarchy">Source Code</a>.
</body> </body>
</html> </html>
""" """
@ -88,8 +89,8 @@ def initdb():
c.execute('''CREATE INDEX active_key ON repos (active)''') 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 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 INDEX url_key ON repo_history (url)''')
c.execute('''CREATE TABLE config (git_commit TEXT, project_title TEXT)''') c.execute('''CREATE TABLE config (git_commit TEXT)''')
c.execute('''INSERT INTO config VALUES ('', '')''') c.execute('''INSERT INTO config VALUES ('')''')
conn.commit() conn.commit()
conn.close() conn.close()
@ -106,17 +107,6 @@ def set_commit(commit):
conn.commit() conn.commit()
conn.close() 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() @ganarchy.group()
def repo(): def repo():
"""Modifies repos to track""" """Modifies repos to track"""
@ -194,8 +184,8 @@ def cron_target():
subprocess.call(["git", "-C", cache_home, "init", "-q"]) subprocess.call(["git", "-C", cache_home, "init", "-q"])
conn = sqlite3.connect(data_home + "/ganarchy.db") conn = sqlite3.connect(data_home + "/ganarchy.db")
c = conn.cursor() c = conn.cursor()
c.execute('''SELECT git_commit, project_title FROM config''') c.execute('''SELECT git_commit FROM config''')
(project_commit, project_title) = c.fetchone() (project_commit,) = c.fetchone()
entries = [] entries = []
generate_html = [] generate_html = []
for (e, url,) in c.execute("""SELECT max(e), url FROM (SELECT max(T1.entry) e, T1.url FROM repo_history T1 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 # TODO process history into SVG
html_entries.append((url, msg, "")) html_entries.append((url, msg, ""))
template = jinja2.Template(TEMPLATE) 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__": if __name__ == "__main__":
ganarchy() ganarchy()