novoid / appendfilename

Intelligent appending text to file names, considering file extensions and file tags
GNU General Public License v3.0
50 stars 7 forks source link

inconsistency --smart-prepend vs. date2name stamp #13

Closed nbehrnd closed 2 years ago

nbehrnd commented 2 years ago

appendfilename functions differently for files stamped by date2name in either default, or --withtime time stamp.

Manual replication:

touch ping.txt
date2name ping.txt

appendfilename 2022-01-06_ping.txt -t new --smart-prepend

to yield

ERROR    Error while trying to build new filename: <class 'TypeError'>
ERROR    1 error(s) occurred. Please check output above.

An analogue programmatic replication with the test script approach (just submitted, incomplete coverage, under construction) with pytest/pytest-3 for Python3:

pytest-3 test_appendfilename.py -m "smart" -v

File 2021-12-31T18.48.22_test.txt is processed as 2021-12-31T18.48.22 book test.txt and thus successfully removed by the test script. However, test file 2021-12-31.txt is processed to 2021-12-31 book txt loosing the period en face of the file extension. (File test.txt is processed by appendfilename to book test.txt, thus indicating appendfilename works fine on this one.).

nbehrnd commented 2 years ago

En route to extend the test script's scope (there is revised deposit in the pull request), the scene is more complex than anticipated earlier.

pytest-3 test_appendfilename.py -m "smart"
pytest-3 test_appendfilename.py -m "smart" -v  # a more verbose report to the CLI
norwid@carnot2:~/Desktop/test_debian$ appendfilename 2022-01-07_ping.txt --smart-prepend -t echo --verbose
DEBUG    2022-01-07 11:51:56,593 text found: [echo]
DEBUG    2022-01-07 11:51:56,593 extracting list of files ...
DEBUG    2022-01-07 11:51:56,593 len(args) [1]
DEBUG    2022-01-07 11:51:56,593 1 filenames found: [2022-01-07_ping.txt]
DEBUG    2022-01-07 11:51:56,593 iterate over files ...
DEBUG    2022-01-07 11:51:56,594 date/time-stamp found, insert text between date/time-stamp and rest
ERROR    2022-01-07 11:51:56,594 Error while trying to build new filename: <class 'TypeError'>
ERROR    2022-01-07 11:51:56,594 1 error(s) occurred. Please check output above.
norwid@carnot2:~/Desktop/test_debian$ ls
 2022-01-07_ping.txt   2022-01-07T11.48.38_ping.txt  'echo ping.txt'
novoid commented 2 years ago

Hi @nbehrnd, Unfortunately, I can't reproduce the issue at my side and the debug output is not showing me something that helps me here.

I just committed a more verbose debug output for that use-case. For comparison, this is my output:

vk@sting ..lename/manualtests/2022-01-07-issue-13 (git)-[master] % appendfilename 2022-01-07_ping.txt --smart-prepend -t echo --verbose --dryrun
DEBUG    2022-01-07 17:04:35,268 text found: [echo]
DEBUG    2022-01-07 17:04:35,268 extracting list of files ...
DEBUG    2022-01-07 17:04:35,268 len(args) [1]
DEBUG    2022-01-07 17:04:35,268 1 filenames found: [2022-01-07_ping.txt]
DEBUG    2022-01-07 17:04:35,269 iterate over files ...
DEBUG    2022-01-07 17:04:35,269 options.smartprepend is set with ||echo| |2022-01-07_ping|.txt
DEBUG    2022-01-07 17:04:35,269 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>
DEBUG    2022-01-07 17:04:35,269 date/time-stamp found, insert text between date/time-stamp and rest
DEBUG    2022-01-07 17:10:30,808 options.smartprepend is set with ||2022-01-07|ping.txt|
DEBUG    2022-01-07 17:10:30,808 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|
DEBUG    2022-01-07 17:10:30,808 new_filename is now: 2022-01-07 echo ping.txt
INFO     2022-01-07 17:04:35,269  
INFO     2022-01-07 17:04:35,269  renaming "2022-01-07_ping.txt"
INFO     2022-01-07 17:04:35,269       ⤷   "2022-01-07 echo ping.txt"
DEBUG    2022-01-07 17:04:35,269 successfully finished.
Please press <Enter> for finishing...
vk@sting ..lename/manualtests/2022-01-07-issue-13 (git)-[master] %

Can you please re-run your test and post here the output? Thank you very much!

nbehrnd commented 2 years ago

By observation, now the manual conversion works (both on Xubuntu 20.04.2 LTS Fossa, as well as on Debian 12/book worm [testing]). Conceptually, the extended log to the CLI matches yours:

norwid@carnot2:~/Desktop/2022-01-07T18.51.32_appendfilename/appendfilename/appendfilename$ python __init__.py 2022-01-07_ping.txt --smart-prepend -t echo --verbose --dryrun
DEBUG    2022-01-07 19:12:09,498 text found: [echo]
DEBUG    2022-01-07 19:12:09,498 extracting list of files ...
DEBUG    2022-01-07 19:12:09,499 len(args) [1]
DEBUG    2022-01-07 19:12:09,499 1 filenames found: [2022-01-07_ping.txt]
DEBUG    2022-01-07 19:12:09,499 iterate over files ...
DEBUG    2022-01-07 19:12:09,499 options.smartprepend is set with ||echo| |2022-01-07_ping|.txt
DEBUG    2022-01-07 19:12:09,499 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>|<class 'str'>
DEBUG    2022-01-07 19:12:09,499 date/time-stamp found, insert text between date/time-stamp and rest
DEBUG    2022-01-07 19:12:09,499 options.smartprepend is set with ||2022-01-07|ping.txt|
DEBUG    2022-01-07 19:12:09,499 options.smartprepend is set with |<class 'str'>|<class 'str'>|<class 'str'>|
DEBUG    2022-01-07 19:12:09,499 new_filename is now: 2022-01-07 echo ping.txt
INFO     2022-01-07 19:12:09,499  
INFO     2022-01-07 19:12:09,499  renaming "2022-01-07_ping.txt"
INFO     2022-01-07 19:12:09,499       ⤷   "2022-01-07 echo ping.txt"
DEBUG    2022-01-07 19:12:09,500 successfully finished.
Please press <Enter> for finishing...
norwid@carnot2:~/Desktop/2022-01-07T18.51.32_appendfilename/appendfilename/appendfilename$ 

So, this obstacle is out of the way. Thank you!

novoid commented 2 years ago

Weird.

Well, thanks for your effort in any case. Let me know when this reappears. I keep the additional debug code for now.