def cli(args): model_name = args.model_name basedir = find_repository_basedir('.') basedir = os.path.join(basedir, 'models') if not os.path.isdir(basedir): os.mkdir(basedir) model_path = os.path.join(basedir, model_name.lower() + '.py') if os.path.exists(model_path): raise CommandError("File already exists: {}".format(model_path)) topic_usage = 'None # TODO: import appropriate topic and set it here' topic_import = '' if args.topic: topic_usage = args.topic topic_import = 'from leapp.topics import {}\n'.format(args.topic) with open(model_path, 'w') as f: f.write('''from leapp.models import Model, fields {topic_import} class {model_name}(Model): topic = {topic_usage} '''.format(model_name=make_class_name(model_name), topic_import=topic_import, topic_usage=topic_usage)) sys.stdout.write("New model {} has been created in {}\n".format(make_class_name(model_name), os.path.realpath(model_path)))
def cli(args): actor_name = args.actor_name basedir = find_repository_basedir('.') tag_imports = '' model_imports = '' if args.tag: tag_imports = '\nfrom leapp.tags import {}'.format(', '.join( tuple(map(lambda x: x.split('.')[0], args.tag)))) if args.consumes or args.produces: models = set((args.produces or []) + (args.consumes or [])) model_imports = '\nfrom leapp.models import {}'.format( ', '.join(models)) tags_content = '({})'.format(as_quoted_tuple(args.tag)) consumes_content = '({})'.format(as_quoted_tuple(args.consumes)) produces_content = '({})'.format(as_quoted_tuple(args.produces)) actors_dir = os.path.join(basedir, 'actors') if not os.path.isdir(actors_dir): os.mkdir(actors_dir) actor_dir = os.path.join(actors_dir, actor_name.lower()) if not os.path.isdir(actor_dir): os.mkdir(actor_dir) actor_test_dir = os.path.join(actor_dir, 'tests') if not os.path.isdir(actor_test_dir): os.mkdir(actor_test_dir) actor_path = os.path.join(actor_dir, 'actor.py') if os.path.exists(actor_path): raise CommandError("File already exists: {}".format(actor_path)) with open(actor_path, 'w') as f: f.write('''from leapp.actors import Actor{model_imports}{tag_imports} class {actor_class}(Actor): name = '{actor_name}' description = 'No description has been provided for the {actor_name} actor.' consumes = {consumes_content} produces = {produces_content} tags = {tags_content} def process(self): pass '''.format(actor_class=make_class_name(actor_name), actor_name=make_name(actor_name), tags_content=tags_content, produces_content=produces_content, consumes_content=consumes_content, model_imports=model_imports, tag_imports=tag_imports)) sys.stdout.write("New actor {} has been created at {}\n".format( make_class_name(actor_name), os.path.realpath(actor_path))) return os.path.dirname(os.path.realpath(actor_path))
def cli(args): topic_name = args.topic_name basedir = find_repository_basedir('.') basedir = os.path.join(basedir, 'topics') if not os.path.isdir(basedir): os.mkdir(basedir) topic_path = os.path.join(basedir, topic_name.lower() + '.py') if os.path.exists(topic_path): raise CommandError("File already exists: {}".format(topic_path)) topic_path = os.path.join(basedir, topic_name.lower() + '.py') topic_class_name = make_class_name(topic_name) if not topic_class_name.endswith('Topic'): topic_class_name += 'Topic' with open(topic_path, 'w') as f: f.write('''from leapp.topics import Topic class {topic_name}(Topic): name = '{topic}' '''.format(topic_name=topic_class_name, topic=make_name(topic_name))) sys.stdout.write("New topic {} has been created in {}\n".format(topic_class_name, os.path.realpath(topic_path)))
def cli(args): basedir = os.path.join(find_repository_basedir('.'), 'tags') if not os.path.isdir(basedir): os.mkdir(basedir) tag_path = os.path.join(basedir, args.tag_name.lower() + '.py') if os.path.exists(tag_path): raise CommandError("File already exists: {}".format(tag_path)) with open(tag_path, 'w') as f: f.write('''from leapp.tags import Tag class {tag_name}Tag(Tag): name = '{tag}' '''.format(tag_name=make_class_name(args.tag_name), tag=make_name(args.tag_name))) sys.stdout.write("New tag {} has been created in {}\n".format( make_class_name(args.tag_name), os.path.realpath(tag_path)))
def cli(args): class_name = args.class_name short_name = args.short_name name = args.name base_dir = find_repository_basedir('.') workflows_dir = os.path.join(base_dir, 'workflows') class_name = class_name or make_class_name(name) short_name = short_name or make_name(name) if not class_name.endswith('Workflow'): class_name += 'Workflow' check_call(['snactor', 'new-tag', class_name]) if not os.path.exists(workflows_dir): os.mkdir(workflows_dir) workflow_path = os.path.join(workflows_dir, make_name(name) + '.py') if not os.path.exists(workflow_path): with open(workflow_path, 'w') as f: f.write("""from leapp.workflows import Workflow from leapp.workflows.phases import Phase from leapp.workflows.flags import Flags from leapp.workflows.tagfilters import TagFilter from leapp.workflows.policies import Policies from leapp.tags import {workflow_class}Tag class {workflow_class}(Workflow): name = '{workflow_name}' tag = {workflow_class}Tag short_name = '{workflow_short_name}' description = '''No description has been provided for the {workflow_name} workflow.''' # Template for phase definition - The order in which the phase classes are defined # within the Workflow class represents the execution order # # class PhaseName(Phase): # name = 'phase_name' # filter = TagFilter(PhaseTag) # policies = Policies(Policies.Errors.FailPhase, # Policies.Retry.Phase) # flags = Flags() """.format(workflow_name=name, workflow_class=class_name, workflow_short_name=short_name)) sys.stdout.write("New workflow {} has been created in {}\n".format( class_name, os.path.realpath(workflow_path)))
def test_make_class_name(param): assert make_class_name(param[0]) == param[1]