Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
4 additions
and
4 deletions.
-
+4
−4
patch.py
|
@@ -15,15 +15,15 @@ def patch_files(paths): |
|
|
# not perfect, but perfect enough |
|
|
name_main_re = re.compile('.*if.* .*__name__.*==.*__main__') |
|
|
for path in paths: |
|
|
wrote = False |
|
|
orig = open(path, 'r') |
|
|
with open(path+'.new', 'w') as new: |
|
|
for line in orig: |
|
|
if name_main_re.match(line): |
|
|
new.write(magic) |
|
|
new.write(line) |
|
|
else: |
|
|
new.write(line) |
|
|
else: |
|
|
wrote = True |
|
|
new.write(line) |
|
|
if not wrote: |
|
|
new.write(magic) |
|
|
orig.close() |
|
|
|
|
|
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.