From b3048f35ea22c791a03fbf57ebef7c727323dc9d Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Sat, 23 May 2020 14:23:18 -0400 Subject: [PATCH] Add a line splitter. --- .gitignore | 1 + notes/continuify.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 notes/continuify.py diff --git a/.gitignore b/.gitignore index 9435c17..54e6b48 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ nohup.out /webapp/settings-dump.txt /webapp/settingtypes-list.txt err.txt +*.continuified.tmp diff --git a/notes/continuify.py b/notes/continuify.py new file mode 100755 index 0000000..6046f55 --- /dev/null +++ b/notes/continuify.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +""" +Make a copy of any files in the given paths, replacing +spaces with " \", newline, then indent. This is useful for creating +intermediate files for the purpose of running meld or diff on files +with long lines (such as cmake commands pasted into files for +comparison purposes and link.txt files). +""" +import sys +import os + +def continuify(inPath, outPath, continueStr=" \\", indent=" ", + sep=" "): + with open(outPath, 'w') as outs: + with open(inPath) as ins: + rawLine = True + while rawLine: + rawLine = ins.readline() + line = rawLine.rstrip() + parts = line.split(sep) + starter = "" + ender = continueStr + for i in range(len(parts)): + part = parts[i] + if i == len(parts) - 1: + ender = "" + outs.write(indent + part.strip(sep) + ender + "\n") + if i >= 0: + starter = indent + +def main(): + if len(sys.argv) < 2: + print("You must specify file(s).") + exit(1) + for i in range(1, len(sys.argv)): + arg = sys.argv[i] + if not os.path.isfile(arg): + print("ERROR: {} is not a file.".format(arg)) + exit(1) + # parts = os.path.splitext(arg) + # outPath = parts[0] + ".tmp" + parts[1] + outPath = arg + ".continuified.tmp" + continuify(arg, outPath) + print("* wrote \"{}\"".format(outPath)) + pass + +if __name__ == "__main__": + main()