ronen25/nautilus-copypath

NameError: global name 'items' is not defined

vredesbyyrd opened this issue · 8 comments

Thanks for the extension. Though I cant seem to get it working. This is the error I am seeing. Thoughts?

Thanks for your time.

Traceback (most recent call last):
  File "/home/clu/.local/share/nautilus-python/extensions/nautilus-copypath.py", line 49, in get_background_items
    return self.get_file_items(window, files)
  File "/home/clu/.local/share/nautilus-python/extensions/nautilus-copypath.py", line 44, in get_file_items
    items.append(item_copy_path)
NameError: global name 'items' is not defined

Python 3.7.0-4
Python-gobject 3.30.1-3
Python2-nautilus 1.2.2-2
Nautilus 3.30.0-1

@vredesbyyrd Hi, It appears to be a redundant variable that I accidentally left in the code.
I've committed a fix for this.

Can you try it now?
Thanks for the issue report!

Thanks for the fix.

So now the extension will load, although I get a different error when attempting to copy a file / directory. Hmm

Traceback (most recent call last):
  File "/home/clu/.local/share/nautilus-python/extensions/nautilus-copypath.py", line 25, in __copy_path
    locations = [fileinfo.get_uri().replace('file://', '') for fileinfo in files]
TypeError: 'NautilusVFSFile' object is not iterable

The main reason I am trying to use your extension is because a change in nautilus 3.30 broke the behavior of copy IMO, and there has not been a fix committed yet. I often find myself copy / pasting paths into the terminal & elsewhere so the mentioned change was a wrench in my workflow. I tried to make a python-nautilus extension myself that incorporated a xclip bash statement, but I do not know python so was basically throwing code at the wall and hoping something would stick.

I was very happy to find your extension, one written by someone who knows what they are doing. BTW, the 'copy file path' option added to the pathbar menu is a nice touch.

Nautilus copy bug report:

https://gitlab.gnome.org/GNOME/nautilus/issues/634

I found the issue - I've set up an Arch Linux environment with GNOME 3.30, and it appears that on it (or on nautilus-python 1.2.2) the get_background_items method returns a single file instead of a list.
I see it's the same on my GNOME 3.28, so I guess I've just misunderstood the API. Still not sure
why it only breaks on 3.30 though...

I'll revise the extension (the Windows bit also needs this rewrite) and post a fix this Thursday (Oct. 11th) after my discrete maths test.

Thanks for getting back, I am on gnome 3.30 & Arch as well.

I see it's the same on my GNOME 3.28, so I guess I've just misunderstood the API. Still not sure
why it only breaks on 3.30 though...

I have come across a handful of seemingly minor changes in GNOME 3.30 with headache causing side effects. But way she goes sometimes I suppose.

I'll revise the extension (the Windows bit also needs this rewrite) and post a fix this Thursday (Oct. 11th) after my discrete maths test.

Sounds great. Thanks for taking the time to set up a test environment and revise the extension. With tests and all I assume you are busy so your work is much appreciated.

Cheers.

@vredesbyyrd Hi, thank you for your patience!

I've revised the extension. I wanted a "harder" revise, so that both extensions would use the same
common core library, but I just couldn't get it to work properly... So for now there's some code duplication
between the two components.

Anyways, I was able to successfully test it under all supported platforms, from Ubuntu 16.04 GNOME (GNOME 3.18) to Antergos (Arch, GNOME 3.30). I'll be glad if you could test it!

Thanks a bunch and sorry for the delay!

Hi, you gave a date and stuck to it. So need to apologize :)

I gave your revised extension a test-drive and everything loads fine and does as advertised, copy a directory / file path. I feel I should point one thing out for clarity sake, as I am not sure if this is intended behavior or possibly a limitation of the extension.

When copying any path that contains white spaces, the result might be a little funky? e.g, here is a path that contains spaces copied with 'Xclip'...

/mnt/696AEA387920C07B/Music/Albums/Ulrich Schnauss/2003 - A Strangely Isolated Place

Now, here is the same directory copied with nautilus-copypath:

/mnt/696AEA387920C07B/Music/Albums/Ulrich%20Schnauss/2003%20-%20A%20Strangely%20Isolated%20Place

Lets say you wanted to 'cd' to that directory in your terminal, with the first example you could just throw quotes around the path, or escape it with slashes and be good to go. I am not exactly sure how nautilus-copypath is handling spaces when inserting the '%20'

If it is possible, maybe it is better to leave the spaces in a path intact? Or maybe this is a limitation of my shell and its just not interpreting the '%20' correctly....hmm. Ill read a bit and see if I can figure something out.

Thanks a ton for your timely work! :)

@vredesbyyrd Thanks for the help! It's not your shell - the get_uri method I'm using is
escaping the spaces.

I've removed that completely, and also tested with a couple of directories/files with spaces
in the file name to make sure that it's escaped correctly.

Try it now! One day it'll work, I promise :-P

Just tested and everything is working perfectly now. Automatically escaping spaces properly with the slashes is super convenient :)

Thanks for sharing your work!

Cheers.