|
21 | 21 |
|
22 | 22 | import argparse |
23 | 23 | import logging |
| 24 | +import requests |
| 25 | +import os |
24 | 26 | import re |
25 | 27 | from typing import List |
26 | 28 |
|
@@ -60,6 +62,8 @@ def parseArgs(): |
60 | 62 | parser = argparse.ArgumentParser(description='Clean the QC database.') |
61 | 63 | parser.add_argument('--config', dest='config', action='store', default="config.yaml", |
62 | 64 | help='Path to the config file') |
| 65 | + parser.add_argument('--config-git', action='store_true', |
| 66 | + help='Check out the config file from git (branch repo_cleaner), ignore --config.') |
63 | 67 | parser.add_argument('--log-level', dest='log_level', action='store', default="20", |
64 | 68 | help='Log level (CRITICAL->50, ERROR->40, WARNING->30, INFO->20,DEBUG->10)') |
65 | 69 | parser.add_argument('--dry-run', action='store_true', |
@@ -97,6 +101,22 @@ def parseConfig(config_file_path): |
97 | 101 |
|
98 | 102 | return {'rules': rules, 'ccdb_url': ccdb_url} |
99 | 103 |
|
| 104 | +def downloadConfigFromGit(): |
| 105 | + """ |
| 106 | + Download a config file from git. |
| 107 | + :param config_git: True if the file must be downloaded from git. |
| 108 | + :return: the path to the config file |
| 109 | + """ |
| 110 | + |
| 111 | + logging.debug("Get it from git") |
| 112 | + r = requests.get('https://raw.github.com/AliceO2Group/QualityControl/repo_cleaner/Framework/script/RepoCleaner/config.yaml') |
| 113 | + logging.debug(f"config file from git : \n{r.text}") |
| 114 | + path = "/tmp/config.yaml" |
| 115 | + with open(path, 'w') as f: |
| 116 | + f.write(r.text) |
| 117 | + logging.info(f"Config path : {path}") |
| 118 | + return path |
| 119 | + |
100 | 120 |
|
101 | 121 | def findMatchingRule(rules, object_path): |
102 | 122 | """Return the first matching rule for the given path or None if none is found.""" |
@@ -124,7 +144,10 @@ def main(): |
124 | 144 | logging.getLogger().setLevel(int(args.log_level)) |
125 | 145 |
|
126 | 146 | # Read configuration |
127 | | - config = parseConfig(args.config) |
| 147 | + path = args.config |
| 148 | + if args.config_git: |
| 149 | + path = downloadConfigFromGit() |
| 150 | + config = parseConfig(path) |
128 | 151 | rules: List[Rule] = config['rules'] |
129 | 152 | ccdb_url = config['ccdb_url'] |
130 | 153 |
|
|
0 commit comments