changeset 21:7a523e13fcb3

Argpars added for the configuration file.
author Magnus Schieder <mschieder@intevation.de>
date Tue, 23 Oct 2018 13:06:16 +0200
parents 3bb3d9a9f1b7
children 33d7c7769155 89469aa41fe1
files README.creole display_issues_demo.py examples/collect_demo3.py
diffstat 3 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/README.creole	Mon Oct 22 16:49:58 2018 +0200
+++ b/README.creole	Tue Oct 23 13:06:16 2018 +0200
@@ -11,14 +11,14 @@
 cp examples/collect_demo3.py c3.py
 cp examples/config3.ini .
 # change config3.ini
-./c3.py
+./c3.py config3.ini
 # create or change some issues
-./c3.py
+./c3.py config3.ini
 
 # to inspect the database contents
 sqlite3 demo3.db 'select * from issues;'
 
-./display_issues_demo.py >demo3.html
+./display_issues_demo.py config3.ini >demo3.html
 chromium demo3.html
 }}}
 
--- a/display_issues_demo.py	Mon Oct 22 16:49:58 2018 +0200
+++ b/display_issues_demo.py	Tue Oct 23 13:06:16 2018 +0200
@@ -13,11 +13,17 @@
 See http://www.gnu.org/licenses/gpl-3.0.txt for details
 """
 import configparser
+import argparse
 from display_issues import *
 
+parser = argparse.ArgumentParser()
+parser.add_argument("config_file", type=str, metavar="[config file]")
+args = parser.parse_args()
+
 config = configparser.ConfigParser()
-config.read('config3.ini')
+config.read(args.config_file)
 
+db = config.get("DB", "DatabaseFile")
 keywords = config.get("SEARCH", "Keywords", fallback="")
 status = config.get("SEARCH", "Status", fallback="")
 columns = config.get("SEARCH", "Columns", fallback="critical, urgent, bug, feature, wish")
@@ -27,6 +33,6 @@
 
 cgitb.enable() # (optional) HTML traceback to browser
 #render_db_stats_as_html("./demo1.db", rcd.SELECT_ALL)
-render_db_stats_as_html("./demo3.db",
+render_db_stats_as_html(db,
         rcd.build_sql_select(columns).format("timestamp > date('now', '-2 month')"),
         status, keywords)
--- a/examples/collect_demo3.py	Mon Oct 22 16:49:58 2018 +0200
+++ b/examples/collect_demo3.py	Tue Oct 23 13:06:16 2018 +0200
@@ -7,13 +7,19 @@
 
 import json
 import configparser
+import argparse
+
 from collect_issues import save_stats_in_db
 import roundup_content_data as rcd
 
 COLUMNS = "critical, urgent, bug, feature, wish"
 
+parser = argparse.ArgumentParser()
+parser.add_argument("config_file", type=str, metavar="[config file]")
+args = parser.parse_args()
+
 config = configparser.ConfigParser()
-config.read('config3.ini')
+config.read(args.config_file)
 
 base_url = config.get("URL", "BaseURL")
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)