From 72f4bcca7deefb5f288e330372dbe57ee84dfbdf Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 14 Apr 2023 18:38:36 -0400 Subject: [PATCH] port-jobs: COMMENTS.py now acts on all Python files in the lib directory Former-commit-id: 7cae54dec389cc649f2165cb723353ad72292992 Former-commit-id: 2ab248feeeed74b5b2ffab0d5cf8ee79955cc585 --- port-jobs/CLIPBOARD.py | 10 +++++----- port-jobs/COMMENTS.py | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/port-jobs/CLIPBOARD.py b/port-jobs/CLIPBOARD.py index e559662..bf033a3 100755 --- a/port-jobs/CLIPBOARD.py +++ b/port-jobs/CLIPBOARD.py @@ -36,15 +36,15 @@ else: s_exit() # define PORT target -string1 = "# PORT START CLIPBOARD" -string2 = "# PORT END CLIPBOARD" +string1 = '# PORT START CLIPBOARD' +string2 = '# PORT END CLIPBOARD' # read input file -text = open("working/sshyp.py", "r").read() +text = open('working/sshyp.py', 'r').read() # find and replace the defined PORT target regex = re.compile(f"{string1}.*?{string2}", re.DOTALL) new_text = re.sub(regex, replacement, text) -# write the updated text -open("working/sshyp.py", "w").write(new_text) +# write updated text +open('working/sshyp.py', 'w').write(new_text) diff --git a/port-jobs/COMMENTS.py b/port-jobs/COMMENTS.py index 36c57a5..a5969bd 100755 --- a/port-jobs/COMMENTS.py +++ b/port-jobs/COMMENTS.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +from os import listdir import re from sys import argv @@ -11,11 +12,12 @@ if len(arguments) > 0 and arguments[0] == 'ALL': else: regex = re.compile(r'^\s*# PORT.*$\n?', re.MULTILINE) -# read input file -text = open("working/sshyp.py", "r").read() - -# run the defined regular expression -new_text = re.sub(regex, '', text) - -# write the updated text -open("working/sshyp.py", "w").write(new_text) +for filename in listdir('working'): + if filename.endswith('.py'): + filepath = 'working/' + filename + # read input file + text = open(filepath, 'r').read() + # run the defined regular expression + new_text = re.sub(regex, '', text) + # write updated text + open(filepath, 'w').write(new_text)