server/tools: better documentation for file rename admin script
This commit is contained in:
parent
369ddaf2f8
commit
734e28e014
2 changed files with 7 additions and 9 deletions
|
@ -7,7 +7,7 @@ name: szurubooru
|
||||||
domain: # example: http://example.com
|
domain: # example: http://example.com
|
||||||
# user agent name used to download files from the web on behalf of the api users
|
# user agent name used to download files from the web on behalf of the api users
|
||||||
user_agent:
|
user_agent:
|
||||||
# used to salt the users' password hashes
|
# used to salt the users' password hashes and generate filenames for static content
|
||||||
secret: change
|
secret: change
|
||||||
# required for running the test suite
|
# required for running the test suite
|
||||||
test_database: 'sqlite:///:memory:'
|
test_database: 'sqlite:///:memory:'
|
||||||
|
|
|
@ -61,18 +61,16 @@ def reset_filenames() -> None:
|
||||||
def convert_to_new_filename(old_name: str) -> str:
|
def convert_to_new_filename(old_name: str) -> str:
|
||||||
matches = regex.match(old_name)
|
matches = regex.match(old_name)
|
||||||
if not matches:
|
if not matches:
|
||||||
raise ValueError('Not a valid filename')
|
return None
|
||||||
post_id = int(matches.group(1))
|
post_id = int(matches.group(1))
|
||||||
post_ext = matches.group(2)
|
post_ext = matches.group(2)
|
||||||
return '%d_%s.%s' % \
|
return '%d_%s.%s' % \
|
||||||
(post_id, postfuncs.get_post_security_hash(post_id), post_ext)
|
(post_id, postfuncs.get_post_security_hash(post_id), post_ext)
|
||||||
|
|
||||||
def rename_in_dir(dir: str) -> None:
|
def rename_in_dir(dir: str) -> None:
|
||||||
for file in os.listdir(config.config['data_dir'] + dir):
|
for old_path in os.listdir(config.config['data_dir'] + dir):
|
||||||
try:
|
new_path = convert_to_new_filename(old_path)
|
||||||
old_path = file
|
if not new_path:
|
||||||
new_path = convert_to_new_filename(file)
|
|
||||||
except ValueError:
|
|
||||||
continue
|
continue
|
||||||
if old_path != new_path:
|
if old_path != new_path:
|
||||||
print('%s -> %s' % (dir + old_path, dir + 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, '
|
help='check the audio flags of all posts, '
|
||||||
'noting discrepancies, without modifying posts')
|
'noting discrepancies, without modifying posts')
|
||||||
parser.add_argument('--reset-filenames', action='store_true',
|
parser.add_argument('--reset-filenames', action='store_true',
|
||||||
help='reset the content and thumbnail filenames'
|
help='reset and rename the content and thumbnail '
|
||||||
'caused by a lost/changed secret key')
|
'filenames in case of a lost/changed secret key')
|
||||||
command = parser_top.parse_args()
|
command = parser_top.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue