1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import os
- import asyncio
- from .pkgbuild import PKGBUILD
- from asyncio import subprocess
- from async_property import async_cached_property
- class Package(object):
- def __init__(self, repo, config):
- self.repo = repo
- self.config = config
- async def _exec(self, *args):
- p = await asyncio.create_subprocess_exec(*args,
- cwd=self.path,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- stdout, stderr = await p.communicate()
- if p.returncode:
- print(stdout.decode("utf-8"))
- async def _git(self, *args):
- await self._exec('git', *args)
- async def _clone(self):
- if not os.path.exists(self.path):
- os.makedirs(self.path)
- await self._git("init")
- await self._git("remote", "add", "origin", self.url)
- await self._git("fetch", "origin")
- await 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)
- @async_cached_property
- async def PKGBUILD(self):
- if not os.path.exists(self.path):
- await self._clone()
- if not os.path.exists(os.path.join(self.path, "PKGBUILD")):
- await self.update()
- if not hasattr(self, '_PKGBUILD'):
- self._PKGBUILD = PKGBUILD(os.path.join(self.path, 'PKGBUILD'))
- return self._PKGBUILD
- async def update(self):
- if not os.path.exists(os.path.join(self.path, '.git')):
- await self._clone()
- else:
- await self._git("remote", "set-url", "origin", self.url)
- await self._git("checkout", "-f")
- await self._git("fetch", "--prune", "origin")
- await self._git("checkout", "-B", "master", "origin/master")
- async def makepkg(self, force=False):
- if force:
- await self._exec("makepkg", "-f")
- else:
- await 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
|