aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-06-30 04:49:25 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-06-30 04:49:25 +0300
commitc94c01482fb6cdbe017d33ed0668bcb80ba06017 (patch)
treeb3d4169f121c865af037c6753d94e1978a1c6e85
parentFix unit tests (diff)
downloadpomu-c94c01482fb6cdbe017d33ed0668bcb80ba06017.tar.gz
pomu-c94c01482fb6cdbe017d33ed0668bcb80ba06017.tar.bz2
pomu-c94c01482fb6cdbe017d33ed0668bcb80ba06017.zip
Multiple changes and fixes for installation
make package backend optional fix merge destination makedir properly add files to git index compare package slot with default the right way multiple fixes in writing metadata changed tests to reflect current code and pass
-rw-r--r--pomu/cli.py5
-rw-r--r--pomu/package.py6
-rw-r--r--pomu/repo/repo.py35
-rw-r--r--pomu/source/file.py2
-rw-r--r--pomu/source/portage.py2
-rw-r--r--tests/test_dispatch.py47
-rw-r--r--tests/test_init.py6
7 files changed, 57 insertions, 46 deletions
diff --git a/pomu/cli.py b/pomu/cli.py
index 9a0b9bf..72cec9b 100644
--- a/pomu/cli.py
+++ b/pomu/cli.py
@@ -120,8 +120,9 @@ def show(package):
print('Merged into repository', repo.name, 'at', repo.root)
for f in pkg.files:
print(' ', path.join(*f))
- print('Backend:', pkg.backend.__name__)
- print('Backend detailes:', pkg.backend)
+ if pkg.backend:
+ print('Backend:', pkg.backend.__name__)
+ print('Backend detailes:', pkg.backend)
def main_():
try:
diff --git a/pomu/package.py b/pomu/package.py
index 55ec994..7c9321e 100644
--- a/pomu/package.py
+++ b/pomu/package.py
@@ -14,7 +14,7 @@ from pomu.util.fs import strip_prefix
from pomu.util.result import Result
class Package():
- def __init__(self, backend, name, root, category=None, version=None, slot='0', d_path=None, files=None, filemap=None):
+ def __init__(self, name, root, backend=None, category=None, version=None, slot='0', d_path=None, files=None, filemap=None):
"""
Parameters:
backend - specific source module object/class
@@ -76,7 +76,7 @@ class Package():
wd, _ = path.split(trg)
dest = path.join(dst, wd)
try:
- makedirs(wd, exists_ok=True)
+ makedirs(dest, exist_ok=True)
copy2(src, dest)
except PermissionError:
return Result.Err('You do not have enough permissions')
@@ -96,7 +96,7 @@ class Package():
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=d)
if ret.returncode != 0:
- return Result.Err('Failed to generate manifest at', d)
+ return Result.Err('Failed to generate manifest at ' + d)
if path.exists(path.join(d, 'Manifest')):
res.append(path.join(d, 'Manifest'))
return Result.Ok(res)
diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py
index 11a5c2c..f41e0e4 100644
--- a/pomu/repo/repo.py
+++ b/pomu/repo/repo.py
@@ -1,5 +1,5 @@
"""Subroutines with repositories"""
-from os import path, rmdir
+from os import path, rmdir, makedirs
from git import Repo
import portage
@@ -33,20 +33,20 @@ class Repository():
"""Merge a package (a pomu.package.Package package) into the repository"""
r = self.repo
pkgdir = path.join(self.pomu_dir, package.category, package.name)
- if package.slot != 0:
+ if package.slot != '0':
pkgdir = path.join(pkgdir, package.slot)
package.merge_into(self.root).expect('Failed to merge package')
for wd, f in package.files:
- r.index.add(path.join(self.root, wd, f))
+ r.index.add([path.join(wd, f)])
manifests = package.gen_manifests(self.root).expect()
for m in manifests:
- r.index.add(m)
+ r.index.add([m])
self.write_meta(pkgdir, package, manifests)
with open(path.join(self.pomu_dir, 'world'), 'a+') as f:
- f.write(package.category, '/', package.name)
+ f.write('{}/{}'.format(package.category, package.name))
f.write('\n' if package.slot == '0' else ':{}\n'.format(package.slot))
- r.index.add(path.join(self.pomu_dir, package.name))
- r.index.add(self.pomu_dir)
+ r.index.add([path.join(self.pomu_dir, package.category, package.name)])
+ r.index.add([path.join(self.pomu_dir, 'world')])
r.index.commit('Merged package ' + package.name)
return Result.Ok('Merged package ' + package.name + ' successfully')
@@ -58,16 +58,17 @@ class Repository():
package - the package object
manifests - list of generated manifest files
"""
- with open(path.join(pkgdir, 'FILES'), 'w') as f:
- for w, f in package.files:
- f.write('{}/{}\n'.format(w, f))
+ makedirs(pkgdir, exist_ok=True)
+ with open(path.join(pkgdir, 'FILES'), 'w+') as f:
+ for wd, fil in package.files:
+ f.write('{}/{}\n'.format(wd, fil))
for m in manifests:
f.write('{}\n'.format(strip_prefix(m, self.root)))
if package.backend:
- with open(path.join(pkgdir, 'BACKEND'), 'w') as f:
+ with open(path.join(pkgdir, 'BACKEND'), 'w+') as f:
f.write('{}\n'.format(package.backend.__name__))
package.backend.write_meta(pkgdir)
- with open(path.join(pkgdir, 'VERSION')) as f:
+ with open(path.join(pkgdir, 'VERSION'), 'w+') as f:
f.write(package.version)
def unmerge(self, package):
@@ -97,14 +98,16 @@ class Repository():
pkgdir = path.join(self.pomu_dir, category, name)
else:
pkgdir = path.join(self.pomu_dir, category, name, slot)
- with open(path.join(pkgdir, 'BACKEND'), 'r') as f:
- bname = f.readline().strip()
- backend = dispatcher.backends[bname].from_meta_dir(pkgdir)
+ backend = None
+ if path.exists(path.join(pkgdir, 'BACKEND')):
+ with open(path.join(pkgdir, 'BACKEND'), 'r') as f:
+ bname = f.readline().strip()
+ backend = dispatcher.backends[bname].from_meta_dir(pkgdir)
with open(path.join(pkgdir, 'VERSION'), 'r') as f:
version = f.readline().strip()
with open(path.join(pkgdir, 'FILES'), 'r') as f:
files = [x.strip() for x in f]
- return Package(backend, name, self.root, category=category, version=version, slot=slot, files=files)
+ return Package(name, self.root, backend, category=category, version=version, slot=slot, files=files)
def get_package(self, name, category=None, slot=None):
"""Get a package by name, category and slot"""
diff --git a/pomu/source/file.py b/pomu/source/file.py
index d3fc7ed..ffd7c07 100644
--- a/pomu/source/file.py
+++ b/pomu/source/file.py
@@ -22,7 +22,7 @@ class LocalEbuild():
self.path = path
def fetch(self):
- return Package(self, self.name, '/', self.category, self.version,
+ return Package(self.name, '/', self, self.category, self.version,
filemap = {
path.join(
self.category,
diff --git a/pomu/source/portage.py b/pomu/source/portage.py
index e71f539..1dc740b 100644
--- a/pomu/source/portage.py
+++ b/pomu/source/portage.py
@@ -25,7 +25,7 @@ class PortagePackage():
self.slot = slot
def fetch(self):
- return Package(self, self.name, portage_repo_path(self.repo),
+ return Package(self.name, portage_repo_path(self.repo), self,
category=self.category, version=self.version, slot=self.slot,
files=[path.join(self.category, self.name, 'metadata.xml'),
path.join(self.category, self.name, self.name + '-' + self.version + '.ebuild')])
diff --git a/tests/test_dispatch.py b/tests/test_dispatch.py
index ebb450f..58d08fb 100644
--- a/tests/test_dispatch.py
+++ b/tests/test_dispatch.py
@@ -1,7 +1,7 @@
import shutil
import unittest
-from os import path
+from os import path, makedirs
from tempfile import mkdtemp
from pomu.package import Package
@@ -20,13 +20,15 @@ class DummySource():
@classmethod
def fetch_package(cls, uri):
- return Package(cls, 'test', cls.path)
+ return Package('test', cls.path, backend=cls, category='test')
+
class DispatcherTests(unittest.TestCase):
def setUp(self):
pomu_active_repo._drop()
self.source_path = mkdtemp()
- with open(path.join(self.source_path, 'test.ebuild'), 'w+') as f:
+ makedirs(path.join(self.source_path, 'test'))
+ with open(path.join(self.source_path, 'test', 'test.ebuild'), 'w+') as f:
f.write('# Copytight 1999-2017\nAll Rights Reserved\nEAPI="0"\n')
DummySource.path = self.source_path
@@ -37,17 +39,18 @@ class DispatcherTests(unittest.TestCase):
def testFetch(self):
pkg = dispatcher.get_package('/test').unwrap()
- self.assertEqual(pkg.files, [('', 'test.ebuild')])
+ self.assertEqual(pkg.files, [('test', 'test.ebuild')])
def tearDown(self):
shutil.rmtree(self.source_path)
-"""
+
class InstallTests(unittest.TestCase):
def setUp(self):
pomu_active_repo._drop()
self.source_path = mkdtemp()
- with open(path.join(self.source_path, 'test.ebuild'), 'w+') as f:
+ makedirs(path.join(self.source_path, 'test'))
+ with open(path.join(self.source_path, 'test', 'test.ebuild'), 'w+') as f:
f.write('# Copytight 1999-2017\nAll Rights Reserved\nEAPI="0"\n')
DummySource.path = self.source_path
@@ -60,24 +63,24 @@ class InstallTests(unittest.TestCase):
shutil.rmtree(self.repo_dir)
def testPkgCreate(self):
- pkg = Package('test', self.source_path, files=['test.ebuild'])
- self.assertEqual(pkg.files, [('', 'test.ebuild')])
-
- def testPkgMerge(self):
- pkg = Package('test', self.source_path)
- self.repo.merge(pkg).expect()
+ pkg = Package('test', self.source_path, category='test', files=['test/test.ebuild'])
+ self.assertEqual(pkg.files, [('test', 'test.ebuild')])
def testPortagePkg(self):
pkg = dispatcher.get_package('sys-apps/portage').expect()
self.repo.merge(pkg).expect()
- def testPkgUnmerge(self):
- pkg = Package('test', self.source_path)
- self.repo.merge(pkg).expect()
- with self.subTest(i=0):
- self.repo.unmerge(pkg).expect()
- with self.subTest(i=1):
- self.repo.remove_package('test').expect()
- with self.subTest(i=2):
- self.repo.remove_package('tset').expect_err()
-"""
+# TODO: convert to LocalEbuildFile backend
+# def testPkgMerge(self):
+# pkg = Package('test', self.source_path, category='test')
+# self.repo.merge(pkg).expect()
+#
+# def testPkgUnmerge(self):
+# pkg = Package('test', self.source_path, category='test')
+# self.repo.merge(pkg).expect()
+# with self.subTest(i=0):
+# self.repo.unmerge(pkg).expect()
+# with self.subTest(i=1):
+# self.repo.remove_package('test').expect()
+# with self.subTest(i=2):
+# self.repo.remove_package('tset').expect_err()
diff --git a/tests/test_init.py b/tests/test_init.py
index 0c68324..bece6f9 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -30,7 +30,6 @@ class PlainRepoInitialization(unittest.TestCase):
class PortageRepoInitialization(unittest.TestCase):
def setUp(self):
- pomu_active_repo._drop()
os.environ['EROOT'] = REPO_PATH
os.environ['ROOT'] = REPO_PATH
os.environ['PORTAGE_CONFIGROOT'] = REPO_PATH
@@ -42,6 +41,11 @@ class PortageRepoInitialization(unittest.TestCase):
self.REPO_DIR = REPO_DIR
def tearDown(self):
+ pomu_active_repo._drop()
+ del os.environ['EROOT']
+ del os.environ['ROOT']
+ del os.environ['PORTAGE_CONFIGROOT']
+ importlib.reload(portage)
rmtree(REPO_PATH)
def testRepoList(self):