Mercurial > roundup-cc
diff roundup_content_data/__init__.py @ 17:adca5b3780d2
Add collecting no-prio issues. Restructure.
* Move usage examples from collect_issues.py to examples/.
Also add a section about this to the readme. This should
make it easier to understand how it all works together.
As we have two examples now, hardcode the database filenames.
* Add a function to create the necessary database command from a list
of columns. This makes it easier to work with tracker that have
customized their priorities,
* Add an example how to collect no-prio issues in a database.
Note that the display part is not included.
* Cleanup roundup_content_data by removing db file name suggestions
and unused "reference db" command. This could be re-added for specific
installations if they need it, however it probably should be separated
as configuration.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 09 Jul 2018 12:28:28 +0200 |
parents | 99e2e0e17103 |
children | 3bb3d9a9f1b7 |
line wrap: on
line diff
--- a/roundup_content_data/__init__.py Mon Jul 09 11:44:52 2018 +0200 +++ b/roundup_content_data/__init__.py Mon Jul 09 12:28:28 2018 +0200 @@ -7,7 +7,7 @@ author: Bernhard Reiter <bernhard@intevation.de> author: Sean Engelhardt <sean.engelhardt@intevation.de> -(c) 2010,2015 by Intevation GmbH +(c) 2010, 2015, 2018 by Intevation GmbH This is Free Software unter the terms of the GNU GENERAL PUBLIC LICENSE Version 3 or later. @@ -15,13 +15,7 @@ """ import os - -#Add desired sqlite databases here -DATABASE_REFERENCCE = os.path.dirname(os.path.realpath(__file__)) + "/test_reference.db" -DATABASE_DEMO = os.path.dirname(os.path.realpath(__file__)) + "/demo.db" -DATABASE_ERRORDB = os.path.dirname(os.path.realpath(__file__)) + "/errordatabase.db" -DATABASE_TECH_INTERN = os.path.dirname(os.path.realpath(__file__)) + "/tech_intern.db" -DATABASE_INT_TEST = os.path.dirname(os.path.realpath(__file__)) + "/int_test.db" +from typing import List COLUMNS= [ "critical", "urgent", "bug", "feature", "wish", @@ -62,7 +56,6 @@ ORDER BY timestamp """ - CREATE_DB = """ CREATE TABLE issues ( timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp, @@ -80,15 +73,24 @@ VALUES (?, ?, ?, ?, ?) """ -#Referecen DB: -SELECT_ALL_REFERENCE = """ -SELECT strftime("%Y-%m-%dT%H:%M:%S", sample_time), - critical, - major, - crash, - normal, - minor, - wishlist -FROM issues -ORDER BY sample_time -""" + +def build_sql_commands(list_of_columns: list): + """Build sql commands for use with collect_issues. + """ + create_db = ("""CREATE TABLE issues ( + timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp, + """ + + ", ".join([c + " INTEGER NOT NULL DEFAULT 0" + for c in list_of_columns]) + ")") + + insert_new = ("INSERT INTO issues (" + ", ".join(list_of_columns) + ") " + + "VALUES (" + ("?, "*len(list_of_columns))[:-2]+ ")") + + select_tmpl = ("""SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp),""" + + ", ".join(list_of_columns)) + + select_all = select_tmpl + "FROM issues ORDER BY timestamp" + select_where = select_tmpl + "FROM issues WHERE {} ORDER BY timestamp" + + # print(select_all, select_where, create_db, insert_new) + return select_all, select_where, create_db, insert_new