|
@@ -1,7 +1,9 @@
|
|
|
import os
|
|
|
-import subprocess
|
|
|
+import asyncio
|
|
|
|
|
|
from .pkgbuild import PKGBUILD
|
|
|
+from asyncio import subprocess
|
|
|
+from async_property import async_cached_property
|
|
|
|
|
|
|
|
|
class Package(object):
|
|
@@ -9,25 +11,26 @@ class Package(object):
|
|
|
self.repo = repo
|
|
|
self.config = config
|
|
|
|
|
|
- def _exec(self, *args):
|
|
|
- try:
|
|
|
- subprocess.run(args, cwd=self.path, capture_output=True, check=True,
|
|
|
- text=True)
|
|
|
+ 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"))
|
|
|
|
|
|
- except subprocess.CalledProcessError as e:
|
|
|
- print("\n".join([e.stdout, e.stderr]))
|
|
|
+ async def _git(self, *args):
|
|
|
+ await self._exec('git', *args)
|
|
|
|
|
|
- def _git(self, *args):
|
|
|
- self._exec('git', *args)
|
|
|
-
|
|
|
- def _clone(self):
|
|
|
+ async 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")
|
|
|
+ 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):
|
|
@@ -42,34 +45,34 @@ class Package(object):
|
|
|
def path(self):
|
|
|
return os.path.join(self.repo.config.config['cachedir'], self.name)
|
|
|
|
|
|
- @property
|
|
|
- def PKGBUILD(self):
|
|
|
+ @async_cached_property
|
|
|
+ async def PKGBUILD(self):
|
|
|
if not os.path.exists(self.path):
|
|
|
- self._clone()
|
|
|
+ await self._clone()
|
|
|
|
|
|
if not os.path.exists(os.path.join(self.path, "PKGBUILD")):
|
|
|
- self.update()
|
|
|
+ await self.update()
|
|
|
|
|
|
if not hasattr(self, '_PKGBUILD'):
|
|
|
self._PKGBUILD = PKGBUILD(os.path.join(self.path, 'PKGBUILD'))
|
|
|
|
|
|
return self._PKGBUILD
|
|
|
|
|
|
- def update(self):
|
|
|
+ async def update(self):
|
|
|
if not os.path.exists(os.path.join(self.path, '.git')):
|
|
|
- self._clone()
|
|
|
+ await 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")
|
|
|
+ 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")
|
|
|
|
|
|
- def makepkg(self, force=False):
|
|
|
+ async def makepkg(self, force=False):
|
|
|
if force:
|
|
|
- self._exec("makepkg", "-f")
|
|
|
+ await self._exec("makepkg", "-f")
|
|
|
else:
|
|
|
- self._exec("makepkg")
|
|
|
+ await self._exec("makepkg")
|
|
|
|
|
|
|
|
|
class Repo(object):
|