[docs]classAppConfig(YamlConfig):"""Application specific configuration access and parsing. Since much of the application centers around configuration of what to persist, this class does more heavy lifting than most configuraetion like classes. """ROOT='discover'OBJECTS_PATH=f'{ROOT}.objects'PROFILES_PATH=f'{ROOT}.profiles'EMPTY_DIR_PATH=f'{ROOT}.empty_dirs'OBJECTS_PROFILE_PATH=f'{PROFILES_PATH}.{{}}.objects'EMPTY_DIR_PROFILE_PATH=f'{PROFILES_PATH}.{{}}.empty_dirs'
[docs]defget_profiles(self,profile_overide:Union[str,List[str]]=None):ifprofile_overideisNone:profiles=self._default_profileselse:ifisinstance(profile_overide,str):profiles=self.split_profiles(profile_overide)else:profiles=profile_overideifprofilesisNone:profiles=self._find_profilesprofiles=list(profiles)# protect user errorif'default'notinprofiles:profiles=['default']+list(profiles)if'nodefault'inprofiles:profiles.pop(profiles.index('default'))profiles.pop(profiles.index('nodefault'))returnprofiles
def_iterate_objects(self,profile):ifprofile=='default':path=self.OBJECTS_PATHelse:path=self.OBJECTS_PROFILE_PATH.format(profile)opts=self.get_options(path)ifoptsisNoneandprofile=='default':opts=()ifoptsisNone:logger.warning(f'no such profile for objects: {profile} for path {path}'+'--maybe entries exist in other profiles')opts=()returnmap(lambdax:x.strip(),opts)
[docs]defget_empty_dirs(self,profiles):paths=[]forprofileinprofiles:ifprofile=='default':path=self.EMPTY_DIR_PATHelse:path=self.EMPTY_DIR_PROFILE_PATH.format(profile)opts=self.get_options(path)ifoptsisNone:## warnings for missing empty directory entries is worth it# logger.warning(# f'no such profile for objects: {profile} for path {path}' +# '--maybe entries exist in other profiles')passelse:paths.extend(opts)returnmap(lambdax:Path(x).expanduser().absolute(),paths)
def_get_path(self,name):path=self.get_option(name)ifpathisNone:raiseValueError('no path defined for option: {name}')returnPath(path).expanduser().absolute()@propertydefdist_dir(self):returnself._get_path(f'{self.ROOT}.local.dist_dir')@dist_dir.setterdefdist_dir(self,dist_dir):ifself.default_varsisNone:self.default_vars={}self.default_vars[f'{self.ROOT}.local.dist_dir']=dist_dir@propertydefwheel_dir_name(self):returnself._get_path(f'{self.ROOT}.local.wheels_dir')@propertydefbootstrap_script_file(self):returnPath(self.dist_dir,'bootstrap.sh')