extend patten timestamps by date2name, 2/2

Addition of the pattern --compact, --month, and --short.
This commit is contained in:
Norwid Behrnd 2022-01-09 13:14:02 +01:00
parent c44d7070c4
commit a282a32a0e
2 changed files with 72 additions and 10 deletions

View file

@ -98,7 +98,8 @@ def test_pattern_s2(arg1, arg2, arg3, arg4):
@pytest.mark.smart @pytest.mark.smart
@pytest.mark.parametrize("arg1", ["test.txt", "2021-12-31_test.txt", @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", @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf",
"--text book", "--text book_shelf"]) "--text book", "--text book_shelf"])
@pytest.mark.parametrize("arg3", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+", @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.") newfile.write("This is a test file for test_appendfilename.")
test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend") test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend")
# analysis section: # analysis section:
old_filename = str(arg1) 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 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 re.search("^\d{4}-\d{2}-\d{2}_", old_filename):
# if (running date2name in default mode) then .true. # 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] time_stamp_separator = old_filename[10]
file_extension = old_filename.split(".")[-1] file_extension = old_filename.split(".")[-1]
old_filename_no_timestamp = old_filename[11:] 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): elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename):
# if (running date2name --withtime) then .true. # if (running date2name --withtime) then .true.
time_stamp = old_filename[:19] time_stamp = old_filename[:19]
time_stamp_separator = old_filename[19] time_stamp_separator = old_filename[19]
file_extension = old_filename.split(".")[-1] file_extension = old_filename.split(".")[-1]
old_filename_no_timestamp = old_filename[20:] 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_elements = old_filename_no_timestamp.split(".")[:-1]
stem = ".".join(stem_elements) stem = ".".join(stem_elements)

View file

@ -295,7 +295,8 @@ def test_pattern_s2(arg1, arg2, arg3, arg4):
#+begin_src python :tangle test_appendfilename.py #+begin_src python :tangle test_appendfilename.py
@pytest.mark.smart @pytest.mark.smart
@pytest.mark.parametrize("arg1", ["test.txt", "2021-12-31_test.txt", @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", @pytest.mark.parametrize("arg2", ["-t book", "-t book_shelf",
"--text book", "--text book_shelf"]) "--text book", "--text book_shelf"])
@pytest.mark.parametrize("arg3", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+", @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.") newfile.write("This is a test file for test_appendfilename.")
test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend") test = getoutput(f"python3 {PROGRAM} {arg1} {arg2} --separator={arg3} --smart-prepend")
# analysis section: # analysis section:
old_filename = str(arg1) 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 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 re.search("^\d{4}-\d{2}-\d{2}_", old_filename):
# if (running date2name in default mode) then .true. # 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] time_stamp_separator = old_filename[10]
file_extension = old_filename.split(".")[-1] file_extension = old_filename.split(".")[-1]
old_filename_no_timestamp = old_filename[11:] 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): elif re.search('^\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}_', old_filename):
# if (running date2name --withtime) then .true. # if (running date2name --withtime) then .true.
time_stamp = old_filename[:19] time_stamp = old_filename[:19]
time_stamp_separator = old_filename[19] time_stamp_separator = old_filename[19]
file_extension = old_filename.split(".")[-1] file_extension = old_filename.split(".")[-1]
old_filename_no_timestamp = old_filename[20:] 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_elements = old_filename_no_timestamp.split(".")[:-1]
stem = ".".join(stem_elements) stem = ".".join(stem_elements)