|
1 | 1 | #!/usr/bin/python3 |
2 | 2 |
|
3 | | -import argparse, os, urllib.request, ast, sys, glob |
| 3 | +import argparse |
| 4 | +import os |
| 5 | +import urllib.request |
| 6 | +import ast |
| 7 | +import sys |
| 8 | +import glob |
4 | 9 | from io import StringIO |
5 | 10 | from pathlib import Path |
6 | 11 | from string import Template |
@@ -100,24 +105,33 @@ def ODM_ERROR(s): |
100 | 105 | # Clean up the output directory - remove all existing .rst files |
101 | 106 | print("Cleaning up %s ..." % argsoutdir) |
102 | 107 | for old_file in glob.glob(os.path.join(argsoutdir, "*.rst")): |
103 | | - os.remove(old_file) |
| 108 | + try: |
| 109 | + os.remove(old_file) |
| 110 | + print("Removed %s" % old_file) |
| 111 | + except (OSError, PermissionError) as e: |
| 112 | + print("Warning: Could not remove %s: %s" % (old_file, e)) |
104 | 113 |
|
105 | 114 | # Clean up old .pot files for deprecated arguments |
106 | 115 | if os.path.isdir(argspotdir): |
107 | 116 | print("Cleaning up %s ..." % argspotdir) |
108 | 117 | for old_pot in glob.glob(os.path.join(argspotdir, "*.pot")): |
109 | | - os.remove(old_pot) |
110 | | - print("Removed %s" % old_pot) |
| 118 | + try: |
| 119 | + os.remove(old_pot) |
| 120 | + print("Removed %s" % old_pot) |
| 121 | + except (OSError, PermissionError) as e: |
| 122 | + print("Warning: Could not remove %s: %s" % (old_pot, e)) |
111 | 123 |
|
112 | 124 | # Clean up old .po files for deprecated arguments in all languages |
113 | 125 | for lang in LANGUAGES: |
114 | 126 | argspodir = os.path.join(localedir, lang, "LC_MESSAGES", "arguments") |
115 | 127 | if os.path.isdir(argspodir): |
116 | 128 | print("Cleaning up %s ..." % argspodir) |
117 | 129 | for old_po in glob.glob(os.path.join(argspodir, "*.po")): |
118 | | - os.remove(old_po) |
119 | | - print("Removed %s" % old_po) |
120 | | - print("Removed %s" % old_file) |
| 130 | + try: |
| 131 | + os.remove(old_po) |
| 132 | + print("Removed %s" % old_po) |
| 133 | + except (OSError, PermissionError) as e: |
| 134 | + print("Warning: Could not remove %s: %s" % (old_po, e)) |
121 | 135 |
|
122 | 136 | with open(argstmplfile) as f: |
123 | 137 | argstmpl = Template(f.read()) |
@@ -178,6 +192,20 @@ def get_opt_choices(opt): |
178 | 192 |
|
179 | 193 | print("Wrote %s" % outfile) |
180 | 194 |
|
| 195 | + # Clean up orphaned files in arguments_edit/ directory |
| 196 | + arguments_edit_dir = os.path.join(argsoutdir + "_edit") |
| 197 | + if os.path.isdir(arguments_edit_dir): |
| 198 | + print("Cleaning up orphaned files in %s ..." % arguments_edit_dir) |
| 199 | + current_opt_names = set(get_opt_name(opt) for opt in keys) |
| 200 | + for edit_file in glob.glob(os.path.join(arguments_edit_dir, "*.rst")): |
| 201 | + edit_opt_name = os.path.splitext(os.path.basename(edit_file))[0] |
| 202 | + if edit_opt_name not in current_opt_names: |
| 203 | + try: |
| 204 | + os.remove(edit_file) |
| 205 | + print("Removed orphaned %s" % edit_file) |
| 206 | + except (OSError, PermissionError) as e: |
| 207 | + print("Warning: Could not remove %s: %s" % (edit_file, e)) |
| 208 | + |
181 | 209 | # Update .tx/config to remove deprecated options |
182 | 210 | if os.path.isfile(txconfigfile): |
183 | 211 | print("Updating %s ..." % txconfigfile) |
|
0 commit comments