""".. _watchdog: https://github.com/gorakhargosh/watchdogWatcher handlers================This component contains `watchdog`_ handlers to use to watch a projectsources."""importos
[docs]classBaseHandler(object):""" Base class for handlers. Assume children inheriting this class have a ``settings`` attribute with a valid ``SettingsModel`` instance as value. """
[docs]defget_relative_template_path(self,path):""" Retrieve relative path from templates directory. Arguments: path (str): Path to a template file. Returns: string: Relative path either from templates directory or untouched if file does not belong to template directory. """ifpath.startswith(self.settings.TEMPLATES_DIR):returnos.path.relpath(path,self.settings.TEMPLATES_DIR)returnpath
[docs]defget_relative_asset_path(self,path):""" Retrieve relative path from assets directory. Arguments: path (str): Path to an asset file. Returns: string: Relative path either from assets directory or untouched if file does not belong to assets directory. """ifpath.startswith(self.settings.SOURCES_DIR):returnos.path.relpath(path,self.settings.SOURCES_DIR)returnpath
[docs]defget_relative_data_path(self,path):""" Retrieve relative path from datas directory. Arguments: path (str): Path to a data file. Returns: string: Relative path either from datas directory or untouched if file does not belong to datas directory. """ifpath.startswith(self.settings.DATAS_DIR):returnos.path.relpath(path,self.settings.DATAS_DIR)returnpath