summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2015-03-14 17:30:43 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2015-03-18 16:08:12 +0000
commitc425d9678c39175b9dc65d34b02ee0397a384258 (patch)
tree6966db16a66d11ad3d86629cd2dbb54ae1ba038f
parent2455c32ced2d9316cb937e8a627afd409c2d1517 (diff)
downloadmorph-c425d9678c39175b9dc65d34b02ee0397a384258.tar.gz
Make fstab.configure use write_from_dict
-rwxr-xr-xmorphlib/exts/fstab.configure25
1 files changed, 7 insertions, 18 deletions
diff --git a/morphlib/exts/fstab.configure b/morphlib/exts/fstab.configure
index 3bbc9102..b9154eee 100755
--- a/morphlib/exts/fstab.configure
+++ b/morphlib/exts/fstab.configure
@@ -1,5 +1,6 @@
-#!/usr/bin/python
-# Copyright (C) 2013,2015 Codethink Limited
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright © 2013-2015 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
@@ -19,21 +20,9 @@
import os
import sys
+import morphlib
-def asciibetical(strings):
+envvars = {k: v for (k, v) in os.environ.iteritems() if k.startswith('FSTAB_')}
- def key(s):
- return [ord(c) for c in s]
-
- return sorted(strings, key=key)
-
-
-fstab_filename = os.path.join(sys.argv[1], 'etc', 'fstab')
-
-fstab_vars = asciibetical(x for x in os.environ if x.startswith('FSTAB_'))
-with open(fstab_filename, 'a') as f:
- for var in fstab_vars:
- f.write('%s\n' % os.environ[var])
-
-os.chown(fstab_filename, 0, 0)
-os.chmod(fstab_filename, 0644)
+conf_file = os.path.join(sys.argv[1], 'etc/fstab')
+morphlib.util.write_from_dict(conf_file, envvars)