mschieder@25: #!/usr/bin/env python3 mschieder@25: """Connect to roundup-tracker and save status to db. mschieder@25: mschieder@25: Run periodically as often as you want data points to be saved. mschieder@25: """ mschieder@25: mschieder@25: import configparser mschieder@25: import argparse mschieder@25: mschieder@25: from collect_issues import save_stats_in_db mschieder@25: import roundup_content_data as rcd mschieder@25: mschieder@32: # Default priorities of 'roundup'. mschieder@25: PRIO = "critical, urgent, bug, feature, wish" mschieder@32: # Default statuses of 'roundup'. mschieder@28: STATES = "unread, deferred, chatting, need-eg, in-progress, testing, done-cbb, resolved" mschieder@25: mschieder@25: def main(): mschieder@25: mschieder@25: parser = argparse.ArgumentParser() mschieder@25: parser.add_argument("config_file", type=str, metavar="[config file]") mschieder@25: args = parser.parse_args() mschieder@25: mschieder@25: config = configparser.ConfigParser() mschieder@25: config.read(args.config_file) mschieder@25: mschieder@32: # URL of the issue tracker mschieder@25: base_url = config.get("URL", "BaseURL") mschieder@25: mschieder@25: user = config.get("LOGIN","Username") mschieder@25: password = config.get("LOGIN", "Password") mschieder@25: mschieder@25: login_parameters = ( mschieder@25: ("__login_name", user), mschieder@25: ("__login_password", password), mschieder@25: ("@action", "Login"), mschieder@25: ) mschieder@25: mschieder@25: database_file = config.get("DB", "DatabaseFile") mschieder@25: mschieder@25: keywords = config.get("SEARCH", "Keywords", fallback="").split(", ") mschieder@31: include_no_prio = config.getboolean("SEARCH", "IncludeNoPrio", fallback= False) mschieder@25: mschieder@25: search = config.get("SEARCH", "Search", fallback="prio") mschieder@25: if search == "prio": mschieder@26: list_of_columns = config.get("SEARCH", "Priority", fallback=PRIO).split(", ") mschieder@31: search_parameters = config.get("SEARCH", "Status", fallback="").split(", ") mschieder@25: if include_no_prio: mschieder@25: list_of_columns += ["None"] mschieder@25: mschieder@25: elif search == "status": mschieder@25: list_of_columns = config.get("SEARCH", "Status", fallback=STATES).split(", ") mschieder@31: search_parameters = config.get("SEARCH", "Priority", fallback="").split(", ") mschieder@31: if include_no_prio: mschieder@31: search_parameters += ["None"] mschieder@31: mschieder@25: mschieder@26: else: mschieder@26: print("Incorrect [SEARCH]Search parameter. (prio, status)") mschieder@26: return mschieder@26: mschieder@28: # roundup uses a "-" in its search parameters. Sql can't handle it. mschieder@28: sql_list_of_columns = [] mschieder@28: for column in list_of_columns: mschieder@28: sql_list_of_columns.append(column.replace("-", "_")) mschieder@28: mschieder@25: select_all, select_where, create_db, insert_new = \ mschieder@28: rcd.build_sql_commands(sql_list_of_columns) mschieder@25: mschieder@25: save_stats_in_db(search, login_parameters, base_url, database_file, mschieder@32: list_of_columns, create_db, insert_new, keywords, mschieder@32: search_parameters, include_no_prio) mschieder@25: mschieder@25: if __name__ == '__main__': mschieder@25: main()