Skip to content

Commit

Permalink
extend patten timestamps by date2name, 2/2
Browse files Browse the repository at this point in the history
Addition of the pattern --compact, --month, and --short.
  • Loading branch information
nbehrnd committed Jan 9, 2022
1 parent c44d707 commit a282a32
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
41 changes: 36 additions & 5 deletions test_appendfilename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+",
Expand All @@ -118,27 +119,57 @@ 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.
time_stamp = old_filename[:10]
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)

Expand Down
41 changes: 36 additions & 5 deletions test_generator.org
Original file line number Diff line number Diff line change
Expand Up @@ -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", [" " , "#", "!", "@", "#", "$", "%", "*", "_", "+",
Expand All @@ -315,27 +316,57 @@ 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.
time_stamp = old_filename[:10]
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)

Expand Down

0 comments on commit a282a32

Please sign in to comment.