aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-06-06 15:29:00 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-06-06 15:29:00 +0300
commit83bacf54aae3155844f53d8d059860961cde98c2 (patch)
treec0aaf8a52678eba5645739f3e7e0dc2d1a15ce34
parentAdd repository and package abstractions (diff)
downloadpomu-83bacf54aae3155844f53d8d059860961cde98c2.tar.gz
pomu-83bacf54aae3155844f53d8d059860961cde98c2.tar.bz2
pomu-83bacf54aae3155844f53d8d059860961cde98c2.zip
Process on package impl
-rw-r--r--pomu/package.py43
1 files changed, 34 insertions, 9 deletions
diff --git a/pomu/package.py b/pomu/package.py
index 8f0c2c2..f3319f1 100644
--- a/pomu/package.py
+++ b/pomu/package.py
@@ -6,18 +6,43 @@ A package is supposed to be created by a package source from a set of files.
from os import path
-from portage.util.string import strip_prefix
+from pomu.util.string import strip_prefix
class Package():
- def __init__(self, name, path):
+ def __init__(self, name, root, d_path=None, files=None):
+ """
+ Parameters:
+ name - name of the package
+ root - root path of the repository (if applicable)
+ d_path - a subdirectory of the root path, which would be sourced recursively.
+ could be a relative or an absolute path
+ files - a set of files to build a package from
+ """
self.name = name
- self.root = path
- self.read_files(files)
-
- #todo: file sets
- def read_files(self)
+ self.root = root
self.files = []
- for wd, dirs, files in os.walk(path):
- wd = strip_prefix(strip_prefix(wd, path), '/')
+ if d_path is None and files is None:
+ self.d_path = None
+ self.read_path(self.root)
+ elif files is None:
+ self.d_path = self.strip_root(d_path)
+ self.read_path(path.join(self.root, self.d_path))
+ elif d_path is None:
+ for f in files:
+ self.files.append(self.strip_root(f))
+ else:
+ raise ValueError('You should specify either d_path, or files')
+
+ def strip_root(self, d_path):
+ # the path should be either relative, or a child of root
+ if d_path.startswith('/'):
+ if path.commonprefix(d_path, root) != root:
+ raise ValueError('Path should be a subdirectory of root')
+ return strip_prefix(strip_prefix(d_path, root), '/')
+ return d_path
+
+ def read_path(self, d_path):
+ for wd, dirs, files in d_path:
+ wd = self.strip_root(wd)
self.files.extend([(wd, f) for f in files])