I have a cross platform os.startfile but I need to asociate fileswith xdg-open in linux how do I do

E

Eric_Dexter

#this should be a cross platform example of os.startfile ( startfile )
#for windows and linux. this is the first version and
#linux, mac, other os's commands for exceptions to the
#rule would be appreciated. at some point this will be
#in the dex tracker project.

import os
import subprocess

def startfile(filename)
try:
os.startfile(filename)
except:
subprocess.Popen(['xdg-open', filename])


_______________________________
http://dextracker.blogspot.com/
 
P

Paul Boddie

#this should be a cross platform example of os.startfile ( startfile )
#for windows and linux.  this is the first version and
#linux, mac, other os's commands for exceptions to the
#rule would be appreciated.  at some point this will be
#in the dex tracker project.

You could look at the desktop package for something similar:

http://pypi.python.org/pypi/desktop

The desktop.open function supports a few extra workarounds, mostly
because it pre-dates xdg-open.

Paul
 
E

Eric_Dexter

You could look at the desktop package for something similar:

http://pypi.python.org/pypi/desktop

The desktop.open function supports a few extra workarounds, mostly
because it pre-dates xdg-open.

Paul

"Since desktop environments like KDE and GNOME provide mechanisms for
running
browsers and editors according to the identified type of a file or
resource,
just as Windows "runs" files or resources, it is appropriate to have a
module
which accesses these mechanisms. It is this kind of functionality that
the
desktop package aims to support. Note that this approach is arguably
better"

I am concerned this means I cant do something like associate python
files with python in artistx (ubuntu). It just associates text files
with editors?? It does look like a cool package and I will look into
that further.
 
E

Eric_Dexter

"Since desktop environments like KDE and GNOME provide mechanisms for
running
browsers and editors according to the identified type of a file or
resource,
just as Windows "runs" files or resources, it is appropriate to have a
module
which accesses these mechanisms. It is this kind of functionality that
the
desktop package aims to support. Note that this approach is arguably
better"

I am concerned this means I cant do something like associate python
files with python in artistx (ubuntu).  It just associates text files
with editors??  It does look like a cool package and I will look into
that further.

I suppose I could test the extension.. if '.py' in filename and then
default to xdg-open if it isn't seems realy messy though.

______________________________
http://dextracker.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top