-def update_grml_versions(iso_mount, target):
- """Update the grml version file on a cd
- Returns true if version was updated successfully,
- False if grml-version does not exist yet on the mountpoint
-
- @iso_mount: string of the iso mount point
- @target: path of the target mount point
- """
- grml_target = target + "/grml/"
- target_grml_version_file = search_file("grml-version", grml_target)
- if target_grml_version_file:
- iso_grml_version_file = search_file("grml-version", iso_mount)
- if not iso_grml_version_file:
- logging.warn(
- "Warning: %s could not be found - can not install it",
- iso_grml_version_file,
- )
- return False
- try:
- # read the flavours from the iso image
- iso_versions = {}
- iso_file = open(iso_grml_version_file, "r")
- for line in iso_file:
- iso_versions[get_flavour(line)] = line.strip()
-
- # update the existing flavours on the target
- for line in fileinput.input([target_grml_version_file], inplace=1):
- flavour = get_flavour(line)
- if flavour in list(iso_versions.keys()):
- print(iso_versions.pop(flavour))
- else:
- print(line.strip())
- fileinput.close()
-
- target_file = open(target_grml_version_file, "a")
- # add the new flavours from the current iso
- for flavour in iso_versions:
- target_file.write("%s\n" % iso_versions[flavour])
- except IOError:
- logging.warn("Warning: Could not write file")
- finally:
- iso_file.close()
- target_file.close()
- return True
- else:
- return False
-
-