Skip to content

Commit

Permalink
Support multiple flavours inside one ISO
Browse files Browse the repository at this point in the history
On grml96 we have multiple grml-version files inside one single ISO,
so we need to find all those grml-version files.

Thanks: Christopher Schramm for the bugreport
Thanks: Ulrich Dangel for the patch
Closes: issue1172
  • Loading branch information
mika committed May 27, 2012
1 parent f377e97 commit 7c076d1
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions grml2usb
Expand Up @@ -121,7 +121,7 @@ if not os.path.isdir(GRML2USB_BASE):


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
Expand Down Expand Up @@ -260,14 +260,15 @@ def get_defaults_file(iso_mount, flavour, name):
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
Expand All @@ -279,15 +280,19 @@ def search_file(filename, search_path='/bin' + os.pathsep + '/usr/bin'):
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

Expand Down Expand Up @@ -1105,26 +1110,28 @@ def identify_grml_flavour(mountpath):
@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

Expand Down

0 comments on commit 7c076d1

Please sign in to comment.