def handle(self, *args, **options): """Register processes.""" schemas = options.get('schemas') force = options.get('force') paths = options.get('path') verbosity = int(options.get('verbosity')) if not isinstance(paths, list): raise ValueError("Argument paths must be of type list") if schemas is not None and not isinstance(schemas, list): raise ValueError("Argument schemas must be of type list or None") users = get_user_model().objects.filter( is_superuser=True).order_by('date_joined') if not users.exists(): self.stderr.write("Admin does not exist: create a superuser") exit(1) user_admin = users.first() processes_paths = paths[:] descriptors_paths = paths[:] if not paths: for finder in get_finders(): processes_paths.extend(finder.find_processes()) descriptors_paths.extend(finder.find_descriptors()) process_schemas = [] for proc_path in processes_paths: process_schemas.extend( self.find_schemas(proc_path, filters=schemas, schema_type='process', verbosity=verbosity)) self.register_processes(process_schemas, user_admin, force, verbosity=verbosity) descriptor_schemas = [] for desc_path in descriptors_paths: descriptor_schemas.extend( self.find_schemas(desc_path, filters=schemas, schema_type='descriptor', verbosity=verbosity)) self.register_descriptors(descriptor_schemas, user_admin, force, verbosity=verbosity) if verbosity > 0: self.stdout.write("Running executor post-registration hook...") manager.get_executor().post_register_hook(verbosity=verbosity)
def handle(self, *args, **options): """Register processes.""" force = options.get("force") retire = options.get("retire") verbosity = int(options.get("verbosity")) users = (get_user_model().objects.filter( is_superuser=True).order_by("date_joined")) if not users.exists(): self.stderr.write("Admin does not exist: create a superuser") exit(1) process_paths, descriptor_paths = [], [] process_schemas, descriptor_schemas = [], [] for finder in get_finders(): process_paths.extend(finder.find_processes()) descriptor_paths.extend(finder.find_descriptors()) for proc_path in process_paths: process_schemas.extend( self.find_schemas(proc_path, schema_type=SCHEMA_TYPE_PROCESS, verbosity=verbosity)) for desc_path in descriptor_paths: descriptor_schemas.extend( self.find_schemas(desc_path, schema_type=SCHEMA_TYPE_DESCRIPTOR, verbosity=verbosity)) user_admin = users.first() self.register_descriptors(descriptor_schemas, user_admin, force, verbosity=verbosity) # NOTE: Descriptor schemas must be registered first, so # processes can validate 'entity_descriptor_schema' field. self.register_processes(process_schemas, user_admin, force, verbosity=verbosity) if retire: self.retire(process_schemas) if verbosity > 0: self.stdout.write("Running executor post-registration hook...") manager.get_executor().post_register_hook(verbosity=verbosity)
def handle(self, *args, **options): """Register processes.""" force = options.get('force') retire = options.get('retire') verbosity = int(options.get('verbosity')) users = get_user_model().objects.filter( is_superuser=True).order_by('date_joined') if not users.exists(): self.stderr.write("Admin does not exist: create a superuser") exit(1) process_paths, descriptor_paths = [], [] process_schemas, descriptor_schemas = [], [] for finder in get_finders(): process_paths.extend(finder.find_processes()) descriptor_paths.extend(finder.find_descriptors()) for proc_path in process_paths: process_schemas.extend( self.find_schemas(proc_path, schema_type='process', verbosity=verbosity)) for desc_path in descriptor_paths: descriptor_schemas.extend( self.find_schemas(desc_path, schema_type='descriptor', verbosity=verbosity)) user_admin = users.first() self.register_processes(process_schemas, user_admin, force, verbosity=verbosity) self.register_descriptors(descriptor_schemas, user_admin, force, verbosity=verbosity) if retire: self.retire(process_schemas) if verbosity > 0: self.stdout.write("Running executor post-registration hook...") manager.get_executor().post_register_hook(verbosity=verbosity)
def handle(self, *args, **options): """Register processes.""" schemas = options.get('schemas') force = options.get('force') paths = options.get('path') verbosity = int(options.get('verbosity')) if not isinstance(paths, list): raise ValueError("Argument paths must be of type list") if schemas is not None and not isinstance(schemas, list): raise ValueError("Argument schemas must be of type list or None") users = get_user_model().objects.filter(is_superuser=True).order_by('date_joined') if not users.exists(): self.stderr.write("Admin does not exist: create a superuser") exit(1) user_admin = users.first() processes_paths = paths[:] descriptors_paths = paths[:] if len(paths) == 0: for finder in get_finders(): processes_paths.extend(finder.find_processes()) descriptors_paths.extend(finder.find_descriptors()) process_schemas = [] for proc_path in processes_paths: process_schemas.extend( self.find_schemas(proc_path, filters=schemas, schema_type='process', verbosity=verbosity)) self.register_processes(process_schemas, user_admin, force, verbosity=verbosity) descriptor_schemas = [] for desc_path in descriptors_paths: descriptor_schemas.extend( self.find_schemas(desc_path, filters=schemas, schema_type='descriptor', verbosity=verbosity)) self.register_descriptors(descriptor_schemas, user_admin, force, verbosity=verbosity)
def resolve_process_tags(self, files): """Resolve process tags. :param files: List of changed process files :return: Test tags that need to be run """ processes_paths = [] for finder in get_finders(): processes_paths.extend(finder.find_processes()) process_schemas = [] for proc_path in processes_paths: process_schemas.extend(self.find_schemas(proc_path)) dependencies = self.find_dependencies(process_schemas) processes = set() for filename in files: with open(filename, 'r') as process_file: data = yaml.load(process_file) for process in data: # Add all process slugs. processes.add(process['slug']) # Add all dependencies. dep_processes = set() while processes: process = processes.pop() if process in dep_processes: continue dep_processes.add(process) processes.update(dependencies.get(process, set())) tags = set() for process in dep_processes: tags.add(generate_process_tag(process)) return tags
def handle(self, *args, **options): """Register processes.""" force = options.get('force') retire = options.get('retire') verbosity = int(options.get('verbosity')) users = get_user_model().objects.filter(is_superuser=True).order_by('date_joined') if not users.exists(): self.stderr.write("Admin does not exist: create a superuser") exit(1) process_paths, descriptor_paths = [], [] process_schemas, descriptor_schemas = [], [] for finder in get_finders(): process_paths.extend(finder.find_processes()) descriptor_paths.extend(finder.find_descriptors()) for proc_path in process_paths: process_schemas.extend( self.find_schemas(proc_path, schema_type=SCHEMA_TYPE_PROCESS, verbosity=verbosity)) for desc_path in descriptor_paths: descriptor_schemas.extend( self.find_schemas(desc_path, schema_type=SCHEMA_TYPE_DESCRIPTOR, verbosity=verbosity)) user_admin = users.first() self.register_descriptors(descriptor_schemas, user_admin, force, verbosity=verbosity) # NOTE: Descriptor schemas must be registered first, so # processes can validate 'entity_descriptor_schema' field. self.register_processes(process_schemas, user_admin, force, verbosity=verbosity) if retire: self.retire(process_schemas) if verbosity > 0: self.stdout.write("Running executor post-registration hook...") manager.get_executor().post_register_hook(verbosity=verbosity)
def resolve_process_tags(self, files): """Resolve process tags. :param files: List of changed process files :return: Test tags that need to be run """ processes_paths = [] for finder in get_finders(): processes_paths.extend(finder.find_processes()) process_schemas = [] for proc_path in processes_paths: process_schemas.extend(self.find_schemas(proc_path)) # Switch to source branch and get all the schemas from there as well, since some schemas # might have been removed. with self.git_branch(self.only_changes_to): for proc_path in processes_paths: process_schemas.extend(self.find_schemas(proc_path)) dependencies = self.find_dependencies(process_schemas) processes = set() def load_process_slugs(filename): """Add all process slugs from specified file.""" with open(filename, "r") as process_file: data = yaml.load(process_file, Loader=yaml.FullLoader) for process in data: # Add all process slugs. processes.add(process["slug"]) for filename in files: try: load_process_slugs(filename) except FileNotFoundError: # File was removed, so we will handle it below when we check the original branch. pass # Switch to source branch and check modified files there as well. with self.git_branch(self.only_changes_to): for filename in files: try: load_process_slugs(filename) except FileNotFoundError: # File was added, so it has already been handled. pass # Add all dependencies. dep_processes = set() while processes: process = processes.pop() if process in dep_processes: continue dep_processes.add(process) processes.update(dependencies.get(process, set())) tags = set() for process in dep_processes: tags.add(generate_process_tag(process)) return tags
def resolve_process_tags(self, files): """Resolve process tags. :param files: List of changed process files :return: Test tags that need to be run """ processes_paths = [] for finder in get_finders(): processes_paths.extend(finder.find_processes()) process_schemas = [] for proc_path in processes_paths: process_schemas.extend(self.find_schemas(proc_path)) # Switch to source branch and get all the schemas from there as well, since some schemas # might have been removed. with self.git_branch(self.only_changes_to): for proc_path in processes_paths: process_schemas.extend(self.find_schemas(proc_path)) dependencies = self.find_dependencies(process_schemas) processes = set() def load_process_slugs(filename): """Add all process slugs from specified file.""" with open(filename, 'r') as process_file: data = yaml.load(process_file) for process in data: # Add all process slugs. processes.add(process['slug']) for filename in files: try: load_process_slugs(filename) except FileNotFoundError: # File was removed, so we will handle it below when we check the original branch. pass # Switch to source branch and check modified files there as well. with self.git_branch(self.only_changes_to): for filename in files: try: load_process_slugs(filename) except FileNotFoundError: # File was added, so it has already been handled. pass # Add all dependencies. dep_processes = set() while processes: process = processes.pop() if process in dep_processes: continue dep_processes.add(process) processes.update(dependencies.get(process, set())) tags = set() for process in dep_processes: tags.add(generate_process_tag(process)) return tags