def load_config(self, cfg) : conf = ConfigParser.RawConfigParser() conf.read(cfg) try : db = conf.get('glob', 'database') verbose = conf.getboolean('glob', 'verbose') if conf.has_option(self.name, 'database') : db = conf.get(self.name, 'database') if conf.has_option(self.name, 'verbose') : verbose = conf.getboolean(self.name, 'verbose') if conf.has_option(self.name, 'db_watchs') : for watch in conf.get(self.name, 'db_watchs').split('\n') : if os.path.isdir(watch) : self.watchs.append(watch) if conf.options(self.name) : self.items = conf.get(self.name, 'db_table').split('|') except : traceback.print_exc() return False self.sql = SQLTools(db, self.name) self.verbose = verbose return True
def load_config(self, cfg) : conf = ConfigParser.RawConfigParser() conf.read(cfg) try : db = conf.get('glob', 'database') verbose = conf.getboolean('glob', 'verbose') if conf.has_option(self.name, 'database') : db = conf.get(self.name, 'database') if conf.has_option(self.name, 'verbose') : verbose = conf.getboolean(self.name, 'verbose') if conf.has_option(self.name, 'db_check_key') : self.keys = conf.get(self.name, 'db_check_key').split('|') except : traceback.print_exc() return False self.sql = SQLTools(db, self.name) self.verbose = verbose return True
class DBChecker : def __init__(self, name, cfg) : self.name = name self.keys = [] self.values = [] self.hits = [] self.load_config(cfg) def __repr__(self) : for hit in self.hits : print('-'*100) print(hit) return '' def __str__(self) : return self.__repr__() def load_config(self, cfg) : conf = ConfigParser.RawConfigParser() conf.read(cfg) try : db = conf.get('glob', 'database') verbose = conf.getboolean('glob', 'verbose') if conf.has_option(self.name, 'database') : db = conf.get(self.name, 'database') if conf.has_option(self.name, 'verbose') : verbose = conf.getboolean(self.name, 'verbose') if conf.has_option(self.name, 'db_check_key') : self.keys = conf.get(self.name, 'db_check_key').split('|') except : traceback.print_exc() return False self.sql = SQLTools(db, self.name) self.verbose = verbose return True # find hits in the db match check_mpas def find_db(self) : self.hits = [] for key in self.keys : for value in self.values : value = self.parse_raw_value(value) ret = self.sql.find(key, [value]) if len(ret) > 0 : self.hits.append('Hit {0} : {1}'.format(value, ret)) # parse raw value for db find def parse_raw_value(self, raw) : return raw; def set_watch_values(self, values=[]) : self.values += values
class DataParser : def __init__(self, name, cfg) : self.name = name self.watchs = [] self.items = [] self.raws = [] self.result = {'done':[], 'fail':[]} self.load_config(cfg) def __repr__(self) : print('-'*50, 'FAIL ({0:04d})'.format(len(self.result['fail'])), '-'*50) for line in self.result['fail'] : print(line) print('\n\n') print('-'*50, 'DONE ({0:04d})'.format(len(self.result['done'])), '-'*50) if self.verbose : for data in self.result['done'] : for key, value in data.items() : print('{name:10s}: {value}'.format(name=key, value=value)) print('-'*120) return '' def __str__(self) : return self.__repr__() def load_config(self, cfg) : conf = ConfigParser.RawConfigParser() conf.read(cfg) try : db = conf.get('glob', 'database') verbose = conf.getboolean('glob', 'verbose') if conf.has_option(self.name, 'database') : db = conf.get(self.name, 'database') if conf.has_option(self.name, 'verbose') : verbose = conf.getboolean(self.name, 'verbose') if conf.has_option(self.name, 'db_watchs') : for watch in conf.get(self.name, 'db_watchs').split('\n') : if os.path.isdir(watch) : self.watchs.append(watch) if conf.options(self.name) : self.items = conf.get(self.name, 'db_table').split('|') except : traceback.print_exc() return False self.sql = SQLTools(db, self.name) self.verbose = verbose return True def make_db(self) : self.sql.create(self.items) for raw in self.get_raw_datas() : if self.is_include(raw) and not self.is_exclude(raw) : parsed = self.parse_data(raw) if parsed is not None : self.sql.insert(parsed) self.result['done'].append(parsed) else : self.result['fail'].append(raw) def get_raw_datas(self) : pass def is_exclude(self, raw) : folder, basename = os.path.split(raw) return basename in ['@eaDir', '.DS_Store', 'System Volume Information'] def is_include(self, rew) : return True def parse_data(self, raw) : return None