Report non-existent file references in config files in more concise

manner.
Fix path finding regular expression to properly catch comma-delimited
paths.
pull/305/head
Shinji Suzuki 6 years ago
parent 6d0e922568
commit d659f83925

@ -29,7 +29,7 @@ def dont_require_tweaking(fname, content, match_start, match_end):
(4 <= match_start and # Don't write an arg of 'init=' param.
content[match_start-4:match_start+1] == 'init=')
def fix_abspath_r(pattern, string, install_dir, iso_name, config_fname):
def fix_abspath_r(pattern, string, install_dir, iso_name, kept_paths):
"""Return a list of tuples consisting of 'string' with replaced path and a bool representing if /boot/ was prepended in the expression."""
m = pattern.search(string)
if not m:
@ -41,7 +41,7 @@ def fix_abspath_r(pattern, string, install_dir, iso_name, config_fname):
return [(string[:start] + prologue + '/' + specified_path,
'/%s is kept as is.' % specified_path)] \
+ fix_abspath_r(pattern, string[end:], install_dir, iso_name,
config_fname)
kept_paths)
# See if a path that has 'boot/' prepended is a better choice.
# E.g. Debian debian-live-9.4.0-amd64-cinnamon has a loopback.cfg
@ -70,21 +70,29 @@ def fix_abspath_r(pattern, string, install_dir, iso_name, config_fname):
"Removed '.efi' from %s" % specified_path)
else:
# Reluctantly accept what is specified.
log("Keeping path [%s] in '%s' though it does not exist." % (
specified_path, config_fname))
if specified_path not in kept_paths:
kept_paths.append(specified_path)
selected_path, fixed = specified_path, False
out = string[:start] + prologue + '/multibootusb/' + iso_name + '/' \
+ selected_path.replace('\\', '/')
return [(out, fixed)] \
+ fix_abspath_r(pattern, string[end:], install_dir, iso_name,
config_fname)
kept_paths)
def fix_abspath(string, install_dir, iso_name, config_fname):
"""Rewrite what appear to be a path within 'string'. If a file does not exist with specified path, one with '/boot' prepended is tried."""
path_expression = re.compile(r'([ \t=])/(.*?)((?=[\s*])|$)')
path_expression = re.compile(r'([ \t=,])/(.*?)((?=[,|\s*])|$)')
kept_paths = []
chunks = fix_abspath_r(
path_expression, string, install_dir, iso_name, config_fname)
path_expression, string, install_dir, iso_name, kept_paths)
if len(kept_paths)==1:
log("'%s' is kept as is though it does not exist." % kept_paths[0])
elif 2<=len(kept_paths):
log("Following paths are used as they are though they don't exist.")
for kept_path in kept_paths:
log(' ' + kept_path)
tweaked_chunks = [c for c in chunks if c[1]]
if len(tweaked_chunks) == 0:
# Fallback to the legacy implementation so that

Loading…
Cancel
Save