file -i vs xdg-mime query filetype

Charlie,

When I notice that the google results are mostly unrelated-to-the-question crap I, nowerdays, often put the same keywords/question into DDG. If anything, DDG doesn't seem to replace search (key)words with something that might-or-might-not mean the same that much.

Sometimes I than find what I'm looking that works, and sometimes not. Oh well. :-)

Regards, Rudy Wieser

Reply to
R.Wieser
Loading thread data ...

Dennis,

pi@raspberrypi: ~ $ uname -a Linux raspberrypi 4.19.57-v7+ #1244 SMP Thu Jul 4 18:45:25 BST 2019 armv7l GNU/Linux

Thats exactly the same for both the sd cards I have, even though they come from different sources (one bought, the other downloaded myself. whats the chance of that ? :-) ).

Same folders, but no files ...

So yes, it looks like we've got different versions. Not much, but obviously plenty enough.

Just to retest I created four files with .py extensions on the above machine containing :

1) 2) print("hello world") 3) #! /usr/bin/env python 4) #! /usr/bin/env python3

Using xdg-mime the first three return text/python and the fourth text/python3.

Using file -i the first two return text/plain, the latter two text/python.

The "no execute request" isn't that strange when it doesn't identify as a script and thus the DTM doesn't know which program to start it with. Or maybe its just that that mimetype has no executable registered for it.

Though the "opens in Thonny" does baffle me. The only thing I can think of is that the returned mime type for that file somehow got linked to Thonny. What do the files properties show ? The "Open with:" entry I mean.

Regards, Rudy Wieser

Reply to
R.Wieser

On Wed, 6 Nov 2019 08:59:35 +0100, "R.Wieser" declaimed the following:

Based upon the date, that looks a lot like it is based on NOOBS 3.2.0 (I still have that archived with a download date of July 12). I believe that was the first Buster version using official Debian release (the foundation had released a version using "testing" sources about two weeks earlier because the recently released 4B required the new OS).

formatting link
shows that "NOOBS Lite" is a July 10 file, while the full NOOBS is September 30. Since the Lite version is a network installer I can't tell exactly what version it really installs

-- it might pull down 3.2.1 files if run today.

The foundation doesn't seem to make older images available (unlike Beagle -- they have an FTP site with practically every release including daily development builds)

However it was set "chmod +x" so had the flags that said it was an executable. And typing ./test1.py in a console does execute it.

Thonny seems to be the foundation's preferred Python IDE (ignoring IDLE

-- as I always do ).

test1.py (no shebang) Open with > Geany Thonny Python IDE Text Editor gVim Vim LibreOffice Writer

test2.py (shebang) Open with > mu Geany Thonny Python IDE Text Editor gVim Vim LibreOffice Writer

"mu" is described as a beginning editor for Python -- but isn't running; from a command line I get a nasty traceback ending with

from PyQt5.Qsci import QsciScintilla, QsciLexerPython, QsciAPIs ImportError: /usr/lib/libqscintilla2_qt5.so.13: undefined symbol: _ZN27QsciAccessibleScintillaBase14interface_castEN11QAccessible13InterfaceTyPeE

Going to try apt-get remove on mu-editor, then autoremove on the crud it left behind... then reinstall it... No change, so I'm going to just remove it permanently... No sense having menu entries for things that won't run.

Thonny is the second entry in mailcap for python.

pi@rpi3bplus-1:~$ grep -i "python" /etc/mailcap text/x-python; geany %s; test=test -n "$DISPLAY" text/x-python; /usr/bin/thonny %s; test=test -n "$DISPLAY"

Hmmm, and no x-python3 entries in mailcap, but there is one in the xdg-mime database. Per "man xdg-mime" it uses the various .desktop files to determine what applications go with what types.

pi@rpi3bplus-1:~$ xdg-mime query default text/x-python3 pi@rpi3bplus-1:~$ xdg-mime query default text/x-python Thonny.desktop pi@rpi3bplus-1:~$

... so Thonny is the .desktop configuration for general x-python. And that .desktop file has the mimetype definition line.

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
Reply to
Dennis Lee Bieber

Dennis,

Phew ... I'm glad it looks that way, as that is what it says in the filename. :-)

The file I have archived has a date of 27 september.

