aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-07-17 08:08:57 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-07-18 23:26:27 +0300
commit80b18d245693314b275aae1fe535e0335fc14d83 (patch)
treeb6524fe54e3206ea46fa1f35b259ddcd04d6fc7f
parentAdded a module to fetch ebuilds via URLs (diff)
downloadpomu-80b18d245693314b275aae1fe535e0335fc14d83.tar.gz
pomu-80b18d245693314b275aae1fe535e0335fc14d83.tar.bz2
pomu-80b18d245693314b275aae1fe535e0335fc14d83.zip
Implemented user changes integration
minor refactoring
-rw-r--r--pomu/package.py24
-rw-r--r--pomu/patch/patch.py54
-rw-r--r--pomu/repo/repo.py25
3 files changed, 88 insertions, 15 deletions
diff --git a/pomu/package.py b/pomu/package.py
index 4a39cd3..e0714dd 100644
--- a/pomu/package.py
+++ b/pomu/package.py
@@ -59,6 +59,10 @@ class Package():
res.append(path.split(k))
return res
+ @property
+ def ebuild_path(self):
+ return path.join(self.category, self.name, '{}-{}.ebuild'.format(self.name, self.version))
+
def strip_root(self, d_path):
"""Strip the root component of d_path"""
# the path should be either relative, or a child of root
@@ -89,12 +93,28 @@ class Package():
def patch(self, patch):
list_add(self.patches, patch)
- def apply_patches(self):
+ def apply_patches(self, revert=False):
"""Applies a sequence of patches at the root (after merging)"""
ps = PatchSet()
for p in self.patches:
ps.parse(open(p, 'r'))
- ps.apply(root=self.root)
+ for patch in ps:
+ if '.ebuild' in ps.target:
+ ps.source = self.ebuild_path
+ ps.target = self.ebuild_path
+ elif '/files/' in ps.target:
+ comps = ps.target.split('/')
+ comps = [self.category, self.name] + comps[comps.index('files'):]
+ ps.target = '/'.join(comps)
+ if not ps.source.split('/'[-2:] == ['dev', 'null']):
+ ps.source = '/'.join(comps)
+ else:
+ pass
+
+ if revert:
+ ps.revert(root=self.root)
+ else:
+ ps.apply(root=self.root)
return Result.Ok()
def gen_manifests(self, dst):
diff --git a/pomu/patch/patch.py b/pomu/patch/patch.py
index 3275cf9..4a8357c 100644
--- a/pomu/patch/patch.py
+++ b/pomu/patch/patch.py
@@ -1,7 +1,7 @@
"""
"""
-from os import path, walk, makedirs
+from os import path, walk, makedirs, remove
from shutil import copy2
from time import time
@@ -21,9 +21,10 @@ def process_changes(_repo):
repo = Repo(_repo.root)
chans = repo.head.commit.diff(None, create_patch=True)
new_files = repo.untracked_files
- all_pkgs = _repo.get_packages
+ all_pkgs = _repo.get_packages()
res = {x: [] for x in all_pkgs}
- pkgs = ls
+
+ ## Process user-made changes to package files
for f in new_files: # process untracked files
pkpref = path.dirname(f).split('/')[0:1].join('/')
if pkpref in res:
@@ -41,9 +42,53 @@ def process_changes(_repo):
patch_name = '{}-user_changes.patch'.format(int(time.time()))
pkg.add_patch(patch_contents, patch_name)
repo.index.add([x.a_path for x in diffs])
- repo.index.add([path.join(_repo.root, 'metadata', cat, name, patch_name)])
+ repo.index.add([path.join('metadata', cat, name, patch_name)])
repo.index.commit('{}/{}: imported user changes'.format(cat, name))
+ ## Process patch order changes
+ res = {x: [] for x in all_pkgs}
+ applied = {x: [] for x in all_pkgs}
+ for diff in chans:
+ if not len(diff.a_path.split('/')) == 4:
+ continue
+ _, cat, name, __ = diff.a_path.split('/')
+ if _ != 'metadata' or __ != 'PATCH_ORDER':
+ continue
+ if '/'.join([cat, name]) not in res:
+ continue
+ orig = repo.odb.stream(diff.a_blob.binsha).read().decode('utf-8')
+ pkg = _repo.get_package(cat, name)
+ orig_lines = [path.join(pkg.pkgdir, x.strip()) for x in orig.split('\n') if x.strip() != '']
+ ps = PatchSet()
+ pkg.patches = orig_lines
+ pkg.apply_patches(revert=True)
+ pkg = _repo.get_package(cat, name)
+ pkg.patches = pkg.patch_list
+ applied['{}/{}'.format(cat, name)].extend(pkg.patches)
+ pkg.apply_patches()
+ repo.index.add([diff.a_path, pkg.root])
+ repo.index.commit('{}/{}: modified patch order'.format(cat, name))
+
+
+ ## Process new patch files
+ res = {x: [] for x in all_pkgs}
+ for f in new_files:
+ if not f.startswith('metadata/'):
+ continue
+ pkpref = path.dirname(f).split('/')[1:2].join('/')
+ if f.split('/')[-1] in applied[pkpref]: #skip, we've added the patch in the previous step
+ continue
+ if pkpref in res:
+ res[pkpref].append(f)
+ for _pkg, diffs in res.items(): # apply each newly added patch
+ pkg = _repo.get_package(cat, name)
+ cat, name, *_ = cpv_split(_pkg)
+ for d in diffs:
+ pkg.patch(d)
+ repo.index.add(diffs)
+ repo.index.add[path.join(cat, name)]
+ repo.index.commit('{}/{}: applied patches'.format(cat, name))
+
def new_file_patch(repo, newf):
with open(path.join(repo.root, newf), 'r') as f:
lines = ['+' + x.strip('\n') for x in f.readlines()]
@@ -55,3 +100,4 @@ def diff_header(a_path, b_path, lines=None):
if lines:
header.append('@@ -0,0 +1,' + lines + ' @@')
return header
+ filename = path.join(self.category, self.name, '{}-{}.format')
diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py
index 1530dfa..4ca7a76 100644
--- a/pomu/repo/repo.py
+++ b/pomu/repo/repo.py
@@ -184,10 +184,14 @@ def pomu_active_repo(no_portage=None, repo_path=None):
return Result.Err('pomu is not initialized')
class MergedPackage(Package):
- def patch(self, patch):
- pkgdir = path.join(self.root, 'metadata', 'pomu', self.category, self.name)
+ @property
+ def pkgdir(self):
+ ret = path.join(self.root, 'metadata', 'pomu', self.category, self.name)
if self.slot != '0':
- pkgdir = path.join(pkgdir, self.slot)
+ ret = path.join(ret, self.slot)
+ return ret
+
+ def patch(self, patch):
if isinstance(patch, list):
for x in patch:
self.patch(x)
@@ -198,18 +202,21 @@ class MergedPackage(Package):
self.add_patch(patch)
return Result.Ok()
+ @property
+ def patch_list(self):
+ with open(path.join(self.pkgdir, 'PATCH_ORDER'), 'r') as f:
+ lines = [x.strip() for x in f.readlines() if x.strip() != '']
+ return lines
+
def add_patch(self, patch, name=None): # patch is a path, unless name is passed
- pkgdir = path.join(self.root, 'metadata', 'pomu', self.category, self.name)
- if self.slot != '0':
- pkgdir = path.join(pkgdir, self.slot)
- patch_dir = path.join(pkgdir, 'patches')
+ patch_dir = path.join(self.pkgdir, 'patches')
makedirs(patch_dir, exist_ok=True)
if name is None:
copy2(patch, patch_dir)
- with open(path.join(pkgdir, 'PATCH_ORDER'), 'w+') as f:
+ with open(path.join(self.pkgdir, 'PATCH_ORDER'), 'w+') as f:
f.write(path.basename(patch) + '\n')
else:
with open(path.join(patch_dir, name), 'w') as f:
f.write(patch)
- with open(path.join(pkgdir, 'PATCH_ORDER'), 'w+') as f:
+ with open(path.join(self.pkgdir, 'PATCH_ORDER'), 'w+') as f:
f.write(name + '\n')