diff options
-rw-r--r-- | pomu/package.py | 9 | ||||
-rw-r--r-- | pomu/repo/repo.py | 2 | ||||
-rw-r--r-- | pomu/source/manager.py | 4 | ||||
-rw-r--r-- | pomu/util/cache.py | 5 | ||||
-rw-r--r-- | pomu/util/portage.py | 2 | ||||
-rw-r--r-- | tests/test_dispatch.py | 17 | ||||
-rw-r--r-- | tests/test_init.py | 4 |
7 files changed, 30 insertions, 13 deletions
diff --git a/pomu/package.py b/pomu/package.py index d59bd4f..55ec994 100644 --- a/pomu/package.py +++ b/pomu/package.py @@ -48,11 +48,18 @@ class Package(): else: raise ValueError('You should specify either d_path, files or filemap') + @property + def files(self): + res = [] + for k in self.filemap: + res.append(path.split(k)) + return res + def strip_root(self, d_path): """Strip the root component of d_path""" # the path should be either relative, or a child of root if d_path.startswith('/'): - if path.commonprefix(d_path, self.root) != self.root: + if path.commonprefix([d_path, self.root]) != self.root: raise ValueError('Path should be a subdirectory of root') return strip_prefix(strip_prefix(d_path, self.root), '/') return d_path diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index 8bbc7fb..11a5c2c 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -156,5 +156,5 @@ def pomu_active_repo(no_portage=None, repo_path=None): else: repo = pomu_active_portage_repo() if repo: - return Result.Ok(Repository(repo)) + return Result.Ok(Repository(portage_repo_path(repo), repo)) return Result.Err('pomu is not initialized') diff --git a/pomu/source/manager.py b/pomu/source/manager.py index b91bdd0..600a987 100644 --- a/pomu/source/manager.py +++ b/pomu/source/manager.py @@ -83,8 +83,8 @@ class PackageDispatcher(): """Get a source which accepts the package""" for priority, source, handler in self.handlers: if handler(uri).is_ok(): - return source - return None + return Result.Ok(source) + return Result.Err('No handler found for package ' + uri) def get_package(self, uri): """Fetch a package specified by the descriptor""" diff --git a/pomu/util/cache.py b/pomu/util/cache.py index 3419a4b..1c92a4e 100644 --- a/pomu/util/cache.py +++ b/pomu/util/cache.py @@ -8,7 +8,12 @@ class cached(): def __init__(self, fun): self.fun = fun self.__name__ = fun.__name__ + def __call__(self, *args): if not hasattr(self, 'retval'): self.retval = self.fun(*args).unwrap() return self.retval + + def _drop(self): + if hasattr(self, 'retval'): + del self.retval diff --git a/pomu/util/portage.py b/pomu/util/portage.py index 2cc93a9..3491dfa 100644 --- a/pomu/util/portage.py +++ b/pomu/util/portage.py @@ -6,7 +6,7 @@ import os from os import path -from portage.versions import suffix_value +from portage.versions import best from pomu.repo.repo import portage_repos, portage_repo_path from pomu.util.pkg import cpv_split, ver_str diff --git a/tests/test_dispatch.py b/tests/test_dispatch.py index 5ccba6d..ebb450f 100644 --- a/tests/test_dispatch.py +++ b/tests/test_dispatch.py @@ -6,32 +6,32 @@ from tempfile import mkdtemp from pomu.package import Package from pomu.repo.init import init_plain_repo -from pomu.repo.repo import Repository +from pomu.repo.repo import Repository, pomu_active_repo from pomu.source import dispatcher from pomu.util.result import Result @dispatcher.source class DummySource(): @dispatcher.handler(priority=3) - @classmethod - def parse(cls, uri): + def parse(uri): if uri.startswith('/'): return Result.Ok(uri[1:]) return Result.Err() @classmethod def fetch_package(cls, uri): - return Package('test', cls.path) + return Package(cls, 'test', cls.path) class DispatcherTests(unittest.TestCase): def setUp(self): + pomu_active_repo._drop() self.source_path = mkdtemp() - with path.join(self.source_path, 'test.ebuild') as f: + with open(path.join(self.source_path, 'test.ebuild'), 'w+') as f: f.write('# Copytight 1999-2017\nAll Rights Reserved\nEAPI="0"\n') DummySource.path = self.source_path def testDispatch(self): - self.assertEqual(dispatcher.get_package_source('/test').unwrap(), 'test') + self.assertEqual(dispatcher.get_package_source('/test').unwrap(), DummySource) self.assertTrue(dispatcher.get_package_source('test').is_err()) self.assertTrue(dispatcher.get_package('sys-apps/portage').is_ok()) @@ -42,10 +42,12 @@ class DispatcherTests(unittest.TestCase): def tearDown(self): shutil.rmtree(self.source_path) +""" class InstallTests(unittest.TestCase): def setUp(self): + pomu_active_repo._drop() self.source_path = mkdtemp() - with path.join(self.source_path, 'test.ebuild') as f: + with open(path.join(self.source_path, 'test.ebuild'), 'w+') as f: f.write('# Copytight 1999-2017\nAll Rights Reserved\nEAPI="0"\n') DummySource.path = self.source_path @@ -78,3 +80,4 @@ class InstallTests(unittest.TestCase): 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 5f0bd2d..0c68324 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -30,6 +30,7 @@ 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 @@ -49,4 +50,5 @@ class PortageRepoInitialization(unittest.TestCase): def testPortageCreate(self): self.assertTrue(init_portage_repo(True, REPO_DIR, REPO_PATH).is_ok()) importlib.reload(portage) - self.assertEqual(pomu_active_repo(), REPO_DIR) + repo = pomu_active_repo() + self.assertEqual(repo.name, REPO_DIR) |