32
34
logger = setup_logging("ubuntu_sso.utils")
39
def _get_dir(dir_name, dir_constant):
40
"""Return the absolute path to this project's 'dir_name' dir.
42
Support symlinks, and priorize local (relative) 'dir_name' dir. If not
43
found, return the value of the 'dir_constant'.
46
module = os.path.dirname(__file__)
47
result = os.path.abspath(os.path.join(module, os.path.pardir,
48
os.path.pardir, dir_name))
49
logger.debug('_get_dir: trying use dir at %r (exists? %s)',
50
result, os.path.exists(result))
51
if os.path.exists(result):
52
logger.info('_get_dir: returning dir located at %r.', result)
55
# otherwise, try to load 'dir_constant' from installation path
57
module = sys.modules.get('ubuntu_sso.constants')
58
return getattr(module, dir_constant)
59
except AttributeError:
60
msg = '_get_dir: can not build a valid path. Giving up. ' \
61
'__file__ is %r, constants module not available.'
62
logger.error(msg, __file__)
65
def get_project_dir():
66
"""Return the absolute path to this project's data/ dir.
68
Support symlinks, and priorize local (relative) data/ dir. If not
69
found, return the value of the PROJECT_DIR.
72
return _get_dir(dir_name=DATA_SUFFIX, dir_constant='PROJECT_DIR')
75
def get_data_file(*args):
76
"""Return the absolute path to 'args' within project data dir."""
77
return os.path.join(get_project_dir(), *args)
81
"""Return the absolute path to this project's bin/ dir.
83
Support symlinks, and priorize local (relative) bin/ dir. If not
84
found, return the value of the BIN_DIR.
87
return _get_dir(dir_name=BIN_SUFFIX, dir_constant='BIN_DIR')
35
90
class RequestHead(urllib2.Request):