Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I have a cross platform os.startfile but I need to asociate files with xdg-open in linux how do I do that??

5 views
Skip to first unread message

Eric_...@msn.com

unread,
Dec 16, 2009, 11:03:31 AM12/16/09
to
#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/

Paul Boddie

unread,
Dec 16, 2009, 11:36:33 AM12/16/09
to
On 16 Des, 17:03, "Eric_Dex...@msn.com" <Eric_Dex...@msn.com> wrote:
> #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

Eric_...@msn.com

unread,
Dec 16, 2009, 4:02:20 PM12/16/09
to

"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.

Eric_...@msn.com

unread,
Dec 17, 2009, 3:21:42 PM12/17/09
to

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

0 new messages