def main(self): self.envs = Environments() self.envs.load() if len(self.envs.items) > 0: options = ['load', 'create', 'delete', 'reset'] if Migration.get_migrations(): options = options + ['download migrations'] options = options + ['cancel'] EnvQuestions.introduction[0]['choices'] = options task_data = prompt(EnvQuestions.introduction) try: self.interface(task_data) except KeyboardInterrupt: print('\n') close_data = prompt(EnvQuestions.close) try: ValidationHelper.check_answers(close_data) action = close_data['close_action'] print(action) if action == 'back to main options': return self.main() else: sys.exit(1) except KeyboardInterrupt: sys.exit(1)
def main(self): print(self.env.ouput()) self.env.load_projects() choices = ['create project', 'link project to database'] if len(self.env.projects) > 0: choices = [ 'create project', 'project settings', 'link project to database' ] PjQuestions.introduction[0]['choices'] = choices + [module_options[0]] intro_data = prompt(PjQuestions.introduction) try: ValidationHelper.check_answers(intro_data) self.interface(intro_data) except KeyboardInterrupt: print('\n') close_data = prompt(PjQuestions.close) try: ValidationHelper.check_answers(close_data) action = close_data['close_action'] print(action) if action == 'back to environment options': return self.main() else: sys.exit(1) except KeyboardInterrupt: sys.exit(1)
def delete(self): delete_tasks = prompt(PjQuestions.delete) ValidationHelper.check_answers(delete_tasks) keep_db = delete_tasks['keep_db'] confirmation = delete_tasks['confirmation'] if confirmation: self.env.delete_project(project=self.pj, keep_db=keep_db) self.main()
def templatify(self): pj_data = self.env.get_project(self.pj.ref_name) print(pj_data) ValidationHelper.check_answers(pj_data) self.pj = Project(ref=pj_data['ref'], name=pj_data['name'], database=pj_data['database']) self.env.templatify_project(self.pj) self.main()
def link_project(self): databases = self.env.list_dbs() PjQuestions.link[0]['choices'] = databases link_data = prompt(PjQuestions.link) ValidationHelper.check_answers(link_data) self.env.link_project( project=Project(ref=link_data['install_ref'], name=link_data['install_name'], database=link_data['database_name'])) self.main()
def load(self): print(self.envs.get()) if len(self.envs.items) > 0: options = map(lambda d: d['ref'], self.envs.items) EnvQuestions.load[0]['choices'] = list(options) + [ module_options[0] ] load_data = prompt(EnvQuestions.load) ValidationHelper.check_answers(load_data) if load_data['env_ref'] == module_options[0]: return self.main() self.env = load_data['env_ref']
def create(self): path = self.check_directus_dir() install_data = prompt(EnvQuestions.create) ValidationHelper.check_answers(install_data) db_user, db_pw = self.get_db_details() ref_name = re.sub('[\W_]+', '', install_data['install_name']) env = Environment(ref_name=ref_name, name=install_data['install_name'], path=path, db_user=db_user, db_pw=db_pw) self.envs.add(env) self.env = ref_name
def project_settings(self): PjQuestions.select_project[0]['choices'] = map(lambda d: d['ref'], self.env.projects) ref_data = prompt(PjQuestions.select_project) ValidationHelper.check_answers(ref_data) self.pj = Project(ref=ref_data['pj_ref']) pj_task = prompt(PjQuestions.project_task)['pj_task'] ValidationHelper.check_answers(pj_task) if pj_task == 'delete project': self.delete() elif pj_task == 'templatify project database': self.templatify()
def create(self): migration_file = None if len(Migration.get_migrations()) > 0: migration_data = prompt(PjQuestions.migrations[0]) ValidationHelper.check_answers(migration_data) if migration_data['use_migration']: PjQuestions.migrations[1][ 'choices'] = Migration.get_migrations() migration_file = prompt( PjQuestions.migrations[1])['migration_file'] install_data = prompt(PjQuestions.create) ValidationHelper.check_answers(install_data) self.pj = Project(ref=install_data['install_ref'], name=install_data['install_name']) self.env.add_project(project=self.pj, migration_file=migration_file) self.main()