[Grml-devel] [PATCH 2/2] properly update grml-versions when updating a grml flavour

Christian Hofstaedtler ch at zeha.at
Thu Jul 1 20:58:04 CEST 2010


Previously, grml-versions would have been only updated when adding a
new grml flavour to the existing target media. This change ensures
that it will also be updated when an existing grml flavour is being
updated.
---
 grml2usb |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/grml2usb b/grml2usb
index dbf1ba9..c1552a9 100755
--- a/grml2usb
+++ b/grml2usb
@@ -1123,18 +1123,20 @@ def update_grml_versions(iso_mount, target):
             logging.warn("Warning: %s could not be found - can not install it", iso_grml_version_file)
             return False
         try:
-            target_file = open(target_grml_version_file, 'a+')
-            target_flavours = [ get_flavour(l) for l in target_file.readlines() ]
-
+            iso_versions = {}
             iso_file = open(iso_grml_version_file, 'r')
-            iso_lines = iso_file.readlines()
-            for line in iso_lines:
-                if not get_flavour(line) in target_flavours:
-                    target_file.write(line)
+            for line in iso_file:
+                iso_versions[get_flavour(line)] = line.strip()
+
+            for line in fileinput.input([target_grml_version_file], inplace=1):
+                flavour = get_flavour(line)
+                if flavour in iso_versions.keys():
+                    print iso_versions[flavour]
+                else:
+                    print line.strip()
         except IOError:
             logging.warn("Warning: Could not write file")
         finally:
-            target_file.close()
             iso_file.close()
         return True
     else:
-- 
1.7.1



More information about the Grml-devel mailing list