Hmmm... Mine is a full version (I don't like to depend on other people keeping stuff available for me), which than should not be possible.

That only helps when it can figure out what to execute it with. AFAIK you can set the execute bit on a textfile, but that doesn't cause it to bexecuted by ... something.

Which makes me suspect that the console and the desktop use different methods to figure out what kind of file they are dealing with (and thus which program they should start it with).

The desktops "programming" group shows both thonny as well as mu. No hint of IDLE (if that is a programs name). And files with the pyton3 shebang are coupled to mu, not thonny (have to figure out how to change that some day too).

Thonny describes itself as the same. No idea how they are different though, as I tend to stick with what works for me. And to be honest, I currently use it as a text editor which a launch capability.

Regards, Rudy Wieser

Reply to
R.Wieser

On Wed, 6 Nov 2019 20:40:34 +0100, "R.Wieser" declaimed the following:

Looks like you downloaded it a few days /before/ 3.2.1 went on-line.

Console probably relies upon "file" and mailcap -- and that uses a number of different methods. The infamous "magic number" being one (a shebang being one of those "magic numbers"). It may also have a database of common file extensions, or some regular expression parsing of the first few lines of a file.

IDLE is a Python script that uses Tkinter (Python interface to TCL/Tk) for GUI.

Interesting... It looks like Raspbian includes IDLE for Python 2.7 but not 3.x -- yet there are .desktop files for the latter (which try to invoke /usr/bin/idle-python3.7 -- and that does not exist).

pi@rpi3bplus-1:~$ sudo find / -iname "idle*" /usr/lib/pypy/lib-python/2.7/idlelib /usr/lib/pypy/lib-python/2.7/idlelib/idle.py /usr/share/raspi-ui-overrides/applications/idle-python3.7.desktop /usr/share/man/man2/idle.2.gz pi@rpi3bplus-1:~$

Since I uninstalled mu, I don't have a .desktop file for it; I'll use the thonny desktop file for the example.

pi@rpi3bplus-1:~$ cat /usr/share/applications/Thonny.desktop [Desktop Entry] Type=Application Name=Thonny Python IDE GenericName=Python IDE Exec=/usr/bin/thonny %F Comment=Python IDE for beginners Icon=thonny Terminal=false Categories=Application;Development; StartupNotify=true MimeType=text/x-python;

Reply to
Dennis Lee Bieber

Dennis,

Yep. Don't know how I did that though. As far as I remember I just went to a(n official looking) Raspberry Pi website, and downloaded the, at that time, latest version. I didn't hack my way in, used a time-traveling machine or anything like that.

Ehrmm... The OS takes its clues to which program a file can be opened with from looking in those *.desktop files ? Does that also mean there are restrictions to where I am allowed to create them ?

It does. Actually, it has the mimetype mentioned twice (no idea why, but I assume someone/thing bungled up there).

After having added the text/x-python3 mimetype to thonny I see that it shows in the current .py files rightclick menu.

Thanks. You're a bit of a treasure-trove to a freshling like me. :-)

Funny though: After I create a new .py file by using rightclick -> create new... rightclicking it doesn't show thonny. But after I put a single 'enter' in it it does. Thats a (bad) behaviour that needs some getting accustomed to.

Regards, Rudy Wieser

Reply to
R.Wieser

On Thu, 7 Nov 2019 08:31:12 +0100, "R.Wieser" declaimed the following:

As I understand it, the GUI desktop manager uses .desktop files to populate the (right-click) menu for files.

formatting link

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
Reply to
Dennis Lee Bieber

Dennis,

That is what I assumed too. But having searched the drive for files with a specific name a few times and noticing that takes tens of seconds, if not minutes, I could not imagine you could just place those .desktop files anywhere.

Although the webpage you liked to talks about GNOME, I take it lxpanel uses the same mechanism (it makes sense).

...

(notice the last line)

So, the answer to my question seems to be "Yes". :-) And thats good to know (causes less "why doesn't it work?!" confusion).

Regards, Rudy Wieser

Reply to
R.Wieser

On Thu, 7 Nov 2019 19:33:44 +0100, "R.Wieser" declaimed the following:

formatting link
Note who develops GTK... then...

formatting link
Note the desktop systems using it... and then...

formatting link
Note what Pixel used for the base... (paragraph just above the roadway image)

Wikipedia states LXDE development is now inactive (which likely explains why Beaglebone images switched from LXDE to LXQT -- LXQT is essentially the LX desktop ported to the QT graphics library)

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
Reply to
Dennis Lee Bieber

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.