|
@@ -6,31 +6,56 @@ from asyncio import subprocess
|
|
from async_property import async_cached_property
|
|
from async_property import async_cached_property
|
|
|
|
|
|
|
|
|
|
|
|
+class PackageException(Exception):
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
class Package(object):
|
|
class Package(object):
|
|
def __init__(self, repo, config):
|
|
def __init__(self, repo, config):
|
|
self.repo = repo
|
|
self.repo = repo
|
|
self.config = config
|
|
self.config = config
|
|
|
|
|
|
- async def _exec(self, *args):
|
|
|
|
|
|
+ async def _exec(self, *args, check=True):
|
|
p = await asyncio.create_subprocess_exec(*args,
|
|
p = await asyncio.create_subprocess_exec(*args,
|
|
cwd=self.path,
|
|
cwd=self.path,
|
|
stdout=subprocess.PIPE,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT)
|
|
stderr=subprocess.STDOUT)
|
|
stdout, stderr = await p.communicate()
|
|
stdout, stderr = await p.communicate()
|
|
- if p.returncode:
|
|
|
|
- print(stdout.decode("utf-8"))
|
|
|
|
|
|
+ if check and p.returncode:
|
|
|
|
+ raise PackageException(stdout.decode("utf-8"))
|
|
|
|
+
|
|
|
|
+ return p.returncode, stdout
|
|
|
|
+
|
|
|
|
+ async def _execAll(self, *tasks, check=True):
|
|
|
|
+ output = ""
|
|
|
|
+ for args in tasks:
|
|
|
|
+ code, stdout = await self._exec(*args, check=False)
|
|
|
|
+ output += stdout.decode('utf-8')
|
|
|
|
+ if code:
|
|
|
|
+ if check:
|
|
|
|
+ print(output)
|
|
|
|
+ break
|
|
|
|
|
|
- async def _git(self, *args):
|
|
|
|
- await self._exec('git', *args)
|
|
|
|
|
|
+ return code, output
|
|
|
|
+
|
|
|
|
+ async def _git(self, *args, check=True):
|
|
|
|
+ return await self._exec('git', *args, check=check)
|
|
|
|
+
|
|
|
|
+ async def _gitAll(self, *tasks, check=True):
|
|
|
|
+ for args in tasks:
|
|
|
|
+ args.insert(0, 'git')
|
|
|
|
+
|
|
|
|
+ return await self._execAll(*tasks, check=check)
|
|
|
|
|
|
async def _clone(self):
|
|
async def _clone(self):
|
|
if not os.path.exists(self.path):
|
|
if not os.path.exists(self.path):
|
|
os.makedirs(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")
|
|
|
|
|
|
+ return await self._gitAll(
|
|
|
|
+ ["init"],
|
|
|
|
+ ["remote", "add", "origin", self.url],
|
|
|
|
+ ["fetch", "origin"],
|
|
|
|
+ ["checkout", "master"])
|
|
|
|
|
|
@property
|
|
@property
|
|
def name(self):
|
|
def name(self):
|
|
@@ -60,19 +85,21 @@ class Package(object):
|
|
|
|
|
|
async def update(self):
|
|
async def update(self):
|
|
if not os.path.exists(os.path.join(self.path, '.git')):
|
|
if not os.path.exists(os.path.join(self.path, '.git')):
|
|
- await self._clone()
|
|
|
|
|
|
+ return await self._clone(check=False)
|
|
|
|
|
|
else:
|
|
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")
|
|
|
|
|
|
+ return await self._gitAll(
|
|
|
|
+ ["remote", "set-url", "origin", self.url],
|
|
|
|
+ ["checkout", "-f"],
|
|
|
|
+ ["fetch", "--prune", "origin"],
|
|
|
|
+ ["checkout", "-B", "master", "origin/master"],
|
|
|
|
+ check=False)
|
|
|
|
|
|
async def makepkg(self, force=False):
|
|
async def makepkg(self, force=False):
|
|
if force:
|
|
if force:
|
|
- await self._exec("makepkg", "-f")
|
|
|
|
|
|
+ return await self._exec("makepkg", "-f", check=False)
|
|
else:
|
|
else:
|
|
- await self._exec("makepkg")
|
|
|
|
|
|
+ return await self._exec("makepkg", check=False)
|
|
|
|
|
|
|
|
|
|
class Repo(object):
|
|
class Repo(object):
|