summaryrefslogtreecommitdiff
path: root/morphlib/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/util.py')
-rw-r--r--morphlib/util.py57
1 files changed, 51 insertions, 6 deletions
diff --git a/morphlib/util.py b/morphlib/util.py
index 8566345d..91880988 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -19,6 +19,7 @@ import pipes
import re
import subprocess
import textwrap
+import sys
import fs.osfs
@@ -119,7 +120,7 @@ def get_git_resolve_cache_server(settings): # pragma: no cover
return None
-def new_artifact_caches(settings): # pragma: no cover
+def new_artifact_caches(settings, status_cb=None): # pragma: no cover
'''Create new objects for local and remote artifact caches.
This includes creating the directories on disk, if missing.
@@ -132,10 +133,8 @@ def new_artifact_caches(settings): # pragma: no cover
os.mkdir(artifact_cachedir)
mode = settings['ostree-repo-mode']
- import logging
- logging.debug(mode)
- lac = morphlib.ostreeartifactcache.OSTreeArtifactCache(artifact_cachedir,
- mode=mode)
+ lac = morphlib.ostreeartifactcache.OSTreeArtifactCache(
+ artifact_cachedir, mode=mode, status_cb=status_cb)
rac_url = get_artifact_cache_server(settings)
rac = None
@@ -453,6 +452,13 @@ def has_hardware_fp(): # pragma: no cover
output = subprocess.check_output(['readelf', '-A', '/proc/self/exe'])
return 'Tag_ABI_VFP_args: VFP registers' in output
+def determine_endianness(): # pragma: no cover
+ '''
+ This function returns whether the host is running
+ in big or little endian. This is needed for MIPS.
+ '''
+
+ return sys.byteorder
def get_host_architecture(): # pragma: no cover
'''Get the canonical Morph name for the host's architecture.'''
@@ -470,7 +476,9 @@ def get_host_architecture(): # pragma: no cover
'armv8l': 'armv8l',
'armv8b': 'armv8b',
'aarch64': 'armv8l64',
- 'aarch64b': 'armv8b64',
+ 'aarch64_be': 'armv8b64',
+ 'mips': 'mips32',
+ 'mips64': 'mips64',
'ppc64': 'ppc64'
}
@@ -479,6 +487,11 @@ def get_host_architecture(): # pragma: no cover
if machine == 'armv7l' and has_hardware_fp():
return 'armv7lhf'
+ elif machine in ('mips', 'mips64'):
+ if determine_endianness() == 'big':
+ return table[machine]+'b'
+ else:
+ return table[machine]+'l'
return table[machine]
@@ -647,3 +660,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)