def maintenance(period="daily"): """ Run all maintenance tasks which should be done daily - these are read from the template """ maintenance = None result = "NotImplementedError" template = settings.get_template() if template != "default": # Try import maintenance routine from template package = "applications.%s.%s.templates.%s" % \ (appname, settings.get_template_location(), template) name = "maintenance" try: maintenance = getattr(__import__(package, fromlist=[name]), name) except (ImportError, AttributeError): pass if maintenance is None: try: # Fallback to default maintenance routine from templates.default import maintenance except ImportError: pass if maintenance is not None: if period == "daily": result = maintenance.Daily()() db.commit() return result
def maintenance(period="daily"): """ Run all maintenance tasks which should be done daily - instantiates and calls the Daily() class defined in the template's maintenance.py file - if it exists - falls back to the default template's maintenancy.py """ maintenance = None result = "NotImplementedError" templates = settings.get_template() if templates != "default": # Try to import maintenance routine from template if not isinstance(templates, (tuple, list)): templates = (templates, ) for template in templates[::-1]: package = "templates.%s" % template name = "maintenance" try: maintenance = getattr(__import__(package, fromlist=[name]), name) except (ImportError, AttributeError): pass else: break if maintenance is None: try: # Fallback to default maintenance routine from templates.default import maintenance except ImportError: pass if maintenance is not None: if period == "daily": result = maintenance.Daily()() db.commit() return result
def maintenance(period="daily"): """ Run all maintenance tasks which should be done daily - these are read from the template """ maintenance = None result = "NotImplementedError" templates = settings.get_template() if templates != "default": # Try to import maintenance routine from template if not isinstance(templates, (tuple, list)): templates = (templates, ) for template in templates[::-1]: package = "applications.%s.modules.templates.%s" % (appname, template) name = "maintenance" try: maintenance = getattr(__import__(package, fromlist=[name]), name) except (ImportError, AttributeError): pass else: break if maintenance is None: try: # Fallback to default maintenance routine from templates.default import maintenance except ImportError: pass if maintenance is not None: if period == "daily": result = maintenance.Daily()() db.commit() return result