Exemple #1
0
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))
Exemple #2
0
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 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))
Exemple #4
0
def driver_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"])

            from backend.model.helper import build_helper
            build_params = build_helper.generate_driver_build(
                form, config.ROOT_BUNDLE_DRIVER)
            logging.info(build_params)
        except BaseError as e:

            traceback.print_exc()
            error_response = e.generate_error()
            logging.error(error_response)
            return error_response

        # Variables for database
        app_db = DriverApplicationRepository(config.DATA_URL)

        application = app_db.get_app_by_id(index)  # App DICT 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()
        message = BuildProducer.generate_driver_message(application,
                                                        build_params,
                                                        build_type=build_type)
        logging.info("For rabbit producer generated Message {%s}" % message)
        producer.send(message=message)
        producer.disconnect()

        app_db.update_app(application)

    return BuildAction.create_action_build(
        action=BaseAction.REDIRECT_ACTION,
        subcode=BuildAction.BUILD_CREATED,
        data=BuildAction.data_created_build(api_driver_app_list))