diff --git a/autorepo.xsd b/archrepo.xsd similarity index 96% rename from autorepo.xsd rename to archrepo.xsd index 27622ac..4752bb2 100644 --- a/autorepo.xsd +++ b/archrepo.xsd @@ -1,8 +1,8 @@ diff --git a/build.py b/build.py index 5256069..be64ee8 100755 --- a/build.py +++ b/build.py @@ -21,24 +21,58 @@ from lxml import etree # TODO: track which versions are built so we don't need to consistently rebuild ALL packages +# TODO: logging # TODO: should this be a configuration option? aurbase = 'https://aur.archlinux.org' _dflts = {'cfgfile': '~/.config/optools/arch/autorepo.xml'} +class Repo(object): + def __init__(self, repo_xml): + self.repo_xml = repo_xml + self.gpg = None + + def _initSigner(self): + + self.gpg = gpg.Context() + + # Just grab the first private key until we flesh this out. + for k in self.gpg.keylist(secret = True): + if k.can_sign: + self.gpg.signers = [k] + break + return() + class Packager(object): - def __init__(self, cfgfile = _dflts['cfgfile'], *args, **kwargs): - user_params = kwargs - self.args = copy.deepcopy(_dflts) - self.args.update(user_params) + def __init__(self, cfgfile = _dflts['cfgfile'], validate = True, *args, **kwargs): + self.cfgfile = os.path.abspath(os.path.expanduser(cfgfile)) + self.cfg = None + self.xml = None + self.schema = None + self._initCfg(validate = validate) self.origdir = os.path.abspath(os.path.expanduser(os.getcwd())) self.gpg = None - self.args['destdir'] = os.path.abspath(os.path.expanduser(self.args['destdir'])) - if not self.args['pkgs']: - self.args['pkgs'] = _dflts['pkgs'] self._initSigner() + def _initCfg(self, validate = True): + with open(self.cfgfile, 'rb') as f: + self.xml = etree.parse(f) + self.xml.xinclude() + self.cfg = self.xml.getroot() + if validate: + if not self.schema: + from urllib.request import urlopen + xsi = self.cfg.nsmap.get('xsi', 'http://www.w3.org/2001/XMLSchema-instance') + schemaLocation = '{{{0}}}schemaLocation'.format(xsi) + schemaURL = self.cfg.attrib.get(schemaLocation, + ('http://git.square-r00t.net/Arch_Repo_Builder/plain/archrepo.xsd')) + with urlopen(schemaURL) as url: + self.schema = url.read() + self.schema = etree.XMLSchema(etree.XML(self.schema)) + self.schema.assertValid(self.xml) + return() + def buildPkgs(self, auronly = None): for p in self.args['pkgs']: print(p) @@ -103,15 +137,6 @@ class Packager(object): shutil.rmtree(extract_dir) return() - def _initSigner(self): - self.gpg = gpg.Context() - # Just grab the first private key until we flesh this out. - for k in self.gpg.keylist(secret = True): - if k.can_sign: - self.gpg.signers = [k] - break - return() - def _getAUR(self, pkgnm, extract_dir): dl_url = None pkg_srch = requests.get(os.path.join(self.args['aurbase'], @@ -173,6 +198,10 @@ class Packager(object): def parseArgs(): args = argparse.ArgumentParser(description = 'Build Pacman packages and update a local repository') + args.add_argument('-n', '--no-validate', + dest = 'validate', + action = 'store_false', + help = ('If specified, do NOT attempt to validate the config file (-c/--config)')) args.add_argument('-c', '--config', dest = 'cfgfile', default = _dflts['cfgfile'], diff --git a/example.pkgs.xml b/sample.config.xml similarity index 89% rename from example.pkgs.xml rename to sample.config.xml index 8942485..600143c 100644 --- a/example.pkgs.xml +++ b/sample.config.xml @@ -4,8 +4,8 @@ You can use external XML snippets if that's easier/cleaner (it usually is). --> + xmlns="http://git.square-r00t.net/Arch_Repo_Builder/tree/" + xsi:schemaLocation="http://git.square-r00t.net/Arch_Repo_Builder/plain/archrepo.xsd"> pkgnm pkgnm2