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

Discussion in 'Python' started by Eric_Dexter@msn.com, Dec 16, 2009.

  1. Guest

    #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/
     
    , Dec 16, 2009
    #1
    1. Advertising

  2. Paul Boddie Guest

    On 16 Des, 17:03, "" <> 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
     
    Paul Boddie, Dec 16, 2009
    #2
    1. Advertising

  3. Guest

    On Dec 16, 10:36 am, Paul Boddie <> wrote:
    > On 16 Des, 17:03, "" <> 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


    "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.
     
    , Dec 16, 2009
    #3
  4. Guest

    On Dec 16, 3:02 pm, "" <> wrote:
    > On Dec 16, 10:36 am, Paul Boddie <> wrote:
    >
    >
    >
    > > On 16 Des, 17:03, "" <> 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

    >
    > "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
     
    , Dec 17, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver Bleckmann
    Replies:
    2
    Views:
    356
    Keith Thompson
    Nov 12, 2006
  2. Oliver Bleckmann
    Replies:
    6
    Views:
    451
    ondra.holub
    Nov 13, 2006
  3. Michael Reichenbach
    Replies:
    5
    Views:
    387
    Zeppe
    May 25, 2007
  4. Lawrence D'Oliveiro

    XDG Base Directory Specification

    Lawrence D'Oliveiro, Dec 28, 2009, in forum: Python
    Replies:
    0
    Views:
    339
    Lawrence D'Oliveiro
    Dec 28, 2009
  5. Intransition

    XDG 1.0

    Intransition, Dec 2, 2009, in forum: Ruby
    Replies:
    0
    Views:
    82
    Intransition
    Dec 2, 2009
Loading...

Share This Page