class CriticalException(Exception):
- """Throw critical exception if the exact error is not known but fatal."
+ """Throw critical exception if the exact error is not known but fatal.
@Exception: message"""
pass
return ('', '')
-def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin'):
+def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin', lst_return=False):
"""Given a search path, find file
@filename: name of file to search for
- @search_path: path where searching for the specified filename"""
- file_found = 0
+ @search_path: path where searching for the specified filename
+ @lst_return: return list of matching files instead one file"""
paths = search_path.split(os.pathsep)
current_dir = '' # make pylint happy :)
+ retval = []
def match_file(cwd):
"""Helper function ffor testing if specified file exists in cwd
for path in paths:
current_dir = path
if match_file(current_dir):
- file_found = 1
- break
+ retval.append(os.path.abspath(os.path.join(current_dir, filename)))
+ if not lst_return:
+ break
# pylint: disable-msg=W0612
for current_dir, directories, files in os.walk(path):
if match_file(current_dir):
- file_found = 1
- break
- if file_found:
- return os.path.abspath(os.path.join(current_dir, filename))
+ retval.append(os.path.abspath(os.path.join(current_dir, filename)))
+ if not lst_return:
+ break
+ if lst_return:
+ return retval
+ elif retval:
+ return retval[0]
else:
return None
# grub all-in-one image
handle_addon_copy('allinone.img', addons, iso_mount)
- # bsd imag
+ # bsd image
handle_addon_copy('bsd4grml', addons, iso_mount)
+ # DOS image
handle_addon_copy('balder10.imz', addons, iso_mount)
- # install hdt and pci.ids only when using syslinux (grub doesn't support it)
- if options.syslinux:
- # hdt (hardware detection tool) image
- hdtimg = search_file('hdt.c32', iso_mount)
- if hdtimg:
- exec_rsync(hdtimg, addons + '/hdt.c32')
-
- # pci.ids file
- picids = search_file('pci.ids', iso_mount)
- if picids:
- exec_rsync(picids, addons + '/pci.ids')
+ # syslinux + pci.ids for hdt
+ for expr in '*.c32', 'pci.ids':
+ glob_and_copy(iso_mount + '/boot/addons/' + expr, addons)
# memdisk image
handle_addon_copy('memdisk', addons, iso_mount)
@mountpath: path where the grml ISO is mounted to
@return: name of grml-flavour"""
- version_file = search_file('grml-version', mountpath)
+ version_files = search_file('grml-version', mountpath, lst_return=True)
- if version_file == "":
+ if not version_files:
logging.critical("Error: could not find grml-version file.")
raise
flavours = []
- tmpfile = None
- try:
- tmpfile = open(version_file, 'r')
- for line in tmpfile.readlines():
- flavours.append(get_flavour(line))
- except TypeError, e:
- raise
- except Exception, e:
- logging.critical("Unexpected error: %s", e)
- raise
- finally:
- if tmpfile:
- tmpfile.close()
+ logging.debug("version_files = %s", version_files)
+ for version_file in version_files:
+ tmpfile = None
+ try:
+ tmpfile = open(version_file, 'r')
+ for line in tmpfile.readlines():
+ flavours.append(get_flavour(line))
+ except TypeError, e:
+ raise
+ except Exception, e:
+ logging.critical("Unexpected error: %s", e)
+ raise
+ finally:
+ if tmpfile:
+ tmpfile.close()
return flavours