Ejemplo n.º 1
0
def _get_xdg_dir(name):
    HOME = util.get_real_home()
    lines = []
    for filename in ["$XDG_CONFIG_HOME/user-dirs.dirs", "%s/.config/user-dirs.dirs" %HOME]:
        if os.path.exists(os.path.expandvars(filename)):
            f = open(filename)
            lines = f.readlines()
            f.close()
            break
    for line in lines:
        if line.startswith('XDG_'+name.upper()):
            return os.path.normpath(os.path.expandvars(line.split('=')[1].strip()[1:-1]))
    return None
Ejemplo n.º 2
0
def setdefaults():
    """Set the shellfolder mappings to directories inside the configuration dir or, if it's default configuration, to matching folders in the user's home directory (using automap)."""
    HOME = util.get_real_home()
    #if HOME == common.ENV['HOME']:
    if common.ENV['WINEPREFIX'] == os.path.expanduser('~/.wine'):
        return automap()

    for folder_name in FOLDER_REG_NAMES.iterkeys():
        create_dir = "%s/%s" % (common.ENV['VINEYARD_DATA'], folder_name)
        if not os.path.exists(create_dir):
            if not os.path.exists(os.path.dirname(create_dir)):
                os.mkdir(os.path.dirname(create_dir))
            os.mkdir(create_dir)
        set(folder_name, create_dir)
Ejemplo n.º 3
0
def setdefaults():
    """Set the shellfolder mappings to directories inside the configuration dir or, if it's default configuration, to matching folders in the user's home directory (using automap)."""
    HOME = util.get_real_home()
    #if HOME == common.ENV['HOME']:
    if common.ENV['WINEPREFIX'] == os.path.expanduser('~/.wine'):
        return automap()

    for folder_name in FOLDER_REG_NAMES.iterkeys():
        create_dir = "%s/%s" % (common.ENV['VINEYARD_DATA'], folder_name)
        if not os.path.exists(create_dir):
            if not os.path.exists(os.path.dirname(create_dir)):
                os.mkdir(os.path.dirname(create_dir))
            os.mkdir(create_dir)
        set(folder_name, create_dir)
Ejemplo n.º 4
0
def automap():
    """Map the shellfolders to matching folders in the user's home directory."""
    HOME = util.get_real_home()
    # Iterate the XDG User Dirs and set Wine's ShellFolders up to match, defaulting to $HOME if there is no matching XDG Dir
    for dirname in [('DESKTOP', 'Desktop'), ('DOCUMENTS', 'My Documents'), ('MUSIC', 'My Music'), ('PICTURES', 'My Pictures'), ('VIDEOS', 'My Videos')]:
        xdgdir = _get_xdg_dir(dirname[0])
        if xdgdir:
            set(dirname[1], xdgdir)
        else:
            # First try, fx. "$HOME/My Documents", then "$HOME/Documents" else just link to "$HOME"
            if os.path.exists("%s/%s" % ( HOME, dirname[0].capitalize() )):
                set(dirname[1], "%s/%s" % ( HOME, dirname[0].capitalize() ))
            elif os.path.exists("%s/%s" % ( HOME, dirname[1] )):
                set(dirname[1], "%s/%s" % ( HOME, dirname[1] ))
            else:
                set(dirname[1], HOME)
Ejemplo n.º 5
0
def _get_xdg_dir(name):
    HOME = util.get_real_home()
    lines = []
    for filename in [
            "$XDG_CONFIG_HOME/user-dirs.dirs",
            "%s/.config/user-dirs.dirs" % HOME
    ]:
        if os.path.exists(os.path.expandvars(filename)):
            f = open(filename)
            lines = f.readlines()
            f.close()
            break
    for line in lines:
        if line.startswith('XDG_' + name.upper()):
            return os.path.normpath(
                os.path.expandvars(line.split('=')[1].strip()[1:-1]))
    return None
Ejemplo n.º 6
0
def automap():
    """Map the shellfolders to matching folders in the user's home directory."""
    HOME = util.get_real_home()
    # Iterate the XDG User Dirs and set Wine's ShellFolders up to match, defaulting to $HOME if there is no matching XDG Dir
    for dirname in [('DESKTOP', 'Desktop'), ('DOCUMENTS', 'My Documents'),
                    ('MUSIC', 'My Music'), ('PICTURES', 'My Pictures'),
                    ('VIDEOS', 'My Videos')]:
        xdgdir = _get_xdg_dir(dirname[0])
        if xdgdir:
            set(dirname[1], xdgdir)
        else:
            # First try, fx. "$HOME/My Documents", then "$HOME/Documents" else just link to "$HOME"
            if os.path.exists("%s/%s" % (HOME, dirname[0].capitalize())):
                set(dirname[1], "%s/%s" % (HOME, dirname[0].capitalize()))
            elif os.path.exists("%s/%s" % (HOME, dirname[1])):
                set(dirname[1], "%s/%s" % (HOME, dirname[1]))
            else:
                set(dirname[1], HOME)