Commit 37e376c1565a56b4bd3ecc6c57d1bb6fbf426352
1 parent
8e309c4d
Exists in
master
and in
1 other branch
Added 'clustering' option, fixed logging import and path expansion.
Showing
1 changed file
with
23 additions
and
20 deletions
Show diff stats
src/config.py
| ... | ... | @@ -22,7 +22,7 @@ __license__ = """ |
| 22 | 22 | import getopt |
| 23 | 23 | import sys |
| 24 | 24 | import os |
| 25 | -from logging import * | |
| 25 | +import logging | |
| 26 | 26 | import logging.handlers |
| 27 | 27 | |
| 28 | 28 | from ConfigParser import * |
| ... | ... | @@ -33,20 +33,19 @@ class Config(): |
| 33 | 33 | """ |
| 34 | 34 | def __init__(self): |
| 35 | 35 | """ |
| 36 | - Set configuration options. | |
| 36 | + Set default configuration options. | |
| 37 | 37 | """ |
| 38 | 38 | self.debug = 0 |
| 39 | 39 | self.verbose = 0 |
| 40 | 40 | self.output = "/dev/null" |
| 41 | 41 | self.config = None |
| 42 | - self.tags_db = "/var/lib/debtags/package-tags" | |
| 43 | - self.tags_index = "~/.app-recommender/debtags_index" | |
| 44 | 42 | self.axi = "/var/lib/apt-xapian-index/index" |
| 45 | 43 | self.axi_values = "/var/lib/apt-xapian-index/values" |
| 46 | - self.popcon_index = "~/.app-recommender/popcon_index" | |
| 47 | - self.popcon_dir = "~/.app-recommender/popcon_dir" | |
| 48 | - self.clusters_dir = "~/.app-recommender/clusters_dir" | |
| 49 | - self.strategy = "cb" # defaults to the cheapest one | |
| 44 | + self.popcon_index = os.path.expanduser("~/.app-recommender/popcon_index") | |
| 45 | + self.popcon_dir = os.path.expanduser("~/.app-recommender/popcon_dir") | |
| 46 | + self.clusters_dir = os.path.expanduser("~/.app-recommender/clusters_dir") | |
| 47 | + self.clustering = 1 | |
| 48 | + self.strategy = "cb" | |
| 50 | 49 | self.weight = "bm25" |
| 51 | 50 | self.load_options() |
| 52 | 51 | self.set_logger() |
| ... | ... | @@ -66,6 +65,7 @@ class Config(): |
| 66 | 65 | print " -a, --axi=PATH Path to Apt-xapian-index." |
| 67 | 66 | print " -p, --popconindex=PATH Path to popcon dedicated index." |
| 68 | 67 | print " -m, --popcondir=PATH Path to popcon submissions dir." |
| 68 | + print " -u, --clustering If popcon data should be clustered." | |
| 69 | 69 | print " -l, --clustersdir=PATH Path to popcon clusters dir." |
| 70 | 70 | print " -w, --weight=OPTION Search weighting scheme." |
| 71 | 71 | print " -s, --strategy=OPTION Recommendation strategy." |
| ... | ... | @@ -113,14 +113,15 @@ class Config(): |
| 113 | 113 | self.axi = self.read_option('recommender', 'axi') |
| 114 | 114 | self.popcon_index = self.read_option('recommender', 'popcon_index') |
| 115 | 115 | self.popcon_dir = self.read_option('recommender', 'popcon_dir') |
| 116 | + self.clustering = self.read_option('recommender', 'clustering') | |
| 116 | 117 | self.clusters_dir = self.read_option('recommender', 'clusters_dir') |
| 117 | 118 | self.weight = self.read_option('recommender', 'weight') |
| 118 | 119 | self.strategy = self.read_option('recommender', 'strategy') |
| 119 | 120 | |
| 120 | - short_options = "hdvo:c:a:p:m:l:w:s:" | |
| 121 | + short_options = "hdvo:c:a:p:m:ul:w:s:" | |
| 121 | 122 | long_options = ["help", "debug", "verbose", "output=", "config=", |
| 122 | - "axi=", "popconindex=", "popcondir=", "clustersdir=", | |
| 123 | - "weight=", "strategy="] | |
| 123 | + "axi=", "popconindex=", "popcondir=", "clustering", | |
| 124 | + "clusters_dir=", "weight=", "strategy="] | |
| 124 | 125 | try: |
| 125 | 126 | opts, args = getopt.getopt(sys.argv[1:], short_options, |
| 126 | 127 | long_options) |
| ... | ... | @@ -149,8 +150,10 @@ class Config(): |
| 149 | 150 | self.popcon_index = p |
| 150 | 151 | elif o in ("-m", "--popcondir"): |
| 151 | 152 | self.popcon_dir = p |
| 153 | + elif o in ("-u", "--clustering"): | |
| 154 | + self.clustering = 1 | |
| 152 | 155 | elif o in ("-l", "--clustersdir"): |
| 153 | - self.popcon_dir = p | |
| 156 | + self.clusters_dir = p | |
| 154 | 157 | elif o in ("-w", "--weight"): |
| 155 | 158 | self.weight = p |
| 156 | 159 | elif o in ("-s", "--strategy"): |
| ... | ... | @@ -162,18 +165,18 @@ class Config(): |
| 162 | 165 | """ |
| 163 | 166 | Configure application logger and log level. |
| 164 | 167 | """ |
| 165 | - self.logger = getLogger('') # root logger is used by default | |
| 166 | - self.logger.setLevel(DEBUG) | |
| 168 | + self.logger = logging.getLogger('') # root logger is used by default | |
| 169 | + self.logger.setLevel(logging.DEBUG) | |
| 167 | 170 | |
| 168 | 171 | if self.debug == 1: |
| 169 | - log_level = DEBUG | |
| 172 | + log_level = logging.DEBUG | |
| 170 | 173 | elif self.verbose == 1: |
| 171 | - log_level = INFO | |
| 174 | + log_level = logging.INFO | |
| 172 | 175 | else: |
| 173 | - log_level = WARNING | |
| 176 | + log_level = logging.WARNING | |
| 174 | 177 | |
| 175 | - console_handler = StreamHandler(sys.stdout) | |
| 176 | - console_handler.setFormatter(Formatter('%(levelname)s: %(message)s')) | |
| 178 | + console_handler = logging.StreamHandler(sys.stdout) | |
| 179 | + console_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) | |
| 177 | 180 | console_handler.setLevel(log_level) |
| 178 | 181 | self.logger.addHandler(console_handler) |
| 179 | 182 | |
| ... | ... | @@ -181,6 +184,6 @@ class Config(): |
| 181 | 184 | maxBytes=5000, |
| 182 | 185 | backupCount=5) |
| 183 | 186 | log_format = '%(asctime)s AppRecommender %(levelname)-8s %(message)s' |
| 184 | - file_handler.setFormatter(Formatter(log_format)) | |
| 187 | + file_handler.setFormatter(logging.Formatter(log_format)) | |
| 185 | 188 | file_handler.setLevel(log_level) |
| 186 | 189 | self.logger.addHandler(file_handler) | ... | ... |