diff options
-rw-r--r-- | morphlib/artifactresolver_tests.py | 3 | ||||
-rw-r--r-- | morphlib/artifactsplitrule.py | 14 | ||||
-rw-r--r-- | morphlib/builder2.py | 2 | ||||
-rwxr-xr-x | morphlib/exts/install-files.configure | 42 |
4 files changed, 50 insertions, 11 deletions
diff --git a/morphlib/artifactresolver_tests.py b/morphlib/artifactresolver_tests.py index 3a9b7f55..6f62b4d1 100644 --- a/morphlib/artifactresolver_tests.py +++ b/morphlib/artifactresolver_tests.py @@ -299,12 +299,15 @@ class ArtifactResolverTests(unittest.TestCase): def assert_depended_on_by_some(artifact, parents): self.assertNotEqual(len(artifact.dependents), 0) self.assertTrue(any(a in artifact.dependents for a in parents)) + def assert_depended_on_by_all(artifact, parents): self.assertNotEqual(len(artifact.dependents), 0) self.assertTrue(all(a in artifact.dependents for a in parents)) + def assert_depends_on_some(artifact, children): self.assertNotEqual(len(artifact.dependencies), 0) self.assertTrue(any(a in children for a in artifact.dependencies)) + def assert_depends_on_all(artifact, children): self.assertNotEqual(len(artifact.dependencies), 0) self.assertTrue(all(a in children for a in artifact.dependencies)) diff --git a/morphlib/artifactsplitrule.py b/morphlib/artifactsplitrule.py index f30b05a3..246691d8 100644 --- a/morphlib/artifactsplitrule.py +++ b/morphlib/artifactsplitrule.py @@ -31,6 +31,7 @@ class Rule(object): source it came from. ''' + def match(self, *args): return True @@ -42,6 +43,7 @@ class FileMatch(Rule): is counted as a valid match. ''' + def __init__(self, regexes): # Possible optimisation: compile regexes as one pattern self._regexes = [re.compile(r) for r in regexes] @@ -53,6 +55,7 @@ class FileMatch(Rule): class ArtifactMatch(Rule): '''Match an artifact's name against a list of regular expressions. ''' + def __init__(self, regexes): # Possible optimisation: compile regexes as one pattern self._regexes = [re.compile(r) for r in regexes] @@ -70,8 +73,10 @@ class ArtifactAssign(Rule): bar-runtime. ''' + def __init__(self, source_name, artifact_name): self._key = (source_name, artifact_name) + def match(self, (source_name, artifact_name)): return (source_name, artifact_name) == self._key @@ -84,8 +89,10 @@ class SourceAssign(Rule): system baz ''' + def __init__(self, source_name): self._source = source_name + def match(self, (source_name, artifact_name)): return source_name == self._source @@ -102,6 +109,7 @@ class SplitRules(collections.Iterable): generic catch-all matches. ''' + def __init__(self, *args): self._rules = list(*args) @@ -119,6 +127,7 @@ class SplitRules(collections.Iterable): and not repeating the artifact. ''' + seen = set() result = [] for artifact_name, rule in self._rules: @@ -135,6 +144,7 @@ class SplitRules(collections.Iterable): only used entry will be the first. ''' + return [a for a, r in self._rules if r.match(*args)] def partition(self, iterable): @@ -145,6 +155,7 @@ class SplitRules(collections.Iterable): logic in multiple places, it's here as a convenience method. ''' + matches = collections.defaultdict(list) overlaps = collections.defaultdict(set) unmatched = set() @@ -209,6 +220,7 @@ def unify_chunk_matches(morphology): by building the chunk to the chunk artifact they should be put in. ''' + split_rules = SplitRules() for ca_name, patterns in ((d['artifact'], d['include']) @@ -235,6 +247,7 @@ def unify_stratum_matches(morphology): strata to the stratum artifact they should be put in. ''' + assignment_split_rules = SplitRules() for spec in morphology['chunks']: source_name = spec['name'] @@ -271,6 +284,7 @@ def unify_system_matches(morphology): by building the chunk to the chunk artifact they should be put in. ''' + name = morphology['name'] + '-rootfs' split_rules = SplitRules() diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 43ae48c4..2dca738c 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -448,11 +448,13 @@ class ChunkBuilder(BuilderBase): while path != '': yield path path = os.path.dirname(path) + def parentify(filenames): names = set() for name in filenames: names.update(all_parents(name)) return sorted(names) + parented_paths = \ parentify(file_paths + ['baserock/%s.meta' % chunk_artifact_name]) diff --git a/morphlib/exts/install-files.configure b/morphlib/exts/install-files.configure index 669fc518..8ba61b4e 100755 --- a/morphlib/exts/install-files.configure +++ b/morphlib/exts/install-files.configure @@ -1,5 +1,5 @@ #!/usr/bin/python -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013-2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,9 +35,9 @@ class InstallFilesConfigureExtension(cliapp.Application): '''Install the files specified in the manifests listed in INSTALL_FILES - The manifest is formatted as: + Entries in the manifest are formatted as: - <octal mode> <uid decimal> <gid decimal> <filename> + [overwrite] <octal mode> <uid decimal> <gid decimal> <filename> Where the filename is how the file is found inside whatever directory the manifest is stored in, and also the path within the system to @@ -47,6 +47,18 @@ class InstallFilesConfigureExtension(cliapp.Application): This extension supports files, symlinks and directories. + For example, + + 0100644 0 0 /etc/issue + + creates a regular file at /etc/issue with 644 permissions, + uid 0 and gid 0, if the file doesn't already exist. + + overwrite 0100644 0 0 /etc/issue + + creates a regular file at /etc/issue with 644 permissions, + uid 0 and gid 0, if the file already exists it is overwritten. + ''' def process_args(self, args): @@ -65,14 +77,22 @@ class InstallFilesConfigureExtension(cliapp.Application): self.install_entry(entry, manifest_dir, target_root) def install_entry(self, entry, manifest_root, target_root): - entry_data = re.split('\W+', entry.strip(), maxsplit=3) - mode = int(entry_data[0], 8) - uid = int(entry_data[1]) - gid = int(entry_data[2]) - path = entry_data[3] + m = re.match('(overwrite )?([0-7]+) ([0-9]+) ([0-9]+) (\S+)', entry) + + if m: + overwrite = m.group(1) + mode = int(m.group(2), 8) # mode is octal + uid = int(m.group(3)) + gid = int(m.group(4)) + path = m.group(5) + else: + raise cliapp.AppException('Invalid manifest entry, ' + 'format: [overwrite] <octal mode> <uid decimal> <gid decimal> ' + '<filename>') + dest_path = os.path.join(target_root, './' + path) if stat.S_ISDIR(mode): - if os.path.exists(dest_path): + if os.path.exists(dest_path) and not overwrite: dest_stat = os.stat(dest_path) if (mode != dest_stat.st_mode or uid != dest_stat.st_uid @@ -86,7 +106,7 @@ class InstallFilesConfigureExtension(cliapp.Application): os.chmod(dest_path, mode) elif stat.S_ISLNK(mode): - if os.path.lexists(dest_path): + if os.path.lexists(dest_path) and not overwrite: raise cliapp.AppException('Symlink already exists at %s' % dest_path) else: @@ -96,7 +116,7 @@ class InstallFilesConfigureExtension(cliapp.Application): os.lchown(dest_path, uid, gid) elif stat.S_ISREG(mode): - if os.path.lexists(dest_path): + if os.path.lexists(dest_path) and not overwrite: raise cliapp.AppException('File already exists at %s' % dest_path) else: |