diff options
author | James E.H. Turner <jturner@gemini.edu> | 2016-10-19 15:29:54 -0400 |
---|---|---|
committer | James E.H. Turner <jturner@gemini.edu> | 2016-10-19 15:29:54 -0400 |
commit | 8580f023028de7ecd63439a288effd9c6d5fa6d0 (patch) | |
tree | a86d8d195a1b9abb9a6f5fb699c9a21a6159560a /scripts/ac_update_extern_pkg | |
parent | 07f295cdeafea52658f09dc0cc11f954d03c17df (diff) | |
download | astroconda-iraf-helpers-8580f023028de7ecd63439a288effd9c6d5fa6d0.tar.gz |
Avoid blank lines at the start of the file when adding/removing the 1st entry.
Diffstat (limited to 'scripts/ac_update_extern_pkg')
-rw-r--r-- | scripts/ac_update_extern_pkg | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/scripts/ac_update_extern_pkg b/scripts/ac_update_extern_pkg index 90d1c65..b44155d 100644 --- a/scripts/ac_update_extern_pkg +++ b/scripts/ac_update_extern_pkg @@ -121,8 +121,9 @@ match = re.search(keep_re, buffer, flags=re.M) if match: buffer = buffer[:match.start()] -# Make sure that what goes before the "keep" ends with a new line: -buffer = re.compile('\n?\Z', flags=re.M).sub('\n', buffer) +# Make sure what goes before the "keep" ends with a new line (unless empty): +sep = '\n' if buffer.strip() else '' +buffer = re.compile('\n?\Z', flags=re.M).sub(sep, buffer) # Find the last entry in extern.pkg (if any) that matches the template: match = None @@ -150,8 +151,12 @@ if match: # template-based definition but then continue as if there had been no # match, so a new definition will get placed at the end of the file below: if later_match or args_remove: - buffer = '%s\n\n%s' % (buffer[:match.start()].rstrip(), - buffer[match.end():].lstrip()) + + # Replace the entry by 2 separator lines (unless it's the first one): + buf_before = buffer[:match.start()].rstrip() + buf_after = buffer[match.end():].lstrip() + buffer = buf_before + ('\n\n' if buf_before else '') + buf_after + del buf_before, buf_after match = None if not args_remove: |