Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
def subs(conf):
    xp_str = './subscription[not(@state="inactive")][title][url]'
    valid_subs = conf.xml.subscriptions.xpath(xp_str)
    valid_subs = [sub for sub in valid_subs if sub.title.text and sub.url.text]
    sub_names = [sub.title.text for sub in valid_subs]
    dupes = set([x for x in sub_names if sub_names.count(x) > 1])
    if len(dupes) > 0:
        msg = "Found the following duplicate titles: %s" % ', '.join(dupes)
        output.config_fatal(msg)
    return valid_subs
Exemplo n.º 3
0
def subs(conf):
    xp_str = './subscription[not(@state="inactive")][title][url]'
    valid_subs = conf.xml.subscriptions.xpath(xp_str)
    valid_subs = [sub for sub in valid_subs if sub.title.text and sub.url.text]
    sub_names = [sub.title.text for sub in valid_subs]
    dupes = set([x for x in sub_names if sub_names.count(x) > 1])
    if len(dupes) > 0:
        msg = "Found the following duplicate titles: %s" % ', '.join(dupes)
        output.config_fatal(msg)
    return valid_subs
Exemplo n.º 4
0
 def __init__(self, args, merge_default=False):
     self.args = args
     self.paths = Paths(args)
     if merge_default:
         objectify.deannotate(DEFAULT_XML)
         self.xml = deepcopy(DEFAULT_XML)
         user_xml = self.get_xml()
         errors = merge(user_xml, self.xml, DEFAULT_XML, errors=[])
         for outcome in errors:
             output.config_fatal(outcome.msg)
     else:
         self.xml = self.get_xml()
Exemplo n.º 5
0
 def get_xml(self):
     '''Returns the XML tree root harvested from the users poca.xml file.'''
     try:
         with open(self.paths.config_file, 'r') as f:
             xml_object = objectify.parse(f)
         return xml_object.getroot()
     except etree.XMLSyntaxError as e:
         msg = 'Could not parse %s. Parser said:\n%s' % \
             (self.paths.config_file, str(e))
         output.config_fatal(msg)
     except PermissionError:
         msg = 'Could not read %s' % self.paths.config_file
         output.config_fatal(msg)
Exemplo n.º 6
0
 def get_xml(self):
     '''Returns the XML tree root harvested from the users poca.xml file.'''
     try:
         with open(self.paths.config_file, 'r') as f:
             xml_object = objectify.parse(f)
         return xml_object.getroot()
     except etree.XMLSyntaxError as e:
         msg = 'Could not parse %s. Parser said:\n%s' % \
             (self.paths.config_file, str(e))
         output.config_fatal(msg)
     except PermissionError:
         msg = 'Could not read %s' % self.paths.config_file
         output.config_fatal(msg)
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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)