diff options
author | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2015-03-24 14:16:54 +0000 |
---|---|---|
committer | Morph (on behalf of Adam Coldrick) <adam.coldrick@codethink.co.uk> | 2015-03-24 14:16:54 +0000 |
commit | aa047d1b4ea195c1a5a70568a2b75f958f47fa99 (patch) | |
tree | 92ad20301b38f56b0e27506e87d7f5a1dcc6bd0f /morphlib/util.py | |
parent | d1e4fa3639540a51dbb71612bf41a45018f164ea (diff) | |
download | morph-aa047d1b4ea195c1a5a70568a2b75f958f47fa99.tar.gz |
Morph build 271da1e1d62c40748b586dc0345d0f7d
System branch: master
Diffstat (limited to 'morphlib/util.py')
-rw-r--r-- | morphlib/util.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/morphlib/util.py b/morphlib/util.py index 00111ff7..e733af9d 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -131,10 +131,8 @@ def new_artifact_caches(settings): # pragma: no cover if not os.path.exists(artifact_cachedir): os.mkdir(artifact_cachedir) - #lac = morphlib.localartifactcache.LocalArtifactCache( - # fs.osfs.OSFS(artifact_cachedir)) - - lac = morphlib.ostreeartifactcache.OSTreeArtifactCache(artifact_cachedir) + lac = morphlib.localartifactcache.LocalArtifactCache( + fs.osfs.OSFS(artifact_cachedir)) rac_url = get_artifact_cache_server(settings) rac = None @@ -646,3 +644,35 @@ def error_message_for_containerised_commandline( 'Containerisation settings: %s\n' \ 'Error output:\n%s' \ % (argv_string, container_kwargs, err) + + +def write_from_dict(filepath, d, validate=lambda x, y: True): #pragma: no cover + '''Takes a dictionary and appends the contents to a file + + An optional validation callback can be passed to perform validation on + each value in the dictionary. + + e.g. + + def validation_callback(dictionary_key, dictionary_value): + if not dictionary_value.isdigit(): + raise Exception('value contains non-digit character(s)') + + Any callback supplied to this function should raise an exception + if validation fails. + ''' + + # Sort items asciibetically + # the output of the deployment should not depend + # on the locale of the machine running the deployment + items = sorted(d.iteritems(), key=lambda (k, v): [ord(c) for c in v]) + + for (k, v) in items: + validate(k, v) + + with open(filepath, 'a') as f: + for (_, v) in items: + f.write('%s\n' % v) + + os.fchown(f.fileno(), 0, 0) + os.fchmod(f.fileno(), 0644) |