1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import os
- import subprocess
- from .pkgbuild import PKGBUILD
- class Package(object):
- def __init__(self, repo, config):
- self.repo = repo
- self.config = config
- def _exec(self, *args):
- try:
- subprocess.run(args, cwd=self.path, capture_output=True, check=True,
- text=True)
- except subprocess.CalledProcessError as e:
- print("\n".join([e.stdout,e.stderr]))
- def _git(self, *args):
- self._exec('git', *args)
- def _clone(self):
- if not os.path.exists(self.path):
- os.makedirs(self.path)
- self._git("init")
- self._git("remote", "add", "origin", self.url)
- self._git("fetch", "origin")
- self._git("checkout", "master")
- @property
- def name(self):
- return self.config["name"]
- @property
- def url(self):
- return self.config.get("url") or "https://aur.archlinux.org/{}.git".format(
- self.name)
- @property
- def path(self):
- return os.path.join(self.repo.config.config['cachedir'], self.name)
- @property
- def PKGBUILD(self):
- if not os.path.exists(self.path):
- self._clone()
- if not os.path.exists(os.path.join(self.path, "PKGBUILD")):
- self.update()
- if not hasattr(self, '_PKGBUILD'):
- self._PKGBUILD = PKGBUILD(os.path.join(self.path, 'PKGBUILD'))
- return self._PKGBUILD
- def update(self):
- if not os.path.exists(os.path.join(self.path, '.git')):
- self._clone()
- else:
- self._git("remote", "set-url", "origin", self.url)
- self._git("checkout", "-f")
- self._git("fetch", "--prune", "origin")
- self._git("checkout", "-B", "master", "origin/master")
- def makepkg(self):
- self._exec("makepkg")
- class Repo(object):
- def __init__(self, config):
- self.config = config
- self.packages = []
- for package in self.config["packages"]:
- if isinstance(package, str):
- self.packages.append(Package(self, dict(name=package)))
- else:
- self.packages.append(Package(self, package))
- @property
- def name(self):
- return self.config.name
- @property
- def id(self):
- return self.config.id
|