diff options
author | 2017-06-08 03:34:08 +0300 | |
---|---|---|
committer | 2017-06-08 03:34:08 +0300 | |
commit | 1e9ba4fda8486136991152d7af2bfe65c0e52c69 (patch) | |
tree | 83a0998170e68271a1fad8e90748ab238cc9ea9d | |
parent | Fix multiple issues with packages and repositories (diff) | |
download | pomu-1e9ba4fda8486136991152d7af2bfe65c0e52c69.tar.gz pomu-1e9ba4fda8486136991152d7af2bfe65c0e52c69.tar.bz2 pomu-1e9ba4fda8486136991152d7af2bfe65c0e52c69.zip |
Hook up sources, repo and dispatcher
Implement initial package recording, uninstalling
-rw-r--r-- | pomu/package.py | 2 | ||||
-rw-r--r-- | pomu/repo/repo.py | 31 | ||||
-rw-r--r-- | pomu/source/manager.py | 19 | ||||
-rw-r--r-- | pomu/util/fs.py (renamed from pomu/util/string.py) | 7 |
4 files changed, 54 insertions, 5 deletions
diff --git a/pomu/package.py b/pomu/package.py index 65c6d18..24fdf00 100644 --- a/pomu/package.py +++ b/pomu/package.py @@ -6,7 +6,7 @@ A package is supposed to be created by a package source from a set of files. from os import path -from pomu.util.string import strip_prefix +from pomu.util.fs import strip_prefix class Package(): def __init__(self, name, root, d_path=None, files=None): diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index f72b996..a30eaab 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -5,6 +5,8 @@ from shutil import copy2 from git import Repo import portage +from pomu.util.fs import remove_file + class Repository(): def __init__(self, root): if not pomu_status(root): @@ -16,6 +18,11 @@ class Repository(): def repo(self): return Repo(repo_path) + pomu_dir = property() + @pomu_dir.getter + def pomu_dir(self): + return path.join(self.root, 'metadata/pomu') + def merge(self, package): r = self.repo for wd, f in package.files: @@ -23,6 +30,9 @@ class Repository(): os.makedirs(dst) copy2(path.join(package.root, wd, f), dst) r.index.add(path.join(dst, f)) + with open(path.join(self.pomu_dir, package.name), 'w') as f: + f.write('{}/{}'.format(wd, f)) + r.index.add(path.join(self.pomu_dir, package.name)) r.index.commit('Merged package ' + package.name) return Result.Ok('Merged package ' + package.name ' successfully') @@ -30,12 +40,27 @@ class Repository(): r = self.repo for wd, f in package.files: dst = path.join(self.root, wd) - r.index.remove(path.join(self.root, wd, f)) - os.remove(path.join(self.root, wd, f)) + remove_file(path.join(dst, f)) try: rmdir(dst) except OSError: pass - self.repo.commit('Removed package ' + package.name + ' successfully') + pf = path.join(self.pomu_dir, package.name) + if path.isfile(pf): + remove_file(pf) + r.commit('Removed package ' + package.name + ' successfully') + return Result.Ok('Removed package ' + package.name ' successfully') + + def remove_package(self, name): + pf = path.join(self.pomu_dir, package.name) + if not path.isfile(pf): + return Result.Err('Package not found') + with open(pf, 'w') as f: + for insf in f: + remove_file(path.join(self.root, insf)) + remove_file(pf) + r.commit('Removed package ' + package.name + ' successfully') + return Result.Ok('Removed package ' + package.name ' successfully') + def portage_repos(): diff --git a/pomu/source/manager.py b/pomu/source/manager.py index 93c05c0..2847547 100644 --- a/pomu/source/manager.py +++ b/pomu/source/manager.py @@ -29,6 +29,8 @@ Example: #import bisect import inspect +from pomu.util.result import Result + class PackageDispatcher(): def __init__(self): self.handlers = [] @@ -66,3 +68,20 @@ class PackageDispatcher(): if handler(uri).is_ok(): return source return None + + def get_package(self, uri): + for priority, source, handler in self.handlers: + res = handler(uri) + if res.is_ok(): + return source.fetch_package(res.ok()) + return Result.Err('No handler found for package ' + uri) + + def install_package(self, uri): + pkg = self.get_package(uri).unwrap() + #TODO: write a helper function which expects pomu_active_repo + #alternatively, test for it before any command which requires a repo + return pomu_active_repo().unwrap().merge(pkg) + + def uninstall_package(self, uri): + pkg = self.get_package(uri).unwrap() + return pomu_active_repo().unwrap().unmerge(pkg) diff --git a/pomu/util/string.py b/pomu/util/fs.py index b7c2334..f5f448c 100644 --- a/pomu/util/string.py +++ b/pomu/util/fs.py @@ -1,6 +1,7 @@ """ -String utils +Filesystem utils """ +import os def strip_prefix(string, prefix): """Returns a string, stripped from its prefix""" @@ -8,3 +9,7 @@ def strip_prefix(string, prefix): return string[len(prefix):] else return string + +def remove_file(repo, dst): + repo.index.remove(dst) + os.remove(dst) |