<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import glob <EOL> def _SHGetFolderPath ( folderID ) : <EOL> from ctypes import wintypes , windll , c_int <EOL> path_buf = wintypes . create_unicode_buffer ( wintypes . MAX_PATH ) <EOL> result = windll . shell32 . SHGetFolderPathW ( <NUM_LIT:0> , folderID , <NUM_LIT:0> , <NUM_LIT:0> , path_buf ) <EOL> if result : <EOL> if result < <NUM_LIT:0> : <EOL> result += <NUM_LIT> <EOL> print path_buf . value <EOL> raise RuntimeError ( "<STR_LIT>" % result ) <EOL> return path_buf . value <EOL> def _mangle_evepath ( path , server ) : <EOL> path = path . lower ( ) . replace ( "<STR_LIT::>" , "<STR_LIT>" ) . replace ( "<STR_LIT:\\>" , "<STR_LIT:_>" ) . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:_>" ) <EOL> path += "<STR_LIT:_>" + server . lower ( ) <EOL> return path <EOL> def _get_protocol ( machopath , bulkpath ) : <EOL> protocol = - <NUM_LIT:1> <EOL> for scandir in ( machopath , bulkpath ) : <EOL> if scandir is not None : <EOL> for dirName in glob . glob ( os . path . join ( scandir , "<STR_LIT:*>" ) ) : <EOL> candidate = os . path . basename ( dirName ) <EOL> if candidate . isdigit ( ) : <EOL> protocol = max ( protocol , int ( candidate ) ) <EOL> if protocol > - <NUM_LIT:1> : <EOL> return protocol <EOL> class _Paths ( object ) : <EOL> def __init__ ( self , root ) : <EOL> if root is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> root = os . path . abspath ( root ) <EOL> self . root = root <EOL> self . sharedcache = None <EOL> self . cache = None <EOL> self . settings = None <EOL> self . machocache = None <EOL> self . bulkdata_updates = None <EOL> self . bulkdata = None <EOL> self . wineprefix = None <EOL> def _set_known_paths ( self , cache = None , sharedcache = None , wineprefix = None ) : <EOL> self . cache = cache <EOL> self . sharedcache = sharedcache <EOL> self . wineprefix = wineprefix <EOL> def _discover ( self , server_name , server_ip , protocol ) : <EOL> if self . cache is None : <EOL> _path = os . path . join ( self . root , "<STR_LIT>" ) <EOL> if os . path . exists ( _path ) : <EOL> self . cache = self . root <EOL> if self . sharedcache is None : <EOL> _path = os . path . join ( self . root , "<STR_LIT>" ) <EOL> if os . path . exists ( _path ) : <EOL> self . sharedcache = _path <EOL> if os . name == "<STR_LIT>" : <EOL> self . __discover_windows ( server_name ) <EOL> elif sys . platform == "<STR_LIT>" or os . name == "<STR_LIT>" : <EOL> if self . wineprefix is None : <EOL> self . __discover_mac ( server_name ) <EOL> else : <EOL> self . __discover_linux ( server_name ) <EOL> elif os . name in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . __discover_linux ( server_name ) <EOL> self . bulkdata = os . path . join ( self . root , '<STR_LIT>' ) <EOL> if self . cache is not None : <EOL> self . _cache = os . path . join ( self . cache , '<STR_LIT>' ) <EOL> self . settings = os . path . join ( self . cache , '<STR_LIT>' ) <EOL> _bulkdata_updates = os . path . join ( self . _cache , '<STR_LIT>' ) <EOL> _machocache = os . path . join ( self . _cache , '<STR_LIT>' , server_ip ) <EOL> if protocol is None : <EOL> protocol = _get_protocol ( _machocache , _bulkdata_updates ) <EOL> if protocol is not None : <EOL> self . machocache = os . path . join ( _machocache , str ( protocol ) ) <EOL> self . bulkdata_updates = os . path . join ( _bulkdata_updates , str ( protocol ) ) <EOL> if not os . path . exists ( self . machocache ) : <EOL> raise RuntimeError ( "<STR_LIT>" % ( protocol , _machocache ) ) <EOL> return protocol <EOL> def __discover_windows ( self , server_name ) : <EOL> self . root = os . path . abspath ( self . root ) <EOL> _localappdata = _SHGetFolderPath ( <NUM_LIT> ) <EOL> _programdata = _SHGetFolderPath ( <NUM_LIT> ) <EOL> _programdata = os . getenv ( "<STR_LIT>" , _programdata ) <EOL> if self . sharedcache is None : <EOL> import _winreg <EOL> _winreg . aReg = _winreg . ConnectRegistry ( None , _winreg . HKEY_CURRENT_USER ) <EOL> try : <EOL> key = _winreg . OpenKey ( _winreg . aReg , '<STR_LIT>' ) <EOL> self . sharedcache , _ = _winreg . QueryValueEx ( key , '<STR_LIT>' ) <EOL> except OSError : <EOL> pass <EOL> if self . sharedcache is None : <EOL> self . sharedcache = os . path . join ( _programdata , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not ( self . sharedcache and os . path . exists ( self . sharedcache ) ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if self . cache is None : <EOL> self . cache = os . path . join ( _localappdata , "<STR_LIT>" , "<STR_LIT>" , _mangle_evepath ( self . root , server_name ) ) <EOL> def __discover_mac ( self , server_name ) : <EOL> home = os . path . expanduser ( '<STR_LIT>' ) <EOL> _localappdata = os . path . join ( home , "<STR_LIT>" ) <EOL> if not os . path . exists ( _localappdata ) : <EOL> _localappdata = os . path . join ( home , "<STR_LIT>" ) <EOL> _programdata = _localappdata <EOL> actualroot = os . path . join ( self . root , "<STR_LIT>" ) <EOL> if os . path . exists ( actualroot ) : <EOL> self . root = actualroot <EOL> if self . sharedcache is None : <EOL> self . sharedcache = os . path . join ( _programdata , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if self . cache is None : <EOL> self . cache = os . path . join ( _localappdata , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" + server_name . lower ( ) ) <EOL> def __discover_linux ( self , server_name ) : <EOL> import pwd <EOL> stat_info = os . stat ( self . root ) <EOL> user = pwd . getpwuid ( stat_info . st_uid ) . pw_name <EOL> def _scan_folders ( paths , pattern ) : <EOL> for path in paths : <EOL> for path in glob . iglob ( os . path . join ( path , pattern ) ) : <EOL> if exists ( path ) : <EOL> return path <EOL> error = None <EOL> if self . wineprefix is None : <EOL> error = "<STR_LIT>" <EOL> else : <EOL> x = self . root . find ( os . path . join ( self . wineprefix , "<STR_LIT>" ) ) <EOL> if x > - <NUM_LIT:1> : <EOL> wineroot = self . root [ : x + len ( self . wineprefix ) ] <EOL> else : <EOL> error = "<STR_LIT>" % ( self . wineprefix , self . root ) <EOL> if self . sharedcache is None : <EOL> if error : <EOL> raise RuntimeError ( error ) <EOL> self . sharedcache = _scan_folders ( ( os . path . join ( wineroot , "<STR_LIT>" ) ) , "<STR_LIT>" ) <EOL> if self . cache is None and error is None : <EOL> candidates = ( <EOL> os . path . join ( wineroot , "<STR_LIT>" , user ) , <EOL> os . path . join ( wineroot , "<STR_LIT>" , user ) , <EOL> os . path . join ( wineroot , "<STR_LIT>" , user ) , <EOL> ) <EOL> cacheFolderName = _mangle_evepath ( self . root [ x + len ( self . wineprefix ) + <NUM_LIT:7> : ] , server_name ) <EOL> self . cache = _scan_folders ( candidates , "<STR_LIT>" + cacheFolderName ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> paths = _Paths ( "<STR_LIT>" ) <EOL> paths . _discover ( "<STR_LIT>" , "<STR_LIT>" , None ) <EOL> for k , v in paths . __dict__ . iteritems ( ) : <EOL> print "<STR_LIT>" % ( k , v ) </s>
