def get_home_dir(): shellvars = ['${HOME}', '${USERPROFILE}'] dir_root = get_dir_root(shellvars) if (dir_root is None) and (os.name == 'nt'): dir = get_shell_dir(shellcon.CSIDL_PROFILE) if dir is None: # there's no clear best fallback here # MS discourages you from writing directly in the home dir, # and sometimes (i.e. win98) there isn't one dir = get_shell_dir(shellcon.CSIDL_DESKTOPDIRECTORY) dir_root = dir return dir_root
def get_save_dir(): dirname = u'%s Downloads' % unicode(app_name) dirname = efs2(dirname) if os.name == 'nt': d = get_shell_dir(shellcon.CSIDL_PERSONAL) if d is None: d = desktop else: d = desktop return os.path.join(d, dirname)
def get_config_dir(): """a cross-platform way to get user's config directory. """ if _config_dir is not None: return _config_dir shellvars = ['${APPDATA}', '${HOME}', '${USERPROFILE}'] dir_root = get_dir_root(shellvars) if dir_root is None and os.name == 'nt': app_dir = get_shell_dir(shellcon.CSIDL_APPDATA) if app_dir is not None: dir_root = app_dir if dir_root is None and os.name == 'nt': tmp_dir_root = os.path.split(sys.executable)[0] if os.access(tmp_dir_root, os.R_OK|os.W_OK): dir_root = tmp_dir_root return dir_root
def get_config_dir(): """a cross-platform way to get user's config directory. """ if _config_dir is not None: return _config_dir shellvars = ['${APPDATA}', '${HOME}', '${USERPROFILE}'] dir_root = get_dir_root(shellvars) if dir_root is None and os.name == 'nt': app_dir = get_shell_dir(shellcon.CSIDL_APPDATA) if app_dir is not None: dir_root = app_dir if dir_root is None and os.name == 'nt': tmp_dir_root = os.path.split(sys.executable)[0] if os.access(tmp_dir_root, os.R_OK | os.W_OK): dir_root = tmp_dir_root return dir_root
def get_startup_dir(): """get directory where symlinks/shortcuts to be run at startup belong""" dir = None if os.name == 'nt': dir = get_shell_dir(shellcon.CSIDL_STARTUP) return dir
try: pid_fname = os.path.join(efs2(u'/var/run'),fname) file(pid_fname, 'w').write(str(os.getpid())) except: try: pid_fname = os.path.join(efs2(u'/etc/tmp'),fname) except: if errorfunc: errorfunc("Couldn't open pid file. Continuing without one.") else: pass # just continue without reporting warning. desktop = None if os.name == 'nt': desktop = get_shell_dir(shellcon.CSIDL_DESKTOPDIRECTORY) else: homedir = get_home_dir() if homedir == None : desktop = '/tmp/' else: desktop = homedir if os.name in ('mac', 'posix'): tmp_desktop = os.path.join(homedir, efs2(u'Desktop')) if os.access(tmp_desktop, os.R_OK|os.W_OK): desktop = tmp_desktop + os.sep
if os.name == 'nt': return try: pid_fname = os.path.join(efs2(u'/var/run'), fname) file(pid_fname, 'w').write(str(os.getpid())) except: try: pid_fname = os.path.join(efs2(u'/etc/tmp'), fname) except: if errorfunc: errorfunc("Couldn't open pid file. Continuing without one.") else: pass # just continue without reporting warning. desktop = None if os.name == 'nt': desktop = get_shell_dir(shellcon.CSIDL_DESKTOPDIRECTORY) else: homedir = get_home_dir() if homedir == None: desktop = '/tmp/' else: desktop = homedir if os.name in ('mac', 'posix'): tmp_desktop = os.path.join(homedir, efs2(u'Desktop')) if os.access(tmp_desktop, os.R_OK | os.W_OK): desktop = tmp_desktop + os.sep
def get_cache_dir(): dir = None if os.name == 'nt': dir = get_shell_dir(shellcon.CSIDL_INTERNET_CACHE) return dir