~nataliabidart/ubuntuone-control-panel/use-new-syncademon-get-udf-fict

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/utils.py

  • Committer: Natalia B. Bidart
  • Date: 2010-11-08 20:32:42 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: natalia.bidart@canonical.com-20101108203242-3015oxw1ogekdz9k
Modified setup.py so ui files are automatically grabbed by distutils-extra.

Added .in files to define at installation time the paths for the dbus service
and the data dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from functools import wraps
24
24
 
 
25
import xdg.BaseDirectory
 
26
 
25
27
from ubuntuone.controlpanel.logger import setup_logging
26
28
 
27
29
 
28
30
logger = setup_logging('utils')
 
31
DATA_SUFFIX = 'data'
29
32
 
30
33
 
31
34
def get_data_dir():
34
37
    Support symlinks, and priorize local (relative) data/ dir.
35
38
    """
36
39
    module = os.path.dirname(__file__)
37
 
    result = os.path.abspath(os.path.join(module, os.path.pardir,
38
 
                                          os.path.pardir, 'data'))
39
 
    return result
 
40
    local = os.path.abspath(os.path.join(module, os.path.pardir,
 
41
                                         os.path.pardir, DATA_SUFFIX))
 
42
    data_dirs = [local] + [os.path.join(p, 'ubuntuone-control-panel')
 
43
                           for p in xdg.BaseDirectory.xdg_data_dirs]
 
44
    for result in data_dirs:
 
45
        result = os.path.abspath(result)
 
46
        logger.debug('get_data_dir: trying use data dir at %r (exists? %s)',
 
47
                     result, os.path.exists(result))
 
48
        if os.path.exists(result):
 
49
            logger.info('get_data_dir: returning dir located at %r.', result)
 
50
            return result
 
51
 
 
52
    # try to load DATA_DIR from installation path
 
53
    try:
 
54
        # pylint: disable=F0401, E0611
 
55
        from ubuntuone.controlpanel.constants import DATA_DIR
 
56
        return DATA_DIR
 
57
    except ImportError:
 
58
        msg = 'get_data_dir: can not build a valid data path. Giving up.' \
 
59
              '__file__ is %r, data_dirs are %r, constants module unavailable.'
 
60
        logger.error(msg, __file__, data_dirs)
40
61
 
41
62
 
42
63
def get_data_file(filename):