def __init__(self, conf, sub): self.conf = conf self.sub = sub self.status = 0 self.sub_dir = os.path.join(self.conf.paths.base_dir,\ self.sub.title.text) self.outcome = files.check_path(self.sub_dir) if not self.outcome.success: return # merge sub settings and defaults defaults = deepcopy(self.conf.xml.defaults) rename = deepcopy(self.sub.rename) if hasattr(self.sub, 'rename') \ else None errors = merge(self.sub, defaults, self.conf.xml.defaults, errors=[]) self.outcome = errors[0] if errors else Outcome(True, '') defaults.tag = "subscription" self.sub = defaults if rename is not None: self.sub.rename = rename if not self.outcome.success: return # get jar and check for user deleted files self.udeleted = [] self.jar, self.outcome = history.get_subjar(self.conf.paths, self.sub) if not self.outcome.success: return self.check_jar() if not self.outcome.success: return # get feed, combine with jar and filter the lot feed = Feed(self.sub, self.jar, self.udeleted) self.status = feed.status if self.status == 301: self.outcome = Outcome(True, 'Feed has moved. Config updated.') self.new_url = feed.href elif self.status == 304: self.outcome = Outcome(True, 'Not modified') return elif self.status >= 400: self.outcome = Outcome(False, feed.bozo_exception) return else: self.outcome = Outcome(True, 'Success') combo = Combo(feed, self.jar, self.sub) self.wanted = Wanted(self.sub, feed, combo, self.jar.del_lst, self.sub_dir) self.outcome = self.wanted.outcome if not self.outcome.success: return from_the_top = self.sub.find('from_the_top') or 'no' if from_the_top == 'no': self.wanted.lst.reverse() # subupgrade will delete unwanted and download lacking self.unwanted = [x for x in self.jar.lst if x not in self.wanted.lst] self.lacking = [x for x in self.wanted.lst if x not in self.jar.lst]
def __init__(self, conf, sub): self.conf = conf self.sub = sub self.status = 0 self.sub_dir = os.path.join(self.conf.xml.settings.base_dir.text, self.sub.title.text) self.outcome = files.check_path(self.sub_dir) if not self.outcome.success: return # merge sub settings and defaults defaults = deepcopy(self.conf.xml.defaults) rename = deepcopy(self.sub.rename) if hasattr(self.sub, 'rename') \ else None errors = merge(self.sub, defaults, self.conf.xml.defaults, errors=[]) self.outcome = errors[0] if errors else Outcome(True, '') defaults.tag = "subscription" self.sub = defaults if rename is not None: self.sub.rename = rename if not self.outcome.success: return # get jar and check for user deleted files self.udeleted = [] self.jar, self.outcome = history.get_subjar(self.conf.paths, self.sub) if not self.outcome.success: return self.check_jar() if not self.outcome.success: return # get feed, combine with jar and filter the lot feed = Feed(self.sub, self.jar, self.udeleted) self.status = feed.status if self.status == 301: self.outcome = Outcome(True, 'Feed has moved. Config updated.') self.new_url = feed.href elif self.status == 304: self.outcome = Outcome(True, 'Not modified') return elif self.status >= 400: self.outcome = Outcome(False, feed.bozo_exception) return else: self.outcome = Outcome(True, 'Success') combo = Combo(feed, self.jar, self.sub) self.wanted = Wanted(self.sub, feed, combo, self.jar.del_lst, self.sub_dir) self.outcome = self.wanted.outcome if not self.outcome.success: return from_the_top = self.sub.find('from_the_top') or 'no' if from_the_top == 'no': self.wanted.lst.reverse() # subupgrade will delete unwanted and download lacking self.unwanted = [x for x in self.jar.lst if x not in self.wanted.lst] self.lacking = [x for x in self.wanted.lst if x not in self.jar.lst]
def save(self): '''Saves jar instance to file using pickle''' outcome = files.check_path(os.path.dirname(self.db_filename)) if outcome.success: with open(self.db_filename, 'wb') as f: pickle.dump(self, f) outcome = Outcome(True, 'Pickle successful') return outcome
def test_paths(self): '''Checks for presence of ~/.poca and ~/.poca/poca.xml''' for check_dir in [self.config_dir, self.db_dir]: outcome = files.check_path(check_dir) if not outcome.success: output.config_fatal(outcome.msg) if not path.isfile(self.config_file): outcome = xmlconf.write_config_file(self.config_file) output.config_fatal(outcome.msg)
def test_paths(self, args): '''Checks for presence of ~/.poca/poca.xml. If that doesn't exist, try to create it. Also, check for existance of the db directory.''' if not path.isfile(self.config_file): config_dir_outcome = files.check_path(self.config_dir) if not config_dir_outcome.success: output.config_fatal(config_dir_outcome.msg) config_file_outcome = xmlconf.write_config_file(self.config_file) output.config_fatal(config_file_outcome.msg) # test db_dir is writable db_dir_outcome = files.check_path(self.db_dir) if not db_dir_outcome.success: output.config_fatal(db_dir_outcome.msg) try: if args.logfile: logfile_outcome = files.check_file_write(self.log_file) if not logfile_outcome.success: output.config_fatal(logfile_outcome.msg) # poca-subscribe does not have logfile as argument option except AttributeError: pass
def test_base_dir(self, base_dir): # test base_dir is writable self.base_dir = base_dir base_dir_outcome = files.check_path(self.base_dir) if not base_dir_outcome.success: output.config_fatal(base_dir_outcome.msg)