LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Pythonistas to the rescue? (Why is this script erroring out?) (https://www.linuxquestions.org/questions/programming-9/pythonistas-to-the-rescue-why-is-this-script-erroring-out-4175625235/)

jamtat 03-08-2018 08:36 PM

Pythonistas to the rescue? (Why is this script erroring out?)
 
I'll start off by saying that I'm no sort of python programmer: it taxes my abilities just to cobble together simple bash scripts. So what I'm trying to do and will ask about in this thread is to use a python script someone else created. I want to get some help here in understanding why I can't get it to complete the task for which it's designed. The script can be found at https://github.com/RaymiiOrg/NoPriv

It's a promising little piece of work I'd really like to use right now. It's supposed to download folders and e-mails from an IMAP server and create a sort of back-up in html. That's very appealing at the moment since I'm going to be closing one of my e-mail accounts and would like to have a back-up of the relatively small (ca. 4k) cache of mails I have there.

The script is a bit dated, the last release apparently having been in 2013, but I do still have python 2.7 on one of my machines so I decided I should be able to run it. And yes, I know I can export my mail to a compressed file using a web interface--but I'd rather have the archive be easily browsable, say, using a text-mode browser.

Anyway, I've downloaded the script and its config file, the latter of which I edited appropriately. The script does actually log into my account, creates local directories and downloads stuff. But it somehow can't complete the final step of creating the email-report-1.html file (my interpretation of the script is that one of those should be in each directory and sub-directory the script creates locally) which, I assume is crucial to making the resulting archive browseable.

Despite the fact that a whole trove of files and folders show up in the target directory--including, importantly, an index.html--once the process finally erros out, opening index.html in a web browser does not allow me to follow any of the links that are supposed to show the contents of downloaded messages within their folders.

The final, apparently show-stopping, error message is as follows:
Code:

. . .
snip
 . . .
Saving message 3373.
Done with folder: INBOX.

Getting messages from server from folder: Misc.
Done with folder: Misc.

Getting messages from server from folder: Priority.
Done with folder: Priority.

Processing folder: [Gmail]/All Mail.
Traceback (most recent call last):
  File "/home/user/bin/nopriv.py", line 885, in <module>
    copy(inc_location, folder + "/inc/")
  File "/home/user/bin/nopriv.py", line 391, in copy
    shutil.copytree(src, dst)
  File "/usr/lib/python2.7/shutil.py", line 185, in copytree
    names = os.listdir(src)
OSError: [Errno 2] No such file or directory: 'inc'

Anyway, I thought the pythonistas on this list should be able to look at the error output and have a quick gander at the script and maybe get an idea of what could be going wrong. Hopefully some simple modification might restore the script's expected behavior. Of course it would be even more wonderful if it could be translated so that it would work in a more recent version of python, but that might be quite a lot of work.

Btw my config file looks something like this:
Code:

[nopriv]
imap_server = imap.gmail.com
imap_user = myuser@gmail.com
imap_password = users_password
imap_folder = NoPriv_All

#optional
ssl = true
incremental_backup = false # tried true here too--no difference

Thanks in advance for any suggestions that will help get this script functioning as needed.

PS Though the script is not all that long I decided it would be best simply to link to it at https://raw.githubusercontent.com/Ra...ster/nopriv.py rather than copy and paste the whole thing into this thread.

Myk267 03-08-2018 09:57 PM

What I *think* is going on is that the script assumes that you're always going to run it from the directory it creates when you clone the repo.

Ex:
Code:

git clone git://github.com/RaymiiOrg/NoPriv.git
cd NoPriv
vim nopriv.ini
python nopriv.py

This way works fine for me.

The problem you're seeing is that the script expects the directory and files 'inc/css/bootstrap.css' from the git repository to be in the same directory as the script is being run from.
If you would like to continue running the script this way, copy that directory to wherever you're running the script from. Possibly like this:
Code:

mkdir email_backup
cd email_backup
cp -R ~/path/to/NoPriv/inc .
python ~/path/to/NoPriv/nopriv.py

Hopefully that fixes the error on your end.

jamtat 03-08-2018 10:37 PM

Yes, Myk267, you seem to have discerned correctly where the problem lies. So I am obviously no more conversant in using git than I am in python. Following your suggestions I was able to get the script to work as advertised. A description along the lines you've explained really needs to be added to the github readme section of this project for dummies like myself. But it looks like nothing much has been done there since 2013 so I suspect the developer may be in the process of abandoning the project and it may be therefore futile to suggest making that sort of addition. Anyway, I need to mark this issue solved and should probably change the title since the central issue is really not a python one.


All times are GMT -5. The time now is 10:29 AM.