def app_update(): if request.method == api.post: # Init Resource Manager res_man = ResourceManager(config.RES_PATH, config.TEMP_PATH) try: app_helper.validate_app_fields(request.form, check_id=True) parsed_theme = theme_helper.get_theme_from_data(request.form) theme_helper.validate_theme_fields(parsed_theme) index = request.form[app_helper.FIELD_ID] except BaseError as e: traceback.print_exc() error_response = e.generate_error() logging.error(error_response) return error_response except Exception as e: traceback.print_exc() error_response = BaseError.generate_base_error(data=e.args) logging.error(msg=error_response) return error_response try: # Variables for database app_db = ApplicationRepository(config.DATA_URL) theme_db = theme_rep.ThemeRepository(config.DATA_URL) # Theme theme = theme_helper.parse_theme( sort_dict(parsed_theme)) # Dict -> Sort dict -> Theme # Application old_app = app_db.get_app_by_id(index) # App from index old_bundle = old_app.bundle # old sku result = app_helper.generate_app_json(request.form, theme.hash) # Form -> JSON application = app_helper.parse_app_by_json(result) # JSON -> App application.id = index # Commit DB app_db.update_app(application) # Update app in DB theme_db.update_theme(theme) # Update theme in DB except Exception as e: return DataBaseError(subcode=DataBaseError.duplicate_code, data=e.args).generate_error() try: res_man.update_app_res(request.files, old_bundle, application.bundle) # Update Res ResourceManager.create_app_icon(request.files, config.STATIC_PATH, application.bundle) return redirect(merge(api.get_app_info_num, index)) except BaseError as e: traceback.print_exc() error_response = e.generate_error() logging.error(error_response) return error_response return redirect(api.get_app_list)
def get_app_list(): # Variables for database app_db = ApplicationRepository(config.DATA_URL) # Application apps = app_db.get_all_apps() # Render View return render_template("app-list.html", apps=apps)
def app_save(): if request.method == api.post: try: # Variables for database app_db = ApplicationRepository(config.DATA_URL) theme_db = theme_rep.ThemeRepository(config.DATA_URL) # Init Resource Manager res_man = ResourceManager(config.RES_PATH, config.TEMP_PATH) try: app_helper.validate_app_fields(request.form) parsed_theme = theme_helper.get_theme_from_data(request.form) theme_helper.validate_theme_fields(parsed_theme) except BaseError as e: error_response = e.generate_error() logging.error(error_response) return error_response # Theme theme = theme_helper.parse_theme(sort_dict(parsed_theme)) # Sort dict # Application result = app_helper.generate_app_json(request.form, theme.hash) # Form -> JSON print(result) new_app = app_helper.parse_app_by_json(result) # JSON -> App old_app = app_db.get_app_by_bundle(new_app.bundle) # Get Old App # Redirect if exist if old_app: return BaseError.generate_base_error(f"Application with Bundle - {new_app.bundle} already exist") try: app_db.create_app(new_app) # Create app in DB theme_db.update_theme(theme) # Create theme in DB except Exception as e: return BaseError.generate_base_error(f"Error while saving application {e.args}") if request.files: try: res_man.create_app_res(request.files, new_app.bundle) # Create Resource # TODO BUNDLE except BaseError as e: traceback.print_exc() res_man.delete_res(new_app.bundle) # Delete Resource if Error error_response = e.generate_error() logging.error(error_response) return error_response except Exception as e: traceback.print_exc() error_response = BaseError.generate_base_error(data=e.args) logging.error(error_response) return error_response return BuildAction.create_action_build(action=BaseAction.REDIRECT_ACTION, subcode=BuildAction.BUILD_CREATED, data=BuildAction.data_created_build(api.get_app_list))
def app_build(): if request.method == api.post: logging.info(request.form) try: form = request.form build_type = validate_field(form["build_type"]) index = validate_field(form["id"]) is_ios: bool = False is_android: bool = False if build_type == "ios": is_ios = True elif build_type == "android": is_android = True # create_app: bool = str_to_bool(validate_field(form["create_app"])) build_params = build_helper.generate_build_params(form, config.ROOT_BUNDLE) except BaseError as e: traceback.print_exc() error_response = e.generate_error() logging.error(error_response) return error_response # Variables for database app_db = ApplicationRepository(config.DATA_URL) theme_db = theme_rep.ThemeRepository(config.DATA_URL) application = app_db.get_app_by_id(index) # App DICT from DB theme = theme_db.get_theme_by_hash(application.theme) # Theme from DB res_man = ResourceManager(config.RESOURCE_PATH, config.TEMP_PATH) res_saved = res_man.validate_resources(application.bundle) print(res_saved) producer = BuildProducer(config.QUEUE_NAME) producer.connect() if is_ios: message = BuildProducer.generate_message(application, theme, build_params, build_type="ios") logging.info("For rabbit producer generated Message {%s}" % message) producer.send(message=message) elif is_android: message = BuildProducer.generate_message(application, theme, build_params, build_type="android") logging.info("For rabbit producer generated Message {%s}" % message) producer.send(message=message) producer.disconnect() # application.status = Application.STATUS_WAITING app_db.update_app(application) return BuildAction.create_action_build(action=BaseAction.REDIRECT_ACTION, subcode=BuildAction.BUILD_CREATED, data=BuildAction.data_created_build(api.get_build_info))
def get_app_info(app_id: int): # Init variables country_path = merge(config.ASSETS_PATH, 'phonecodes.json') try: # Variables for database app_db = ApplicationRepository(config.DATA_URL) theme_db = theme_rep.ThemeRepository(config.DATA_URL) # Get application from DB application = app_db.get_app_by_id(app_id) # Get theme from DB theme = theme_db.get_theme_by_hash(application.theme) theme_dict = sort_dict(theme.dict()) # Theme to dict # Remove in further del theme_dict['id'] del theme_dict['hash'] # Generate double quotes theme_dict = json.dumps(theme_dict) logging.info("Theme for " + application.app_name.upper() + " | " + theme_dict) res_man = ResourceManager(config.RES_PATH, config.TEMP_PATH) res_saved = res_man.validate_resources(application.bundle, with_remote=False) # TODO with remote True path = AndroidLauncher.get_final_path(application.bundle) # TODO from this is_android_existing = os.path.exists(path) path = IosLauncher.get_final_path(application.bundle_ios) is_ios_existing = os.path.exists(path) # Read countries list with open(country_path) as data_file: countries = json.load(data_file) except Exception as e: traceback.print_exc() error_response = BaseError.generate_base_error(data=e.args) logging.error(error_response) # Render View return error_response response: Response = make_response(render_template("app-info.html", app=application, colors=theme_dict, countries=countries, android_res=res_saved["android"] or False, ios_res=res_saved["ios"] or False, google_res=res_saved["google"] or False)) response.set_cookie("is_android_existing", str(is_android_existing or False)) response.set_cookie("is_ios_existing", str(is_ios_existing or False)) # Render View return response
def build_update(): # Variables for database app_db = ApplicationRepository(config.DATA_URL) logging.info("Build updating " + str(request.form)) data = request.form app_index = validate_field(data["app_index"]) status = validate_field(data["status"]) # TODO REWORK THIS! It is not best practices application = app_db.get_app_by_id(app_index) application.status = status app_db.update_app(application) return ""
def app_list(): # Variables for database app_db = ApplicationRepository(config.DATA_URL) # Application apps = app_db.get_all_apps() apps_json = [] for appl in apps: apps_json.append(appl.get_simple_dist()) # Render View return json.dumps(apps_json)
def app_delete(): if request.method == api.post: form = request.form index = validate_field(form["id"]) app_db = ApplicationRepository(config.DATA_URL) res_man = ResourceManager(config.RES_PATH, config.TEMP_PATH) application = app_db.get_app_by_id(index) # App DICT from DB app_db.delete_app(application) res_man.delete_res(application.bundle) # Delete app res return redirect(api.get_app_list)
def app_build_test(): if request.method == api.post: logging.info(request.form) try: form = request.form build_type = validate_field(form["build_type"]) index = validate_field(form["id"]) except BaseError as e: traceback.print_exc() error_response = e.generate_error() logging.error(error_response) return error_response # Variables for database app_db = ApplicationRepository(config.DATA_URL) theme_db = theme_rep.ThemeRepository(config.DATA_URL) application = app_db.get_app_by_id(index) # App DICT from DB theme = theme_db.get_theme_by_hash(application.theme) # Theme from DB res_man = ResourceManager(config.RESOURCE_PATH, config.TEMP_PATH) try: res_valid = res_man.validate_resources(application.bundle) except BaseError as e: traceback.print_exc() error_response = e.generate_error() logging.error(error_response) return error_response if res_valid: build_rep = BuildRepository(config.DATA_URL) active_builds_count = build_rep.get_active_builds_count() + 1 build = build_helper.generate_build(form=form, app_id=application.app_id, build_type=build_type, theme_id=theme.id, priority=active_builds_count) build_rep.create_build(build) application.status = Application.STATUS_WAITING app_db.update_app(application) return BuildAction.create_action_build(action=BaseAction.REDIRECT_ACTION, subcode=BuildAction.BUILD_CREATED, data=BuildAction.data_created_build( api.get_build_info))