nicolasshu / zotero2papis

4 stars 1 forks source link

FileNotFoundError: [Errno 2] No such file or directory: 'storage:XXXXXXX.pdf' #1

Open tobiasrenkin opened 1 year ago

tobiasrenkin commented 1 year ago

Hi. The script doesn't work for me - the "path" variable seems to not be defined properly, see output below. The file in question exists at /home/XXX/.zotero_data/storage/ADENEUW7/Blundell and Stoker - 2005 - Heterogeneity and Aggregation.pdf

I am wondering if I am doing something wrong? Not only does "path" contain a "storeage:" stub that should not be there, it also doesn't contain the full path but only the file name.

> zotero2papis --zotdir /home/XXX/.zotero_data -o /home/XXX/Papers --verbose


 (1, 'journalArticle', 'IYZZDBTY', '2019-08-08 09:37:23', '2022-04-20 12:51:29', '2022-04-20 12:51:29')
Heterogeneity and Aggregation
    KEY   ADENEUW7
    PATH  storage:Blundell and Stoker - 2005 - Heterogeneity and Aggregation.pdf
    PARID 1
    DIR:  
      original: /home/XXX/.zotero_data/storage/ADENEUW7/storage:Blundell and Stoker - 2005 - Heterogeneity and Aggregation.pdf
      dest:     /home/XXX/Papers/storage:Blundell and Stoker - 2005 - Heterogeneity and Aggregation.pdf
storage:Blundell and Stoker - 2005 - Heterogeneity and Aggregation.pdf

Traceback (most recent call last):
[...]
FileNotFoundError: [Errno 2] No such file or directory: 'storage:Blundell and Stoker - 2005 - Heterogeneity and Aggregation.pdf'
mcepl commented 1 year ago

Exactly the same:

stitny~/D/c/bibliography$ zotero2papis -z ~/.local/share/zotero/ -o ~/Dokumenty/clanky/bib
liography/
storage:Baker - Authentic Christianity and its Distortions Commun.pdf
Traceback (most recent call last):
  File "/home/matej/.bin/zotero2papis", line 33, in <module>
    sys.exit(load_entry_point('zotero2papis', 'console_scripts', 'zotero2papis')())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 386, in run
    client.run()
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 360, in run
    files, target_dir = self.getFiles(conn, itemID, itemKey)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 236, in getFiles
    shutil.copyfile(path, dest)
  File "/usr/lib64/python3.10/shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'storage:Baker - Authentic Christianity and its Distortions Commun.pdf'
stitny~/D/c/bibliography$ 
nicolasshu commented 1 year ago

Ah, sorry. This might be because I wrote it in a way that I use Zotfile to store the files directly at the directory where papis will be, and so that in the future I don't have to go hunting down where every file is. Take a look at this to see how I did it

http://nicolasshu.com/zotero_and_papis.html

and look through the first for loop in the zotero2papis.py to see how it works. It could have been that it was already moved and it wasn't accounted for too. You're welcome to open a pull request. Otherwise, I'll get to it later

mcepl commented 1 year ago

I am sure I don’t understand. See this:

stitny~/r/t/z/zotero2papis (main)$ ls ~/.local/share/**/*Authentic*.pdf 2>/dev/null
/home/matej/.local/share/zotero/storage/KAW59S9R/Baker - Authentic Christianity and its Distortions Commun.pdf
stitny~/r/t/z/zotero2papis (main)$ python3 -mzotero2papis -v -z ~/.local/share/zotero/ -o 
~/Dokumenty/clanky/bibliography/
(1, 'webpage', 'AZRCRCJM', '2015-04-02 00:25:58', '2015-04-06 09:16:39', '2021-06-16 21:14:35')
Authentic Christianity and its Distortions: Communicating Jacques Ellul’s Thought Using Paul Hiebert’s Bounded and Centered Set Categories

    KEY   KAW59S9R
    PATH  storage:Baker - Authentic Christianity and its Distortions Commun.pdf
    PARID 1
    DIR:  
      original: /home/matej/.local/share/zotero/storage/KAW59S9R/storage:Baker - Authentic Christianity and its Distortions Commun.pdf
      dest:     /home/matej/Dokumenty/clanky/bibliography/storage:Baker - Authentic Christianity and its Distortions Commun.pdf
storage:Baker - Authentic Christianity and its Distortions Commun.pdf
Traceback (most recent call last):
  File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 389, in <module>
    run()
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 386, in run
    client.run()
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 360, in run
    files, target_dir = self.getFiles(conn, itemID, itemKey)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 236, in getFiles
    shutil.copyfile(path, dest)
  File "/usr/lib64/python3.10/shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'storage:Baker - Authentic Christianity and its Distortions Commun.pdf'
