diff options
| author | Shyam Sunder <sgsunder1@gmail.com> | 2019-09-04 17:58:26 -0400 |
|---|---|---|
| committer | Shyam Sunder <sgsunder1@gmail.com> | 2019-09-04 17:58:26 -0400 |
| commit | 734e28e014ee6b1ac63108043e8487efae81e584 (patch) | |
| tree | 49fc7ba2eaedc0e54c4faab3182dbb102a543352 /server/szuru-admin | |
| parent | 369ddaf2f86f1a596716012d295910f38f859bcc (diff) | |
server/tools: better documentation for file rename admin script
Diffstat (limited to 'server/szuru-admin')
| -rwxr-xr-x | server/szuru-admin | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/server/szuru-admin b/server/szuru-admin index 429dc83..6433fde 100755 --- a/server/szuru-admin +++ b/server/szuru-admin @@ -61,18 +61,16 @@ def reset_filenames() -> None: def convert_to_new_filename(old_name: str) -> str: matches = regex.match(old_name) if not matches: - raise ValueError('Not a valid filename') + return None post_id = int(matches.group(1)) post_ext = matches.group(2) return '%d_%s.%s' % \ (post_id, postfuncs.get_post_security_hash(post_id), post_ext) def rename_in_dir(dir: str) -> None: - for file in os.listdir(config.config['data_dir'] + dir): - try: - old_path = file - new_path = convert_to_new_filename(file) - except ValueError: + for old_path in os.listdir(config.config['data_dir'] + dir): + new_path = convert_to_new_filename(old_path) + if not new_path: continue if old_path != new_path: print('%s -> %s' % (dir + old_path, dir + new_path)) @@ -95,8 +93,8 @@ def main() -> None: help='check the audio flags of all posts, ' 'noting discrepancies, without modifying posts') parser.add_argument('--reset-filenames', action='store_true', - help='reset the content and thumbnail filenames' - 'caused by a lost/changed secret key') + help='reset and rename the content and thumbnail ' + 'filenames in case of a lost/changed secret key') command = parser_top.parse_args() try: |