def _lookup(cmd): '''Lookup cmd in PATH''' if zim.fs.isabs(cmd): if zim.fs.isfile(cmd): return cmd else: return None elif os.name == 'nt': # Check executable extensions from windows environment extensions = environ.get_list('PATHEXT', '.com;.exe;.bat;.cmd') for dir in environ.get_list('PATH'): for ext in extensions: file = os.sep.join((dir, cmd + ext)) if zim.fs.isfile(file) and os.access(file, os.X_OK): return file else: return None else: # On POSIX no extension is needed to make scripts executable for dir in environ.get_list('PATH'): file = os.sep.join((dir, cmd)) if zim.fs.isfile(file) and os.access(file, os.X_OK): return file else: return None
def _lookup(cmd): '''Lookup cmd in PATH''' if zim.fs.isabs(cmd): if zim.fs.isfile(cmd): return cmd else: return None elif os.name == 'nt': # Check executable extensions from windows environment extensions = environ.get_list('PATHEXT', '.com;.exe;.bat;.cmd') for dir in environ.get_list('PATH'): for ext in extensions: file = os.sep.join((dir, cmd + ext)) if zim.fs.isfile(file) and os.access(file, os.X_OK): return file else: return None else: # On POSIX no extension is needed to make scripts executable for dir in environ.get_list('PATH'): file = os.sep.join((dir, cmd)) if zim.fs.isfile(file) and os.access(file, os.X_OK): return file else: return None
def set_basedirs(): '''This method sets the global configuration paths for according to the freedesktop basedir specification. Called automatically when module is first loaded, should be called explicitly only when environment has changed. ''' global ZIM_DATA_DIR global XDG_DATA_HOME global XDG_DATA_DIRS global XDG_CONFIG_HOME global XDG_CONFIG_DIRS global XDG_CACHE_HOME # Cast string to folder import zim zim_data_dir = File(zim.ZIM_EXECUTABLE).dir.subdir('data') if zim_data_dir.exists(): ZIM_DATA_DIR = zim_data_dir if os.name == 'nt': APPDATA = environ['APPDATA'] XDG_DATA_HOME = Dir( environ.get('XDG_DATA_HOME', APPDATA + r'\zim\data')) XDG_DATA_DIRS = map(Dir, environ.get_list('XDG_DATA_DIRS', '~/.local/share/')) # Backwards compatibility XDG_CONFIG_HOME = Dir( environ.get('XDG_CONFIG_HOME', APPDATA + r'\zim\config')) XDG_CONFIG_DIRS = map(Dir, environ.get_list('XDG_CONFIG_DIRS', '~/.config/')) # Backwards compatibility XDG_CACHE_HOME = Dir( environ.get('XDG_CACHE_HOME', APPDATA + r'\zim\cache')) else: XDG_DATA_HOME = Dir( environ.get('XDG_DATA_HOME', '~/.local/share/')) XDG_DATA_DIRS = map(Dir, environ.get_list('XDG_DATA_DIRS', ('/usr/share/', '/usr/local/share/'))) XDG_CONFIG_HOME = Dir( environ.get('XDG_CONFIG_HOME', '~/.config/')) XDG_CONFIG_DIRS = map(Dir, environ.get_list('XDG_CONFIG_DIRS', ('/etc/xdg/',))) XDG_CACHE_HOME = Dir( environ.get('XDG_CACHE_HOME', '~/.cache'))
def testGetListPath(self): path = environ.get_list('PATH') self.assertGreater(len(path), 0) for dir in map(Dir, path): if dir.exists(): break else: raise AssertionError, 'No existing dirs found in PATH: %s' % path
def set_basedirs(): '''This method sets the global configuration paths for according to the freedesktop basedir specification. Called automatically when module is first loaded, should be called explicitly only when environment has changed. ''' global ZIM_DATA_DIR global XDG_DATA_HOME global XDG_DATA_DIRS global XDG_CONFIG_HOME global XDG_CONFIG_DIRS global XDG_CACHE_HOME # Cast string to folder import zim zim_data_dir = File(zim.ZIM_EXECUTABLE).dir.subdir('data') if zim_data_dir.exists(): ZIM_DATA_DIR = zim_data_dir if os.name == 'nt': APPDATA = environ['APPDATA'] XDG_DATA_HOME = Dir( environ.get('XDG_DATA_HOME', APPDATA + r'\zim\data')) XDG_DATA_DIRS = map(Dir, environ.get_list('XDG_DATA_DIRS', '~/.local/share/')) # Backwards compatibility XDG_CONFIG_HOME = Dir( environ.get('XDG_CONFIG_HOME', APPDATA + r'\zim\config')) XDG_CONFIG_DIRS = map(Dir, environ.get_list('XDG_CONFIG_DIRS', '~/.config/')) # Backwards compatibility try: import _winreg as wreg wreg_key = wreg.OpenKey( wreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders') cache_dir = str(wreg.QueryValueEx(wreg_key, "Cache")[0].replace(u'%USERPROFILE%', environ['USERPROFILE'])) wreg.CloseKey(wreg_key) except: cache_dir = APPDATA + r'\zim\cache' # Not using TMP here because it is cleaned too often XDG_CACHE_HOME = Dir( environ.get('XDG_CACHE_HOME', cache_dir + r'\zim')) else: XDG_DATA_HOME = Dir( environ.get('XDG_DATA_HOME', '~/.local/share/')) XDG_DATA_DIRS = map(Dir, environ.get_list('XDG_DATA_DIRS', ('/usr/share/', '/usr/local/share/'))) XDG_CONFIG_HOME = Dir( environ.get('XDG_CONFIG_HOME', '~/.config/')) XDG_CONFIG_DIRS = map(Dir, environ.get_list('XDG_CONFIG_DIRS', ('/etc/xdg/',))) XDG_CACHE_HOME = Dir( environ.get('XDG_CACHE_HOME', '~/.cache'))
def set_basedirs(): '''This method sets the global configuration paths for according to the freedesktop basedir specification. Called automatically when module is first loaded, should be called explicitly only when environment has changed. ''' global ZIM_DATA_DIR global XDG_DATA_HOME global XDG_DATA_DIRS global XDG_CONFIG_HOME global XDG_CONFIG_DIRS global XDG_CACHE_HOME # Cast string to folder import zim zim_data_dir = File(zim.ZIM_EXECUTABLE).dir.subdir('data') if zim_data_dir.exists(): ZIM_DATA_DIR = zim_data_dir if os.name == 'nt': APPDATA = environ['APPDATA'] XDG_DATA_HOME = Dir( environ.get('XDG_DATA_HOME', APPDATA + r'\zim\data')) XDG_DATA_DIRS = map(Dir, environ.get_list( 'XDG_DATA_DIRS', '~/.local/share/')) # Backwards compatibility XDG_CONFIG_HOME = Dir( environ.get('XDG_CONFIG_HOME', APPDATA + r'\zim\config')) XDG_CONFIG_DIRS = map( Dir, environ.get_list('XDG_CONFIG_DIRS', '~/.config/')) # Backwards compatibility try: import _winreg as wreg wreg_key = wreg.OpenKey( wreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' ) cache_dir = str( wreg.QueryValueEx(wreg_key, "Cache")[0].replace(u'%USERPROFILE%', environ['USERPROFILE'])) wreg.CloseKey(wreg_key) except: cache_dir = APPDATA + r'\zim\cache' # Not using TMP here because it is cleaned too often XDG_CACHE_HOME = Dir(environ.get('XDG_CACHE_HOME', cache_dir + r'\zim')) else: XDG_DATA_HOME = Dir(environ.get('XDG_DATA_HOME', '~/.local/share/')) XDG_DATA_DIRS = map( Dir, environ.get_list('XDG_DATA_DIRS', ('/usr/share/', '/usr/local/share/'))) XDG_CONFIG_HOME = Dir(environ.get('XDG_CONFIG_HOME', '~/.config/')) XDG_CONFIG_DIRS = map( Dir, environ.get_list('XDG_CONFIG_DIRS', ('/etc/xdg/', ))) XDG_CACHE_HOME = Dir(environ.get('XDG_CACHE_HOME', '~/.cache'))