mirror of
https://github.com/novoid/appendfilename.git
synced 2026-02-16 12:54:15 +00:00
extend patten timestamps by date2name, 2/2
Addition of the pattern --compact, --month, and --short.
This commit is contained in:
parent
c44d7070c4
commit
a282a32a0e
2 changed files with 72 additions and 10 deletions
|
|
@ -98,7 +98,8 @@ def test_pattern_s2(arg1, arg2, arg3, arg4):
|
|||
|
||||
@pytest.mark.smart
|
||||
@pytest.mark.parametrize("arg1", ["test.txt", "2021-12-31_test.txt",
|
||||
"2021-12-31T18.48.22_test.txt"])
|
||||
"2021-12-31T18.48.22_test.txt", "20211231_test.txt",
|
||||
"2021-12_test.txt", "211231_test.txt"])
|
||||
@pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf",
|
||||
"--text book", "--text book_shelf"])
|
||||
@pytest.mark.parametrize("arg3", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+",
|
||||
|
|
@ -118,12 +119,21 @@ def test_pattern_s3_02(arg1, arg2, arg3):
|
|||
newfile.write("This is a test file for test_appendfilename.")
|
||||
|
||||
test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend")
|
||||
|
||||
|
||||
# analysis section:
|
||||
old_filename = str(arg1)
|
||||
|
||||
# test pattern issued by date2name vs. other pattern
|
||||
# default (YYYY-MM-DD)
|
||||
# --withtime (YYYY-MM-DDTHH.MM.SS)
|
||||
# --compact (YYYYMMDD)
|
||||
# --month (YYYY-MM)
|
||||
# --short (YYMMDD)
|
||||
if (re.search("^\d{4}-[012]\d-[0-3]\d_", old_filename) or
|
||||
re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename)):
|
||||
re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename) or
|
||||
re.search("^\d{4}[012]\d[0-3]\d_", old_filename) or
|
||||
re.search("^\d{4}-[012]\d_", old_filename) or
|
||||
re.search("^\d{2}[012]\d[0-3]\d_", old_filename)):
|
||||
|
||||
if re.search("^\d{4}-\d{2}-\d{2}_", old_filename):
|
||||
# if (running date2name in default mode) then .true.
|
||||
|
|
@ -131,14 +141,35 @@ def test_pattern_s3_02(arg1, arg2, arg3):
|
|||
time_stamp_separator = old_filename[10]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[11:]
|
||||
|
||||
|
||||
elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename):
|
||||
# if (running date2name --withtime) then .true.
|
||||
time_stamp = old_filename[:19]
|
||||
time_stamp_separator = old_filename[19]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[20:]
|
||||
|
||||
|
||||
elif re.search("^\d{4}\d{2}\d{2}_", old_filename):
|
||||
# if (running date2name --compact) then .true.
|
||||
time_stamp = old_filename[:8]
|
||||
time_stamp_separator = old_filename[8]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[9:]
|
||||
|
||||
elif re.search("^\d{4}-\d{2}_", old_filename):
|
||||
# if (running date2name --month) then .true.
|
||||
time_stamp = old_filename[:7]
|
||||
time_stamp_separator = old_filename[7]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[8:]
|
||||
|
||||
elif re.search("^\d{4}\d{2}\d{2}_", old_filename):
|
||||
# if (running date2name --short) then .true.
|
||||
time_stamp = old_filename[:6]
|
||||
time_stamp_separator = old_filename[6]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[7:]
|
||||
|
||||
stem_elements = old_filename_no_timestamp.split(".")[:-1]
|
||||
stem = ".".join(stem_elements)
|
||||
|
||||
|
|
|
|||
|
|
@ -295,7 +295,8 @@ def test_pattern_s2(arg1, arg2, arg3, arg4):
|
|||
#+begin_src python :tangle test_appendfilename.py
|
||||
@pytest.mark.smart
|
||||
@pytest.mark.parametrize("arg1", ["test.txt", "2021-12-31_test.txt",
|
||||
"2021-12-31T18.48.22_test.txt"])
|
||||
"2021-12-31T18.48.22_test.txt", "20211231_test.txt",
|
||||
"2021-12_test.txt", "211231_test.txt"])
|
||||
@pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf",
|
||||
"--text book", "--text book_shelf"])
|
||||
@pytest.mark.parametrize("arg3", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+",
|
||||
|
|
@ -315,12 +316,21 @@ def test_pattern_s3_02(arg1, arg2, arg3):
|
|||
newfile.write("This is a test file for test_appendfilename.")
|
||||
|
||||
test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend")
|
||||
|
||||
|
||||
# analysis section:
|
||||
old_filename = str(arg1)
|
||||
|
||||
# test pattern issued by date2name vs. other pattern
|
||||
# default (YYYY-MM-DD)
|
||||
# --withtime (YYYY-MM-DDTHH.MM.SS)
|
||||
# --compact (YYYYMMDD)
|
||||
# --month (YYYY-MM)
|
||||
# --short (YYMMDD)
|
||||
if (re.search("^\d{4}-[012]\d-[0-3]\d_", old_filename) or
|
||||
re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename)):
|
||||
re.search('^\d{4}-[012]\d-[0-3]\dT[012]\d\.[0-5]\d\.[0-5]\d_', old_filename) or
|
||||
re.search("^\d{4}[012]\d[0-3]\d_", old_filename) or
|
||||
re.search("^\d{4}-[012]\d_", old_filename) or
|
||||
re.search("^\d{2}[012]\d[0-3]\d_", old_filename)):
|
||||
|
||||
if re.search("^\d{4}-\d{2}-\d{2}_", old_filename):
|
||||
# if (running date2name in default mode) then .true.
|
||||
|
|
@ -328,14 +338,35 @@ def test_pattern_s3_02(arg1, arg2, arg3):
|
|||
time_stamp_separator = old_filename[10]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[11:]
|
||||
|
||||
|
||||
elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename):
|
||||
# if (running date2name --withtime) then .true.
|
||||
time_stamp = old_filename[:19]
|
||||
time_stamp_separator = old_filename[19]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[20:]
|
||||
|
||||
|
||||
elif re.search("^\d{4}\d{2}\d{2}_", old_filename):
|
||||
# if (running date2name --compact) then .true.
|
||||
time_stamp = old_filename[:8]
|
||||
time_stamp_separator = old_filename[8]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[9:]
|
||||
|
||||
elif re.search("^\d{4}-\d{2}_", old_filename):
|
||||
# if (running date2name --month) then .true.
|
||||
time_stamp = old_filename[:7]
|
||||
time_stamp_separator = old_filename[7]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[8:]
|
||||
|
||||
elif re.search("^\d{4}\d{2}\d{2}_", old_filename):
|
||||
# if (running date2name --short) then .true.
|
||||
time_stamp = old_filename[:6]
|
||||
time_stamp_separator = old_filename[6]
|
||||
file_extension = old_filename.split(".")[-1]
|
||||
old_filename_no_timestamp = old_filename[7:]
|
||||
|
||||
stem_elements = old_filename_no_timestamp.split(".")[:-1]
|
||||
stem = ".".join(stem_elements)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue