Dapbler / cbr2cbz

Python script that converts compressed CBR and CBZ comic archives to stored CBZ. Many options.
GNU General Public License v3.0
26 stars 5 forks source link

global name 'FileExistsError' is not defined #17

Open wisewtf opened 3 years ago

wisewtf commented 3 years ago

I've been testing out the script, but I haven't been able to get past this:

[wise:plutus] 0
~/utilities/cbr2cbz: ./cbr2cbz.py /home/wise/source/work/ /opt/library/comics/Taskmaster/
Creating /tmp/cbr2cbztemp-u1000/p998406
Traceback (most recent call last):
  File "./cbr2cbz.py", line 803, in <module>
    main()
  File "./cbr2cbz.py", line 755, in main
    ,whatif=options.whatif
  File "./cbr2cbz.py", line 369, in cbr2cbz
    except FileExistsError:
NameError: global name 'FileExistsError' is not defined

Source directory contains one .cbr file called "'Taskmaster 005 (2021) (John_Williams).cbr" and destination folder exists and has correct permissions.

As far as I am aware a /tmp/cbr2cbztemp-u1000/p1002996/Taskmaster 005 (2021) (John_Williams) folder is correctly created containing all extracted pages from the .cbr but then it fails.

I am not sure what exactly is failing on 'FileExists', I have tried removing everything and starting from scratch even going as far as not having a destination folder created, thinking the script would do it itself. <- It does create it on its own but it still won't work.

I haven't been able to get a successful run on the script ever so I can't test for proper funcionality at all. Is it a problem with naming scheme of the archive contents? Even renaming the .cbr to a single clean string doesn't work.

mleduque commented 3 years ago

You're probably running it with python2. On debian/ubuntu (and anything like that), the "python" command will stay python2 by default (even whenit is removed, that's happening now in debian I think). i don't know what other distributions do. This script is python3.

You either need to change the /usr/bin/python link or modify cbr2cbz.py to #!/usr/bin/python3

PiDockMedia commented 3 years ago

I was also confused for a short time on this.

You could easily "fix" this by replacing the #!/usr/bin/python with #!/usr/bin/env python3 at the top of the script. This allows it to find whichever your current default python3 is which is really important when you run in virtual python environments.

This method also follows the official recommendation:

https://www.python.org/dev/peps/pep-0394/#recommendation

I don't mind pulling this and suggesting the change.

Dapbler commented 3 years ago

Thanks for the pointer. I've changed the shebang to #!/usr/bin/env python3 and pushed to a new test branch - should add some tempdir autodetection/safety improvements to it also.

Dapbler commented 3 years ago

Promoted to the default branch.