view roundup_cc.py @ 34:916fa83b4144

Clean up repository. 'Update README.creole' * /doc added for the old demos. * Added comments to config.ini.
author Magnus Schieder <mschieder@intevation.de>
date Mon, 26 Nov 2018 16:08:27 +0100
parents 80bbd06fe8ec
children
line wrap: on
line source
#!/usr/bin/env python3
"""Connect to roundup-tracker and save status to db.

Run periodically as often as you want data points to be saved.
"""

import configparser
import argparse

from collect_issues import save_stats_in_db
import roundup_content_data as rcd

# Default priorities of 'roundup'.
PRIO = "critical, urgent, bug, feature, wish"
# Default statuses of 'roundup'.
STATES = "unread, deferred, chatting, need-eg, in-progress, testing, done-cbb, resolved"

def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("config_file", type=str, metavar="[config file]")
    args = parser.parse_args()

    config = configparser.ConfigParser()
    config.read(args.config_file)

    # URL of the issue tracker
    base_url = config.get("URL", "BaseURL")

    user = config.get("LOGIN","Username")
    password = config.get("LOGIN", "Password")

    login_parameters = (
        ("__login_name", user),
        ("__login_password", password),
        ("@action", "Login"),
        )

    database_file = config.get("DB", "DatabaseFile")

    keywords = config.get("SEARCH", "Keywords", fallback="").split(", ")
    include_no_prio = config.getboolean("SEARCH", "IncludeNoPrio", fallback= False)

    search = config.get("SEARCH", "Search", fallback="prio")
    if search == "prio":
        list_of_columns = config.get("SEARCH", "Priority", fallback=PRIO).split(", ")
        search_parameters = config.get("SEARCH", "Status", fallback="").split(", ")
        if include_no_prio:
            list_of_columns += ["None"]

    elif search == "status":
        list_of_columns = config.get("SEARCH", "Status", fallback=STATES).split(", ")
        search_parameters = config.get("SEARCH", "Priority", fallback="").split(", ")
        if include_no_prio:
            search_parameters += ["None"]


    else:
        print("Incorrect [SEARCH]Search parameter. (prio, status)")
        return

    # roundup uses a "-" in its search parameters. Sql can't handle it.
    sql_list_of_columns = []
    for column in list_of_columns:
         sql_list_of_columns.append(column.replace("-", "_"))

    select_all, select_where, create_db, insert_new = \
        rcd.build_sql_commands(sql_list_of_columns)

    save_stats_in_db(search, login_parameters, base_url, database_file,
                    list_of_columns, create_db, insert_new, keywords,
                    search_parameters, include_no_prio)

if __name__ == '__main__':
    main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)