~josernestodavila/glipper/autostart-gnome-unity

« back to all changes in this revision

Viewing changes to glipper/__init__.py

  • Committer: Laszlo Pandy
  • Date: 2011-04-08 23:06:47 UTC
  • Revision ID: bzr@laszlopandy.com-20110408230647-x3sju8ubsnj3kv7q
XDG_DATA_HOMEĀ support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os, sys
2
2
from os.path import join, exists, isdir, isfile, dirname, abspath, expanduser
3
3
 
 
4
import xdg.BaseDirectory
4
5
import gtk, gtk.gdk, gconf
5
6
 
6
7
# Autotools set the actual data_dir in defs.py
30
31
print "SHARED_DATA_DIR: %s" % SHARED_DATA_DIR
31
32
 
32
33
 
33
 
USER_GLIPPER_DIR = expanduser("~/.glipper")
34
 
if not exists(USER_GLIPPER_DIR):
 
34
# check if it exists first, because save_data_path() creates the folder
 
35
xdg_dir_existed = exists(join(xdg.BaseDirectory.xdg_data_home, 'glipper'))
 
36
try:
 
37
        USER_GLIPPER_DIR = xdg.BaseDirectory.save_data_path('glipper')
 
38
except OSError, e:
 
39
        print 'Error: could not create user glipper dir (%s): %s' % (join(xdg.BaseDirectory.xdg_data_home, 'glipper'), e)
 
40
        sys.exit(1)
 
41
 
 
42
if exists(expanduser("~/.glipper")) and not xdg_dir_existed:
 
43
        # first run for new directory; move old ~/.glipper
35
44
        try:
36
 
                os.makedirs(USER_GLIPPER_DIR, 0744)
37
 
        except Exception , msg:
38
 
                print 'Error:could not create user glipper dir (%s): %s' % (USER_GLIPPER_DIR, msg)
 
45
                os.rename(expanduser("~/.glipper"), USER_GLIPPER_DIR)
 
46
        except OSError:
 
47
                # folder must already have some files in it 
 
48
                # (race condition with xdg_dir_existed check)
 
49
                pass
39
50
 
40
51
# ------------------------------------------------------------------------------
41
52
 
45
56
else:
46
57
        PLUGINS_DIR = join(SHARED_DATA_DIR, 'plugins')
47
58
 
 
59
# Path to plugins save directory
 
60
USER_PLUGINS_DIR = xdg.BaseDirectory.save_data_path('glipper', 'plugins')
 
61
 
48
62
# Path to history file
49
63
HISTORY_FILE = join(USER_GLIPPER_DIR, "history")
50
64