def generate_project(args, files): try: if args.name != '.': if not os.path.exists(files['main_dir']): os.mkdir(files['main_dir']) ParserHelpers.generate_all(files) else: print("Directory already exists.") return True else: # Initialising project in existing directory project_parent_dir = Utility.find_project(os.getcwd()) if project_parent_dir is None: # Not an afctl project. Generate all directories. ParserHelpers.generate_all(files) else: # Since its an afctl project. Just populate the config files. ParserHelpers.generate_config_file(files) if args.v != None: Utility.update_config(files['project_name'], {'global': { 'airflow_version': args.v }}) return False except Exception as e: raise AfctlParserException(e)
def validate_project(cls): try: project_name = None project_path = None pwd = os.getcwd() # If any parent of pwd contains .afctl_project. If so then it should be the project. project = Utility.find_project(pwd) if project is None: # Could not find .afctl_project cls.parser.error( colored("{} is not an afctl project.".format(pwd), 'red')) else: # Check is the dir containing .afctl_project has a config file project_name = project[0] project_path = project[1] if not os.path.exists(Utility.project_config(project_name)): cls.parser.error( colored( "Config file does not exists for {}".format( project_name), 'red')) return project_name, project_path except Exception as e: raise AfctlParserException(e)
def test_find_project(self, create_project): path = '/tmp/one/two/three' project = Utility.find_project(path) assert project[0] == 'two' assert project[1] == '/tmp/one/two'