Changeset View
Changeset View
Standalone View
Standalone View
bin/EmergeConfig.py
Show All 17 Lines | |||||
18 | 18 | | |||
19 | import configparser | 19 | import configparser | ||
20 | import os | 20 | import os | ||
21 | import platform | 21 | import platform | ||
22 | import re | 22 | import re | ||
23 | 23 | | |||
24 | emergeSettings = None | 24 | emergeSettings = None | ||
25 | 25 | | |||
26 | | ||||
27 | class EmergeStandardDirs( object ): | 26 | class EmergeStandardDirs( object ): | ||
28 | __pathCache = dict( ) | 27 | __pathCache = dict( ) | ||
29 | __noShortPathCache = dict( ) | 28 | __noShortPathCache = dict( ) | ||
30 | _allowShortpaths = True | 29 | _allowShortpaths = True | ||
31 | _SUBST = None | 30 | _SUBST = None | ||
32 | 31 | | |||
33 | @staticmethod | 32 | @staticmethod | ||
34 | def _deSubstPath(path): | 33 | def _deSubstPath(path): | ||
Show All 22 Lines | |||||
57 | def _pathCache( ): | 56 | def _pathCache( ): | ||
58 | if EmergeStandardDirs._allowShortpaths: | 57 | if EmergeStandardDirs._allowShortpaths: | ||
59 | return EmergeStandardDirs.__pathCache | 58 | return EmergeStandardDirs.__pathCache | ||
60 | else: | 59 | else: | ||
61 | return EmergeStandardDirs.__noShortPathCache | 60 | return EmergeStandardDirs.__noShortPathCache | ||
62 | 61 | | |||
63 | @staticmethod | 62 | @staticmethod | ||
64 | def allowShortpaths( allowd ): | 63 | def allowShortpaths( allowd ): | ||
64 | old = EmergeStandardDirs._allowShortpaths | ||||
65 | EmergeStandardDirs._allowShortpaths = allowd | 65 | EmergeStandardDirs._allowShortpaths = allowd | ||
66 | return old | ||||
66 | 67 | | |||
67 | @staticmethod | 68 | @staticmethod | ||
68 | def downloadDir( ): | 69 | def downloadDir( ): | ||
69 | """ location of directory where fetched files are stored """ | 70 | """ location of directory where fetched files are stored """ | ||
70 | if not "DOWNLOADDIR" in EmergeStandardDirs._pathCache( ): | 71 | if not "DOWNLOADDIR" in EmergeStandardDirs._pathCache( ): | ||
71 | if EmergeStandardDirs._allowShortpaths and emergeSettings.getboolean( "ShortPath", "EMERGE_USE_SHORT_PATH", | 72 | if EmergeStandardDirs._allowShortpaths and emergeSettings.getboolean( "ShortPath", "EMERGE_USE_SHORT_PATH", | ||
72 | False ): | 73 | False ): | ||
73 | EmergeStandardDirs._pathCache( )[ "DOWNLOADDIR" ] = EmergeStandardDirs.nomalizePath( | 74 | EmergeStandardDirs._pathCache( )[ "DOWNLOADDIR" ] = EmergeStandardDirs.nomalizePath( | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 143 | def etcPortageDir( ): | |||
144 | return os.path.join( EmergeStandardDirs.etcDir( ), "portage" ) | 145 | return os.path.join( EmergeStandardDirs.etcDir( ), "portage" ) | ||
145 | 146 | | |||
146 | 147 | | |||
147 | class EmergeConfig( object ): | 148 | class EmergeConfig( object ): | ||
148 | variablePatern = re.compile( "\$\{[A-Za-z0-9_]*\}", re.IGNORECASE ) | 149 | variablePatern = re.compile( "\$\{[A-Za-z0-9_]*\}", re.IGNORECASE ) | ||
149 | 150 | | |||
150 | def __init__( self ): | 151 | def __init__( self ): | ||
151 | self._config = None | 152 | self._config = None | ||
152 | EmergeStandardDirs.allowShortpaths( False ) | 153 | with TemporaryUseShortpath(False): | ||
153 | self.iniPath = os.path.join( EmergeStandardDirs.etcDir( ), "kdesettings.ini" ) | 154 | self.iniPath = os.path.join( EmergeStandardDirs.etcDir( ), "kdesettings.ini" ) | ||
154 | EmergeStandardDirs.allowShortpaths( True ) | | |||
155 | self._alias = dict( ) | 155 | self._alias = dict( ) | ||
156 | self._readSettings( ) | 156 | self._readSettings( ) | ||
157 | 157 | | |||
158 | self.setDefault( "General", "DUMP_SETTINGS", "False" ) | 158 | self.setDefault( "General", "DUMP_SETTINGS", "False" ) | ||
159 | self.addAlias( "EmergeDebug", "Verbose", "General", "EMERGE_VERBOSE" ) | 159 | self.addAlias( "EmergeDebug", "Verbose", "General", "EMERGE_VERBOSE" ) | ||
160 | self.addAlias( "EmergeDebug", "MeasureTime", "General", "EMERGE_MEASURE_TIME" ) | 160 | self.addAlias( "EmergeDebug", "MeasureTime", "General", "EMERGE_MEASURE_TIME" ) | ||
161 | self.addAlias( "General", "UseHardlinks", "General", "EMERGE_USE_SYMLINKS" ) | 161 | self.addAlias( "General", "UseHardlinks", "General", "EMERGE_USE_SYMLINKS" ) | ||
162 | self.addAlias( "General", "WorkOffline", "General", "EMERGE_OFFLINE" ) | 162 | self.addAlias( "General", "WorkOffline", "General", "EMERGE_OFFLINE" ) | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 242 | if not ( group, key ) in self: | |||
243 | self.set( group, key, value ) | 243 | self.set( group, key, value ) | ||
244 | 244 | | |||
245 | 245 | | |||
246 | def dump( self ): | 246 | def dump( self ): | ||
247 | with open( self.iniPath + ".dump", 'wt+' ) as configfile: | 247 | with open( self.iniPath + ".dump", 'wt+' ) as configfile: | ||
248 | self._config.write( configfile ) | 248 | self._config.write( configfile ) | ||
249 | 249 | | |||
250 | 250 | | |||
251 | class TemporaryUseShortpath(object): | ||||
252 | """Context handler for temporarily different shortpath setting""" | ||||
253 | def __init__(self, enabled): | ||||
254 | self.prev = EmergeStandardDirs.allowShortpaths(enabled) | ||||
255 | | ||||
256 | def __enter__(self): | ||||
257 | return self | ||||
258 | | ||||
259 | def __exit__(self, exc_type, exc_value, trback): | ||||
260 | EmergeStandardDirs.allowShortpaths(self.prev) | ||||
261 | | ||||
262 | | ||||
263 | | ||||
251 | emergeSettings = EmergeConfig( ) | 264 | emergeSettings = EmergeConfig( ) | ||
252 | 265 | | |||
253 | 266 | | |||
267 | | ||||
268 | | ||||
269 | | ||||
270 | | ||||
271 | | ||||
272 | | ||||
273 | | ||||
274 | |