def _register_packs(self): """ Register all the packs inside the fixtures directory. """ registrar = ResourceRegistrar(use_pack_cache=False) registrar.register_packs(base_dirs=get_packs_base_paths())
from st2common.constants.pack import DEFAULT_PACK_NAME from st2common.content.loader import ContentPackLoader from st2common.content.loader import MetaLoader from st2common.bootstrap.base import ResourceRegistrar import st2common.content.utils as content_utils from st2common.models.api.action import ActionAPI from st2common.models.api.sensor import SensorTypeAPI from st2common.models.api.rule import RuleAPI from st2common.models.db import db_setup from st2common.models.db import db_teardown from st2common.models.system.common import ResourceReference from st2common.persistence.rule import Rule from st2common.persistence.sensor import SensorType from st2common.persistence.action import Action registrar = ResourceRegistrar() registrar.ALLOWED_EXTENSIONS = ['.yaml', '.yml', '.json'] meta_loader = MetaLoader() API_MODELS_ARTIFACT_TYPES = { 'actions': ActionAPI, 'sensors': SensorTypeAPI, 'rules': RuleAPI } API_MODELS_PERSISTENT_MODELS = { Action: ActionAPI, SensorType: SensorTypeAPI, Rule: RuleAPI }
def setup_virtualenvs(recreate_virtualenvs=False): """ Setup Python virtual environments for all the registered or the provided pack. """ LOG.info("=========================================================") LOG.info("########### Setting up virtual environments #############") LOG.info("=========================================================") pack_dir = cfg.CONF.register.pack fail_on_failure = not cfg.CONF.register.no_fail_on_failure registrar = ResourceRegistrar() if pack_dir: pack_name = os.path.basename(pack_dir) pack_names = [pack_name] # 1. Register pack registrar.register_pack(pack_name=pack_name, pack_dir=pack_dir) else: # 1. Register pack base_dirs = content_utils.get_packs_base_paths() registrar.register_packs(base_dirs=base_dirs) # 2. Retrieve available packs (aka packs which have been registered) pack_names = registrar.get_registered_packs() if recreate_virtualenvs: """ update = False: this is more than an update of an existing virtualenv the virtualenv itself will be removed & recreated this is i.e. useful for updates to a newer Python release """ update = False else: """ update = True: only dependencies inside the virtualenv will be updated """ update = True setup_count = 0 for pack_name in pack_names: try: setup_pack_virtualenv(pack_name=pack_name, update=update, logger=LOG) except Exception as e: exc_info = not fail_on_failure LOG.warning( 'Failed to setup virtualenv for pack "%s": %s', pack_name, e, exc_info=exc_info, ) if fail_on_failure: raise e else: setup_count += 1 LOG.info("Setup virtualenv for %s pack(s)." % (setup_count))