|
@@ -3,11 +3,30 @@ import subprocess
|
|
|
|
|
|
from .pkgbuild import PKGBUILD
|
|
|
|
|
|
-
|
|
|
class Package(object):
|
|
|
- def __init__(self, config):
|
|
|
+ def __init__(self, repo, config):
|
|
|
+ self.repo = repo
|
|
|
self.config = config
|
|
|
|
|
|
+ def _exec(self, *args):
|
|
|
+ try:
|
|
|
+ subprocess.check_output(args, cwd=self.path)
|
|
|
+
|
|
|
+ except subprocess.CalledProcessError as e:
|
|
|
+ print(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"]
|
|
@@ -19,20 +38,35 @@ class Package(object):
|
|
|
|
|
|
@property
|
|
|
def path(self):
|
|
|
- return os.path.join(self.config.config.cachedir, self.name)
|
|
|
+ return os.path.join(self.repo.config.config['cachedir'], self.name)
|
|
|
+
|
|
|
|
|
|
@property
|
|
|
def PKGBUILD(self):
|
|
|
if not os.path.exists(self.path):
|
|
|
- subprocess.check_call(["git", "clone", self.url],
|
|
|
- cwd=self.config.config.cachedir)
|
|
|
+ self._clone()
|
|
|
+
|
|
|
+ if not os.path.exists(os.path.join(self.path, "PKGBUILD")):
|
|
|
+ self.update()
|
|
|
|
|
|
if not hasattr(self, '_PKGBUILD'):
|
|
|
- path = os.path.join(self.path, 'PKGBUILD')
|
|
|
- self._PKGBUILD = PKGBUILD(path)
|
|
|
+ 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):
|
|
@@ -40,10 +74,10 @@ class Repo(object):
|
|
|
self.packages = []
|
|
|
for package in self.config["packages"]:
|
|
|
if isinstance(package, str):
|
|
|
- self.packages.append(Package(dict(name=package)))
|
|
|
+ self.packages.append(Package(self, dict(name=package)))
|
|
|
|
|
|
else:
|
|
|
- self.packages.append(Package(package))
|
|
|
+ self.packages.append(Package(self, package))
|
|
|
|
|
|
@property
|
|
|
def name(self):
|