stitny~/r/t/z/zotero2papis (main)$ 

Do you have any suggestions how to make zotero2papis more universal and less dependent on your specific configuration?

nicolasshu commented 1 year ago

Sorry, guys. I think I took care of it now. Yeah, I had written it more so for my configuration with my Zotfile configuration. What I didn't account for was

  1. People not using Zotfile and storing their PDFs collectively somewhere
  2. That whenever you use the Zotero connector from the webpage (e.g. https://arxiv.org/abs/1409.0473#) and from the PDF (e.g https://arxiv.org/pdf/1409.0473.pdf) would log differently on the SQLite database.

So when you use the Zotero Connector straight from the PDF, it gives you the issues you guys were all facing, since the PDF is stored in whichever way Zotero decides to save its file (which, still to today, I don't fully understand. E.g. when you add other attachments, it gets added to a different itemKey directory).

But I think it should be working now. For my own personal preference (since I didn't want to have to deal with file tree patterns from a Zotfile config), I decided to have it copy to

$papis_dir/{YYYY}_{TITLE}.pdf

where $papis_dir is the directory you pass into the -o flag.

So I tried this a few times from different ways, and I think you should be able to use a Zotfile configuration, and you should be able to also use this without a Zotfile altogether. (I think)

The only problem if you don't use Zotfile is that you'll have two copies of the same PDF on your system. I.e. if you edit/annotate the PDF on the papis directory, you will not see it on Zotero, or if you edit the one on Zotero, you will not see it on papis.

mcepl commented 1 year ago

Still not right (master of this repository):

stitny~/D/clanky$ ls ~/.local/share/zotero
locate  papers  storage  translators    zotero.sqlite.bak    zotero.sqlite.111.bak
logs    pipes   styles   zotero.sqlite  zotero.sqlite.1.bak
stitny~/D/clanky$ rm -rf bibliography/
stitny~/D/clanky$ mkdir -p bibliography/files
stitny~/D/clanky$ ls ~/.local/share/zotero
locate  papers  storage  translators    zotero.sqlite.bak    zotero.sqlite.111.bak
logs    pipes   styles   zotero.sqlite  zotero.sqlite.1.bak
stitny~/D/clanky$ zotero2papis -z ~/.local/share/zotero/ -o ~/Dokumenty/clanky/bibliograph
y/
Declaration "Dominus Iesus" On the Unicity and Salvific Universality of Jesus Christ and the Church
Traceback (most recent call last):
  File "/home/matej/.bin/zotero2papis", line 33, in <module>
    sys.exit(load_entry_point('zotero2papis', 'console_scripts', 'zotero2papis')())
  File "/home/matej/.local/lib/python3.10/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/matej/.local/lib/python3.10/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/matej/.local/lib/python3.10/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/matej/.local/lib/python3.10/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 529, in run
    client.run()
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 493, in run
    files, target_dir, deleted_entry = self.getFiles(conn, itemID, itemKey)
  File "/home/matej/archiv/knihovna/repos/tmp/zotero2papis/zotero2papis/zotero2papis.py", line 340, in getFiles
    print(f"    Now parsing other storage files for: [{os.path.basename(path)}]")
UnboundLocalError: local variable 'path' referenced before assignment
stitny~/D/clanky$ cat ~/authentic_christianity.bib/dominus_iesus/dominus_iesus.bib

@misc{ratzinger_declaration_2000,
    title = {Declaration "{Dominus} {Iesus}" {On} the {Unicity} and {Salvific} {Universality} of {Jesus} {Christ} and the {Church}},
    shorttitle = {Domnus {Jesus}},
    url = {http://www.vatican.va/roman_curia/congregations/cfaith/documents/rc_con_cfaith_doc_20000806_dominus-iesus_en.html},
    language = {English},
    urldate = {2015-04-06},
    author = {Ratzinger, Joseph},
    month = aug,
    year = {2000},
    note = {00000},
    file = {Dominus Iesus:files/263/rc_con_cfaith_doc_20000806_dominus-iesus_en.html:text/html},
}
stitny~/D/clanky$ ls ~/.local/share/zotero/**/*ominus*
/home/matej/.local/share/zotero/storage/DNTRT475/rc_con_cfaith_doc_20000806_dominus-iesus_en.html
stitny~/D/clanky$ 
nicolasshu commented 1 year ago

Hey! Do your references not have attachments to them? I won't have time for the next couple of days to debug this, but could you try to just comment out that line or just remove the reference to the variable path? By just looking at it, it looks like the only way that error could occur is if you are not pulling any publications along with it to your filesystem.

mcepl commented 1 year ago

I don’t understand what you mean: I see pretty simple record with the attached snapshot in Zotero:

screenshot-2023-04-21_14-04-1682079755