def whereis_user_resources( self, context = None ): """ """ context = self._find_context( context ) fallback_to_POSIX = \ context.get_with_default( "Pythonic" ) \ or context.get_with_default( "XDG_standard" ) if fallback_to_POSIX: return POSIXStandardPath.whereis_user_resources( self, context ) base_path, specific_path = \ self._choose_user_path_parts( context ) if base_path: base_path_trunc = \ StandardPath._truncate_framework_path( base_path ) if base_path == base_path_trunc: return POSIXStandardPath.whereis_user_resources( self, context ) base_path = base_path_trunc else: base_path = POSIXStandardPath._whereis_user_home( ) base_path = _join_path( base_path, "Application Support" ) if specific_path: return _join_path( base_path, specific_path ) return base_path
def whereis_common_config( self, context = None ): """ """ context = self._find_context( context ) pythonic = context.get_with_default( "Pythonic" ) if pythonic and context.get_with_default( "strictly_Pythonic" ): return _whereis_common_Python_package( context ) base_path, specific_path = \ self._choose_common_path_parts( context ) if (None is base_path) and pythonic: base_path = context.get_with_default( "Python_prefix_path" ) if None is base_path: # TEMP HACK: Satisfy '__str__'. Not an acutal Windows convention. # TODO: Need to raise exception if software name is not supplied. # And, need to think about how to handle '__str__' # representation of objects in this case. base_path = \ _join_path( StandardPath._whereis_common_installation( context ), "Common Files" ) else: base_path = _join_path( base_path, "Config" ) if specific_path: return _join_path( base_path, specific_path ) return base_path
def whereis_common_resources( self, context = None ): """ """ context = self._find_context( context ) pythonic = context.get_with_default( "Pythonic" ) if pythonic: return POSIXStandardPath.whereis_common_resources( self, context ) base_path, specific_path = \ self._choose_common_path_parts( context ) if base_path: base_path_trunc = \ StandardPath._truncate_framework_path( base_path ) if base_path == base_path_trunc: return POSIXStandardPath.whereis_common_resources( self, context ) base_path = base_path_trunc if base_path.startswith( "/System" ): base_path = "/Library" else: base_path = "/Library" base_path = _join_path( base_path, "Application Support" ) if specific_path: return _join_path( base_path, specific_path ) return base_path
def whereis_saved_data( self, context = None ): """ """ context = self._find_context( context ) base_path, specific_path = \ self._choose_user_path_parts( context ) if not base_path: base_path = POSIXStandardPath._whereis_user_home( ) base_path = _join_path( base_path, "Documents" ) if specific_path: return _join_path( base_path, specific_path ) return base_path
def whereis_temp( self, context = None ): """ """ context = self._find_context( context ) base_path, specific_path = \ self._choose_common_path_parts( context ) if base_path and context.get_with_default( "temp_on_base_path" ): base_path = _join_path( base_path, "Temp" ) else: base_path = None if None is base_path: base_path = _envvars.get( "TMP", _envvars.get( "TEMP" ) ) if None is base_path: context.raise_UndeterminedPathError( _TD_( "temporary storage" ) ) if specific_path: return _join_path( base_path, specific_path ) return base_path
def _whereis_user_Python_package( context ): """ Returns the path to a particular Python package relative to the user's site packages directory specified by :pep:`370` and provided by the :py:mod:`site <CPython3:site>` module. """ python_package_name = context.get_with_default( "Python_package_name" ) if None is python_package_name: context.raise_UndeterminedPathError( _TD_( "Python package" ), specify_software = True ) return _join_path( site.USER_SITE, python_package_name )
def _whereis_common_Python_package( context ): """ Returns the path to a particular Python package relative to the primary site packages directory for a given Python installation and version. """ python_package_name = context.get_with_default( "Python_package_name" ) if None is python_package_name: context.raise_UndeterminedPathError( _TD_( "Python package" ), specify_software = True ) return _join_path( context.get_with_default( "Python_prefix_path" ), "Lib", "site-packages", python_package_name )
def _calculate_path( self ): """ """ error_on_none = \ self.get_with_default( "error_on_none" ) software_name = \ self.get_with_default( "software_name" ) software_provider_name = \ self.get_with_default( "software_provider_name" ) software_version = \ self.get_with_default( "software_version" ) if not software_name: if error_on_none: raise UndeterminedPathError( _TD_( "Missing software name for calculated path." ) ) else: return None return _join_path( *filter( None, [ software_provider_name, software_name, software_version ] ) )
# Note: If something goes wrong here, then just let the exception propagate. if 3 == python_version.major: if 2 <= python_version.minor: from configparser import ( # pylint: disable=F0401 ConfigParser as _ConfigParser, ) else: from configparser import ( # pylint: disable=F0401 SafeConfigParser as _ConfigParser, ) else: from ConfigParser import ( # pylint: disable=F0401 SafeConfigParser as _ConfigParser, ) _path_to_config = _join_path( __path__[ 0 ], "version.cfg" ) _vinfo_CFG = _ConfigParser( ) if _path_to_config not in _vinfo_CFG.read( _path_to_config ): raise IOError( "Configuration file '{0}' expected but not found.".format( _path_to_config ) ) _vinfo_release_type = _vinfo_CFG.get( "control", "release_type" ) assert _vinfo_release_type in [ "bugfix", "candidate", "development" ] _vinfo_numbers_DICT = dict( _vinfo_CFG.items( "numbers" ) ) if "bugfix" == _vinfo_release_type: # Stable Bugfix Release __version__ = \ "{major}.{minor}.{bugfix}".format( **_vinfo_numbers_DICT ) elif "candidate" == _vinfo_release_type: # Release Candidate