mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-05 16:47:14 -04:00
Former-commit-id: 954de0d020fb579fb1355fd6918aea898038e751 Former-commit-id: 263ea195e60daddeca5c11fef2e2f5943e9a6eff
25 lines
853 B
Python
Executable File
25 lines
853 B
Python
Executable File
#!/usr/bin/env python3
|
|
from os import listdir
|
|
from re import match as rematch
|
|
from sys import argv
|
|
|
|
# read arguments
|
|
arguments = argv[1:]
|
|
|
|
# loop through all Python files in the working directory
|
|
for filename in listdir('working'):
|
|
if filename.endswith('.py'):
|
|
filepath = 'working/' + filename
|
|
# read input file
|
|
with open(filepath, 'r') as file:
|
|
new_file = []
|
|
for line in file:
|
|
# determine whether to remove all or only PORT comments
|
|
if len(arguments) > 0 and arguments[0] == 'ALL':
|
|
if not rematch(r'^\s*#', line):
|
|
new_file.append(line)
|
|
elif not rematch(r'^\s*# PORT', line):
|
|
new_file.append(line)
|
|
# write the updated file contents
|
|
open(filepath, 'w').writelines(new_file)
|