<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import io <EOL> import string <EOL> import getpass <EOL> import platform <EOL> import _winreg <EOL> import sublime <EOL> def _log ( function , string ) : <EOL> if log : <EOL> print "<STR_LIT>" + function + "<STR_LIT>" + string <EOL> def program_path ( ) : <EOL> """<STR_LIT>""" <EOL> return _program_path <EOL> def program_drive ( ) : <EOL> """<STR_LIT>""" <EOL> return _program_drive <EOL> def settings_path ( ) : <EOL> """<STR_LIT>""" <EOL> return _settings_path <EOL> def skins_path ( ) : <EOL> """<STR_LIT>""" <EOL> return _skins_path <EOL> def plugins_path ( ) : <EOL> """<STR_LIT>""" <EOL> return _plugins_path <EOL> def addons_path ( ) : <EOL> """<STR_LIT>""" <EOL> return _addons_path <EOL> def get_program_path ( ) : <EOL> """<STR_LIT>""" <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> rainmeterpath = settings . get ( "<STR_LIT>" , None ) <EOL> if not rainmeterpath : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> programfiles = os . getenv ( "<STR_LIT>" ) <EOL> rainmeterpath = os . path . join ( programfiles , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> rainmeterpath = os . path . normpath ( rainmeterpath ) + "<STR_LIT:\\>" <EOL> if not os . path . exists ( rainmeterpath + "<STR_LIT>" ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + rainmeterpath ) <EOL> return rainmeterpath <EOL> def get_program_drive ( ) : <EOL> """<STR_LIT>""" <EOL> rainmeterpath = program_path ( ) <EOL> if not rainmeterpath : return <EOL> if re . match ( "<STR_LIT>" , rainmeterpath ) : <EOL> return os . path . splitdrive ( rainmeterpath ) [ <NUM_LIT:0> ] <EOL> if rainmeterpath . startswith ( r"<STR_LIT:\\>" ) : <EOL> return os . path . splitunc ( rainmeterpath ) [ <NUM_LIT:0> ] <EOL> return <EOL> def get_settings_path ( ) : <EOL> """<STR_LIT>""" <EOL> rainmeterpath = program_path ( ) <EOL> if not rainmeterpath : return <EOL> if os . path . exists ( rainmeterpath + "<STR_LIT>" ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + rainmeterpath ) <EOL> return rainmeterpath <EOL> else : <EOL> appdata = os . getenv ( "<STR_LIT>" ) <EOL> if os . path . exists ( os . path . join ( appdata , "<STR_LIT>" ) ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> os . path . join ( appdata , "<STR_LIT>" ) + "<STR_LIT:\\>" ) <EOL> return os . path . join ( appdata , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> else : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return None <EOL> def get_skins_path ( ) : <EOL> """<STR_LIT>""" <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> skinspath = settings . get ( "<STR_LIT>" , None ) <EOL> if skinspath : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return os . path . normpath ( skinspath ) + "<STR_LIT:\\>" <EOL> rainmeterpath = program_path ( ) <EOL> if not rainmeterpath : return <EOL> settingspath = settings_path ( ) <EOL> if not settingspath : return <EOL> fhnd = io . open ( os . path . join ( settingspath , "<STR_LIT>" ) ) <EOL> lines = fhnd . read ( ) <EOL> fhnd . close ( ) <EOL> match = re . search ( r"""<STR_LIT>""" , lines ) <EOL> if match : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return match . group ( "<STR_LIT>" ) . strip ( ) . replace ( "<STR_LIT:/>" , "<STR_LIT:\\>" ) <EOL> if os . path . samefile ( rainmeterpath , settingspath ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return os . path . join ( rainmeterpath , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> try : <EOL> regkey = _winreg . OpenKey ( _winreg . HKEY_CURRENT_USER , <EOL> r"<STR_LIT>" + <EOL> r"<STR_LIT>" + <EOL> r"<STR_LIT>" ) <EOL> keyval = _winreg . QueryValueEx ( regkey , "<STR_LIT>" ) <EOL> pathrep = keyval [ <NUM_LIT:0> ] <EOL> pathrep = os . path . expandvars ( pathrep ) <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return os . path . join ( pathrep , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> except WindowsError : <EOL> pass <EOL> try : <EOL> username = getpass . getuser ( ) <EOL> except Exception : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return <EOL> else : <EOL> mydocuments = "<STR_LIT>" <EOL> winversion = platform . version ( ) <EOL> if int ( winversion [ <NUM_LIT:0> ] ) < <NUM_LIT:6> : <EOL> mydocuments = os . path . join ( "<STR_LIT>" , <EOL> username , <EOL> "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + mydocuments + <EOL> "<STR_LIT>" ) <EOL> else : <EOL> mydocuments = os . path . join ( "<STR_LIT>" , <EOL> username , <EOL> "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + mydocuments + <EOL> "<STR_LIT>" ) <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return os . path . join ( mydocuments , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> def get_plugins_path ( ) : <EOL> """<STR_LIT>""" <EOL> settingspath = settings_path ( ) <EOL> if not settingspath : return <EOL> return os . path . join ( settingspath , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> def get_addons_path ( ) : <EOL> """<STR_LIT>""" <EOL> settingspath = settings_path ( ) <EOL> if not settingspath : return <EOL> return os . path . join ( settingspath , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> def get_current_path ( filepath ) : <EOL> """<STR_LIT>""" <EOL> filepath = os . path . normpath ( filepath ) <EOL> skinspath = skins_path ( ) <EOL> if not skinspath or not filepath . startswith ( skinspath ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return <EOL> if os . path . isfile ( filepath ) : <EOL> return os . path . dirname ( filepath ) + "<STR_LIT:\\>" <EOL> else : <EOL> return filepath + "<STR_LIT:\\>" <EOL> def get_root_config_path ( filepath ) : <EOL> """<STR_LIT>""" <EOL> filepath = os . path . normpath ( filepath ) <EOL> skinspath = skins_path ( ) <EOL> if not skinspath or not filepath . startswith ( skinspath ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return <EOL> relpath = os . path . relpath ( filepath , skinspath ) <EOL> _log ( "<STR_LIT>" , <EOL> os . path . join ( skinspath , relpath . split ( "<STR_LIT:\\>" ) [ <NUM_LIT:0> ] ) + "<STR_LIT:\\>" ) <EOL> return os . path . join ( skinspath , relpath . split ( "<STR_LIT:\\>" ) [ <NUM_LIT:0> ] ) + "<STR_LIT:\\>" <EOL> def get_current_file ( filepath ) : <EOL> """<STR_LIT>""" <EOL> filepath = os . path . normpath ( filepath ) <EOL> skinspath = skins_path ( ) <EOL> if not skinspath or not filepath . startswith ( skinspath ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return <EOL> if os . path . isfile ( filepath ) : <EOL> return os . path . basename ( filepath ) <EOL> else : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return <EOL> def get_current_config ( filepath ) : <EOL> """<STR_LIT>""" <EOL> filepath = os . path . normpath ( filepath ) <EOL> skinspath = skins_path ( ) <EOL> if not skinspath or not filepath . startswith ( skinspath ) : <EOL> _log ( "<STR_LIT>" , "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return <EOL> if os . path . isfile ( filepath ) : filepath = os . path . dirname ( filepath ) <EOL> return os . path . relpath ( filepath , skinspath ) <EOL> def get_resources_path ( filepath ) : <EOL> """<STR_LIT>""" <EOL> rfp = get_root_config_path ( filepath ) <EOL> if not rfp : <EOL> return <EOL> _log ( "<STR_LIT>" , os . path . join ( rfp , "<STR_LIT>" ) + "<STR_LIT:\\>" ) <EOL> return os . path . join ( rfp , "<STR_LIT>" ) + "<STR_LIT:\\>" <EOL> def replace_variables ( string , filepath ) : <EOL> """<STR_LIT>""" <EOL> variables = { "<STR_LIT>" : lambda : get_current_file ( filepath ) , <EOL> "<STR_LIT>" : lambda : get_current_path ( filepath ) , <EOL> "<STR_LIT>" : lambda : get_root_config_path ( filepath ) , <EOL> "<STR_LIT>" : lambda : get_current_config ( filepath ) , <EOL> "<STR_LIT>" : lambda : get_resources_path ( filepath ) , <EOL> "<STR_LIT>" : lambda : skins_path ( ) , <EOL> "<STR_LIT>" : lambda : settings_path ( ) , <EOL> "<STR_LIT>" : lambda : program_path ( ) , <EOL> "<STR_LIT>" : lambda : program_drive ( ) , <EOL> "<STR_LIT>" : lambda : addons_path ( ) , <EOL> "<STR_LIT>" : lambda : plugins_path ( ) } <EOL> pattern = re . compile ( "<STR_LIT>" + "<STR_LIT:|>" . join ( variables . keys ( ) ) ) <EOL> repl = pattern . sub ( lambda x : variables [ x . group ( ) . upper ( ) ] ( ) , <EOL> string ) <EOL> repl = os . path . expandvars ( repl ) <EOL> return repl <EOL> def make_path ( string , filepath ) : <EOL> """<STR_LIT>""" <EOL> if not string : return None <EOL> repl = replace_variables ( string , filepath ) <EOL> norm = os . path . normpath ( repl ) <EOL> if not os . path . isabs ( norm ) : <EOL> curpath = get_current_path ( filepath ) <EOL> abso = norm <EOL> if curpath : <EOL> abso = os . path . join ( curpath , norm ) <EOL> else : <EOL> abso = os . path . join ( os . path . dirname ( filepath ) , norm ) <EOL> if os . path . exists ( abso ) : <EOL> return abso <EOL> abso = os . path . join ( skins_path ( ) , norm ) <EOL> if os . path . exists ( abso ) : <EOL> return abso <EOL> else : <EOL> if os . path . exists ( norm ) : <EOL> return norm <EOL> if os . path . exists ( os . path . dirname ( norm ) ) : <EOL> return os . path . dirname ( norm ) <EOL> return <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> log = settings . get ( "<STR_LIT>" , False ) <EOL> _program_path = get_program_path ( ) <EOL> _program_drive = get_program_drive ( ) <EOL> _settings_path = get_settings_path ( ) <EOL> _skins_path = get_skins_path ( ) <EOL> _plugins_path = get_plugins_path ( ) <EOL> _addons_path = get_addons_path ( ) <EOL> if log : <EOL> print ( "<STR_LIT>" + program_path ( ) + <EOL> "<STR_LIT>" + program_drive ( ) + <EOL> "<STR_LIT>" + settings_path ( ) + <EOL> "<STR_LIT>" + skins_path ( ) + <EOL> "<STR_LIT>" + plugins_path ( ) + <EOL> "<STR_LIT>" + addons_path ( ) ) </s>
