Exemplo n.º 1
0
def render_tracks(assembly, mode, metadata_file):
    obj = yaml.load(metadata_file)
    # Just pull out the assembly ones
    if mode == 'preferences':
      generate_track_dict = generate_preferences_track_dict
    else:
      generate_track_dict = generate_predictions_track_dict
    tracks = [generate_track_dict(x) for x in obj if x['assembly'] == assembly]
    trackdb = {'tracks': tracks}
    render_template(trackdb, 'trackDb')
Exemplo n.º 2
0
 def GET(self):
     '''
     Method:post
     '''
     try:
         log.info("Dashboard:Get")
         render.render_template("layout.tmpl")
     except Exception, e:
         log.error(e)
         return HTTPAdaptor.format_response("error", "Request processing failed.")
Exemplo n.º 3
0
 def GET(self):
     '''
     Method:post
     '''
     try:
         log.info("Dashboard:Get")
         render.render_template("layout.tmpl")
     except Exception, e:
         log.error(e)
         return HTTPAdaptor.format_response("error",
                                            "Request processing failed.")
Exemplo n.º 4
0
def get_service_list_json(
        task_definition_template_dir,
        task_definition_config,
        task_definition_config_env
) -> list:
    service_list = []

    files = os.listdir(task_definition_template_dir)
    for file in files:
        file_path = os.path.join(task_definition_template_dir, file)
        try:
            with open(file_path, 'r') as template:
                task_definitions_data = render.render_template(template.read(),
                                                               task_definition_config,
                                                               task_definition_config_env)
        except Exception as e:
            raise Exception("Template error. file: %s\n%s" % (file, e))
        try:
            task_definitions = json.loads(task_definitions_data)
        except json.decoder.JSONDecodeError as e:
            raise Exception("{e.__class__.__name__} {e}\njson:\n{json}".format(e=e, json=task_definitions_data))
        for t in task_definitions:
            service_list.append(Service(task_definition=t, stop_before_deploy=False, primary_placement=False))

    return service_list
Exemplo n.º 5
0
def test_templates(args):
    h1("Step: Check ECS Template")
    environment = None
    files = os.listdir(args.environment_yaml_dir)
    if files is None or len(files) == 0:
        raise Exception("environment yaml file not found.")
    services_config = yaml.load(args.services_yaml)
    for f in files:
        file_path = os.path.join(args.environment_yaml_dir, f)
        if os.path.isfile(file_path):
            with open(file_path, 'r') as environment_yaml:
                environment_config = yaml.load(environment_yaml.read())

                environment = environment_config.get("environment")
                if environment is None:
                    raise VariableNotFoundException("%s requires parameter `environment`." % file_path)
                environment = render.render_template(
                    str(environment),
                    environment_config,
                    args.task_definition_config_env
                )

                ecs.service.get_service_list_yaml(
                    services_config=services_config,
                    environment_config=environment_config,
                    is_task_definition_config_env=args.task_definition_config_env,
                    environment=environment
                )
                get_scheduled_task_list(
                    services_config=services_config,
                    environment_config=environment_config,
                    is_task_definition_config_env=args.task_definition_config_env,
                    environment=environment
                )
        success("Template check environment `{environment}` done.".format(environment=environment))
Exemplo n.º 6
0
        def wrapper(request, *args, **kwargs):
            module_name = get_template_app_folder(func.__module__)

            response = func(request, *args, **kwargs)
            if isinstance(response, HttpResponse):
                return response

            template_name, context_processors, mimetype = process_response(
                response, func.__name__)

            if prefix:
                if isinstance(template_name, (list, tuple)):
                    template_name = map(correct_path, template_name)
                else:
                    template_name = correct_path(template_name, prefix)
            else:
                template_name = correct_path(template_name, module_name)

            context_processors['App'] = module_name
            context_processors['View'] = func.__name__
            context_processors['Layout'] = correct_path('base.html',
                                                        prefix or module_name)

            return render_template(template_name, context_processors,
                                   context_instance=RequestContext(request),
                                   mimetype=mimetype)
Exemplo n.º 7
0
def get_variables(deploy_name: str, name: str, base_service_config: dict, environment_config: dict, is_task_definition_config_env: bool):
    variables = {"item": name}
    service_config = {}
    # ベースの値を取得
    variables.update(base_service_config)
    service_config.update(base_service_config)
    # ベースのvars
    base_vars = base_service_config.get("vars")
    if base_vars:
        variables.update(base_vars)
    # 各環境の設定値を取得
    variables.update(environment_config)
    # 各環境の設定を取得
    environment_config_services = environment_config.get(deploy_name)
    if environment_config_services:
        environment_service = environment_config_services.get(name)
        if environment_service:
            variables.update(environment_service)
            service_config.update(environment_service)
            environment_vars = environment_service.get("vars")
            if environment_vars:
                variables.update(environment_vars)
    # varsをrenderする
    vars_renderd = render.render_template(yaml.dump(variables), variables, is_task_definition_config_env)
    variables.update(yaml.load(vars_renderd))
    return service_config, variables

    
Exemplo n.º 8
0
    def POST(self):
        '''
        Method:post
        '''
        try:
            log.info("CI:Post")
            query = HTTPAdaptor.format_query(web.ctx.env["QUERY_STRING"])
            body = HTTPAdaptor.format_form_data(web.data())
            if not (query.has_key("action") and query.has_key("commit_id")):
                raise "Invalid query string"

            commit_id = query["commit_id"]

            sopt = SQLAdaptor()
            if query["action"] == "Revoke":
                sopt.SetCommitStatus(commit_id, 6)
            elif query["action"] == "Ignore":
                sopt.SetCommitStatus(commit_id, 5)
                
            author = "mxu"
            
            request_num = sopt.GetUnprocessedRequest(author)
            
            request_url = "/".join([config.server["cvproxy"],"myunprocessedrequests"])
                        
            author_info = {"name":author,
                           "request_url":request_url,
                           "request_num":request_num}
            
            dashboard_url = "/".join([config.server["cvproxy"], "dashboard"])
            navi = [
                    {"name":"Dashboard",
                     "url":dashboard_url,
                     "theme":"unselected"
                    },
                    {"name":"Current review request",
                     "url":"#",
                     "theme":"selected"
                    }
                    ]

            
            result = {
                      "category": body["category"],
                      "comment": body["comment"],
                      "choice": query["action"]
                      }
            
            sopt.InsertActionInfo(commit_id, author, query["action"], body["category"], body["comment"])
            
            return render.render_template('current_review_result.tmpl',
                                            author = author_info,
                                            navi = navi, 
                                            commit_id = commit_id,
                                            result = result
               )
            
        except Exception, e:
            log.error(e)
            return HTTPAdaptor.format_response("error", "Request processing failed.")
Exemplo n.º 9
0
def get_deploy_list(
        services_yaml,
        environment_yaml,
        task_definition_template_dir,
        task_definition_config_json,
        task_definition_config_env,
        deploy_service_group,
        template_group
):
    h1("Step: Check ECS Template")
    scheduled_task_list = []
    deploy_scheduled_task_list = []
    if services_yaml:
        services_config = yaml.load(services_yaml)
        environment_config = yaml.load(environment_yaml)

        environment = environment_config.get("environment")
        if environment is None:
            raise VariableNotFoundException("environment-yaml requires parameter `environment`.")
        environment = render.render_template(str(environment), environment_config, task_definition_config_env)

        service_list = ecs.service.get_service_list_yaml(
            services_config=services_config,
            environment_config=environment_config,
            is_task_definition_config_env=task_definition_config_env,
            environment=environment
        )

        scheduled_task_list = get_scheduled_task_list(
            services_config=services_config,
            environment_config=environment_config,
            is_task_definition_config_env=task_definition_config_env,
            environment=environment
        )
        deploy_scheduled_task_list = get_deploy_scheduled_task_list(
            scheduled_task_list, deploy_service_group, template_group)

    else:
        task_definition_config = json.load(task_definition_config_json)
        environment = task_definition_config['environment']
        service_list = ecs.service.get_service_list_json(
            task_definition_template_dir=task_definition_template_dir,
            task_definition_config=task_definition_config,
            task_definition_config_env=task_definition_config_env
        )
    deploy_service_list = ecs.service.get_deploy_service_list(service_list, deploy_service_group, template_group)

    # duplicate name check
    for deploy_service in deploy_service_list:
        for deploy_scheduled_task in deploy_scheduled_task_list:
            if deploy_service.family == deploy_scheduled_task.family:
                raise Exception('Duplicate family name `{family}` found.'.format(family=deploy_service.family))

    if len(deploy_service_list) == 0 and len(deploy_scheduled_task_list) == 0:
        error("Deployment target not found.")
        sys.exit(1)

    success("Template check environment `{environment}` done.".format(environment=environment))
    return service_list, deploy_service_list, scheduled_task_list, deploy_scheduled_task_list, environment
Exemplo n.º 10
0
    def GET(self):
        '''
        Method:get
        '''
        try:
            log.info("CI:Get")
            query = HTTPAdaptor.format_query(web.ctx.env["QUERY_STRING"])
            if not (query.has_key("action") and query.has_key("commit_id")):
                raise "Invalid query string"

            sopt = SQLAdaptor()

            author = "mxu"
            commit_id = query["commit_id"]
            sopt.SetCommitStatus(commit_id, 6)
            request_num = sopt.GetUnprocessedRequest(author)

            request_url = "/".join(
                [config.server["cvproxy"], "myunprocessedrequests"])

            author_info = {
                "name": author,
                "request_url": request_url,
                "request_num": request_num
            }

            dashboard_url = "/".join([config.server["cvproxy"], "dashboard"])
            navi = [{
                "name": "Dashboard",
                "url": dashboard_url,
                "theme": "unselected"
            }, {
                "name": "Current review request",
                "url": "#",
                "theme": "selected"
            }]

            sopt.InsertActionInfo(commit_id, query["action"], author, comment)

            result = {
                "category": "An issue",
                "comment": "Haha!",
                "choice": query["action"]
            }

            return render.render_template('current_review_result.tmpl',
                                          author=author_info,
                                          navi=navi,
                                          commit_id=commit_id,
                                          result=result)

        except Exception, e:
            log.error(e)
            return HTTPAdaptor.format_response("error",
                                               "Request processing failed.")
Exemplo n.º 11
0
def chat_groupchats(request, **kwargs):
    query = request.query
    count_str = query.get('count', [0])[0]
    count = try_to_int(count_str, null=0)

    kwargs.update(count=count)

    user = request.auth_get_user()
    chats = db.get_chats_by_user(user.id, limit=count)
    kwargs.update(chats=chats)

    return render_template(request, 'templates/chat/groupchats.html', kwargs=kwargs)
Exemplo n.º 12
0
def my_error(request, message=None, is_ajax=False):
    code = request.response.code
    if message is None:
        message = request.responses.get(code, ("other", "Another ERROR"))
    kwargs = {
        'code': code,
        'message': message,
        'code_span': gen_code(code),
        'base_vars': {
            'title': 'ERROR'
        }
    }

    if is_ajax:
        ajax_dict = {
            'html': render_template(request,
                                    'shared/Error.html',
                                    kwargs=kwargs),
            'title': 'Error'
        }
        return json.dumps(ajax_dict)
    else:
        return render_template(request, 'shared/Error.html', kwargs=kwargs)
Exemplo n.º 13
0
    def render_to_response(self, context, **response_kwargs):
        """
        Returns a response with a template rendered with the given context.
        """
        context['App'] = get_template_app_folder(self.__module__)
        context['View'] = self.__class__.__name__.lower()
        context['Layout'] = correct_path('base.html', context['App'])

        return render_template(
            response_kwargs.pop('template', self.get_template_names()),
            context_processors=context,
            context_instance=RequestContext(self.request),
            **response_kwargs
        )
Exemplo n.º 14
0
def index(request, response):
    if request.method == "POST":
        url = request.POST.get('url')
        email = request.POST.get('email')
        # song = Song(link=url)
        # session.add(song)
        # session.commit()
        create_query(url, email)
        download.delay(url, email)
        response.text = "Вам будет отправлено письмо на email"
        return response
    data = render_template("index.html")
    response.text = data
    return response
Exemplo n.º 15
0
def manage_edit_password_POST(request, **kwargs):
    data = request.POST_query
    old_password, new_password, confirm_password = data["old_password"][0].strip(), data["new_password"][0].strip(), \
                                                   data["confirm_password"][0].strip()
    user = request.auth_get_user()
    print(old_password, new_password, confirm_password)
    if not old_password or not new_password or not confirm_password or \
            new_password != confirm_password or not equal_passhash(user.password, old_password):
        kwargs.setdefault('message', 'bad password')
        return render_template(request,
                               'templates/auth/manage/edit_password.html',
                               kwargs=kwargss)
    pass_hex = convert_pass_to_passhash(new_password)
    db.update_user(user.id, password=pass_hex)
    return redirect_to(request, '/auth/manage/index/')
Exemplo n.º 16
0
def chat_enjoy(request, **kwargs):
    query = request.query
    chat_id = query.get2('chat_id')
    if chat_id is None or try_to_int(chat_id) is None:
        request.response.code = 444
        return my_error(request, message=("chat", "chat not found"))
    user = request.auth_get_user()
    # chat = db.get_chats_by_user(user_id=user.id, chat_id=chat_id, is_users=True)
    chat = db.find_chat({'id': chat_id}, is_users=True)

    if chat is None:
        request.response.code = 444
        return my_error(request, message=("chat", "chat not found"))
    elif any(u.id == user.id for u in chat.users):
        request.response.code = 444
        return my_error(request, message=("chat", "chat has user"))
    return render_template(request, 'templates/chat/enjoychat.html', kwargs={'chat':chat})
Exemplo n.º 17
0
def chat(request):
    query = request.query
    # chat_id, chat_password = request.query_get('chat_id'), request.query_get('chat_id')
    chat_id = query.get2('chat_id')
    if chat_id is None or try_to_int(chat_id) is None:
        request.response.code = 404
        return my_error(request, message=("chat", "bad chat_id"))
        # return redirect_to(request, '/')
    chat = db.find_chat({'id': chat_id})
    if chat is None:
        request.response.code = 404
        return my_error(request, message=("chat", "chat not found"))
    user = request.auth_get_user()
    chat = db.get_chats_by_user(user_id=user.id, chat_id=chat_id)
    if chat is None:
        return redirect_to(request, f'/chat/enjoy_chat?chat_id={chat_id}')

    kwargs = {}
    return render_template(request, 'templates/chat/chat.html', kwargs=kwargs)
Exemplo n.º 18
0
def myauth_register_POST(request):
    data = request.POST_query
    login, password, nickname, photodata = data.get2('login'), data.get2('password'), data.get2('nickname'), \
                                           data.get2('photodata', '')
    ajax_json = {}
    user = find_user(login=login)
    if user is None:
        photopath = save_photo(photodata)
        pass_hex = convert_pass_to_passhash(password)
        user_id = create_user(login, pass_hex, nickname, photopath)
        session_hash, user_id = create_session(request, login, user_id)
        request.auth_is = True
        request.auth_session = db.find_session(user_id, session_hash)
        ajax_json.update(header_right=render_template(
            request, 'shared/render_header-right.html', kwargs={'auth': True}),
                         redirect=True,
                         newurl='/')
        redirect_to(request, is_manual=True)
        return json.dumps(ajax_json)
    else:
        pass

    ajax_json.update(message='Bad request')
    return json.dumps(ajax_json)
Exemplo n.º 19
0
def myauth_login_POST(request):
    data = request.POST_query
    login, password = data["login"][0], data["password"][0]
    ajax_json = {}
    user = find_user(login=login)
    if user is not None:
        if equal_passhash(user.password, password):
            session_hash, user_id = create_session(request, user.login,
                                                   user.id)
            request.auth_is = True
            request.auth_session = db.find_session(user_id, session_hash)
            ajax_json.update(header_right=render_template(
                request,
                'shared/render_header-right.html',
                kwargs={'auth': True}),
                             redirect=True,
                             newurl='/')
            redirect_to(request, is_manual=True)
            return json.dumps(ajax_json)
    else:
        pass

    ajax_json.update(message='Bad request')
    return json.dumps(ajax_json)
Exemplo n.º 20
0
def myauth(request, **kwargs):
    kwargs.setdefault('message', '')
    return render_template(request,
                           'templates/auth/register.html',
                           kwargs=kwargs)
Exemplo n.º 21
0
def list_product_content(request, product_id):
    company_info = CompanyInfo.objects.get(id=1)
    products = Product.objects.filter(is_valid=1).values("name", "id")
    product_info = Product.objects.get(is_valid=1, id=product_id)
    return render_template("product_page.html", **locals())
Exemplo n.º 22
0
    def GET(self):
        '''
        Method:get
        '''
        try:
            log.info("CI:Get")
            query = HTTPAdaptor.format_query(web.ctx.env["QUERY_STRING"])
            if not (query.has_key("author") and query.has_key("commit_id")
                    and query.has_key("token")):
                raise InvalidQueryStringError
            author = query.get("author")
            commit_id = query.get("commit_id")
            token = query.get("token")
            #            if not utils.validate_token( author = author, commit_id = commit_id, url = config.server["cvproxy"],token = token):
            #                raise AuthenticationError

            sopt = SQLAdaptor()
            request_num = sopt.GetUnprocessedRequest(author)
            request_url = "/".join(
                [config.server["cvproxy"], "myunprocessedrequests"])

            author_info = {
                "name": author,
                "request_url": request_url,
                "request_num": request_num
            }

            dashboard_url = "/".join([config.server["cvproxy"], "dashboard"])
            navi = [
                #                    {"name":"Dashboard",
                #                     "url":dashboard_url,
                #                     "theme":"unselected"
                #                    },
                {
                    "name": "Current review request",
                    "url": "#",
                    "theme": "selected"
                }
            ]

            url = {
                "ignore": {
                    "absolute":
                    "/".join([
                        config.server["cvproxy"],
                        "submitaction?action=ignore&commit_id=%s" % commit_id
                    ]),
                    "relative":
                    "submitaction?action=Ignore&commit_id=%s" % commit_id
                },
                "revoke": {
                    "absolute":
                    "/".join([
                        config.server["cvproxy"],
                        "submitaction?action=revoke&commit_id=%s" % commit_id
                    ]),
                    "relative":
                    "submitaction?action=Revoke&commit_id=%s" % commit_id
                }
            }

            cijob = sopt.GetJobNameByCommit(commit_id)
            files_committed = sopt.GetCommitedFilesNum(commit_id)

            downstreamjobs = sopt.GetDownstreamJobs(cijob)
            if downstreamjobs:
                project_info = sopt.GetProjectInfo(downstreamjobs[0])
                test_info = sopt.GetTestSummary(downstreamjobs)
                results, failed_jobs = sopt.GetTestResult(downstreamjobs)

            else:
                project_info = sopt.GetProjectInfo(cijob)
                test_info = sopt.GetTestSummary([cijob])
                results, failed_jobs = sopt.GetTestResult([cijob])

            log.debug("downstream jobs: %s" % downstreamjobs)
            log.debug("project_info: %s" % project_info)
            log.debug("test_info: %s" % test_info)

            info = {
                "product": project_info["product"],
                "platform": project_info["platform"],
                "version": project_info["version"],
                "files_committed": files_committed,
                "tests_executed": test_info["tests"],
                "failures": test_info["failures"]
            }

            ci_url = config.ciserver["urlprefix"]
            jobs = []

            jobs.append({
                "jobpage":
                "/".join([ci_url, cijob[0]]),
                "name":
                cijob[0],
                "overview":
                "/".join([ci_url, cijob[0], cijob[1]]),
                "console":
                "/".join([ci_url, cijob[0], cijob[1], "console"]),
                "workspace":
                "/".join([ci_url, cijob[0], "ws"]),
                "testresult":
                "/".join([ci_url, cijob[0], cijob[1], "TestReport/?"]),
                "logs":
                "/".join([ci_url, cijob[0], cijob[1], "artifact/logs"]),
                "results":
                results,
                "failed_jobs":
                opts.FormatFailedJobs(failed_jobs)
            })

            categories = sopt.GetCategory()

            diff_list = sopt.GetDiffSetByCommit(commit_id)
            codes = opts.FormatDiffs(diff_list)

            return render.render_template('current_review_request.tmpl',
                                          author=author_info,
                                          navi=navi,
                                          url=url,
                                          commit_id=commit_id,
                                          info=info,
                                          categories=categories,
                                          jobs=jobs,
                                          codes=codes)
        except Exception, e:
            log.error(e)
            return HTTPAdaptor.format_response("error",
                                               "Request processing failed.")
Exemplo n.º 23
0
def slides(num):
    md_file = 'lesson-{}/index.md'.format(num)
    return render_template('slides.html', doc=get_doc(md_file))
Exemplo n.º 24
0
def get_service_list_yaml(
        services_config: dict,
        environment_config: dict,
        is_task_definition_config_env: bool,
        environment: str
) -> list:
    try:
        services = services_config["services"]
    except KeyError:
        return []

    task_definition_template_dict = services_config["taskDefinitionTemplates"]

    service_list = []
    service_name_list = []
    for service_name in services:
        if service_name in service_name_list:
            raise Exception("'%s' is duplicate service." % service_name)
        service_name_list.append(service_name)
        # 設定値と変数を取得
        service_config, variables = get_variables(
            deploy_name = 'services',
            name=service_name,
            base_service_config=services.get(service_name),
            environment_config=environment_config,
            is_task_definition_config_env=is_task_definition_config_env
        )

        # parameter check & build docker environment
        env = [{"name": "ENVIRONMENT", "value": environment}]

        registrator = service_config.get("registrator")
        if registrator is not None:
            registrator = render.render_template(str(registrator), variables, is_task_definition_config_env)
            try:
                registrator = bool(strtobool(registrator))
            except ValueError:
                raise ParameterInvalidException(
                    "Service `{service_name}` parameter `registrator` must be bool".format(service_name=service_name)
                )
            if registrator:
                env.append({"name": "SERVICE_NAME", "value": environment})
                env.append({"name": "SERVICE_TAGS", "value": service_name})

        cluster = service_config.get("cluster")
        if cluster is None:
            raise ParameterNotFoundException("Service `{service_name}` requires parameter `cluster`"
                                             .format(service_name=service_name))
        cluster = render.render_template(str(cluster), variables, is_task_definition_config_env)
        env.append({"name": "CLUSTER_NAME", "value": cluster})

        service_group = service_config.get("serviceGroup")
        if service_group is not None:
            service_group = render.render_template(str(service_group), variables, is_task_definition_config_env)
            env.append({"name": "SERVICE_GROUP", "value": service_group})

        service_template_group = service_config.get("templateGroup")
        if service_template_group is not None:
            service_template_group = render.render_template(
                str(service_template_group), variables, is_task_definition_config_env)
            env.append({"name": "TEMPLATE_GROUP", "value": service_template_group})

        desired_count = service_config.get("desiredCount")
        if desired_count is None:
            raise ParameterNotFoundException("Service `{service_name}` requires parameter `desiredCount`"
                                             .format(service_name=service_name))
        desired_count = render.render_template(str(desired_count), variables, is_task_definition_config_env)
        try:
            int(desired_count)
        except ValueError:
            raise ParameterInvalidException("Service `{service_name}` parameter `desiredCount` is int"
                                            .format(service_name=service_name))
        env.append({"name": "DESIRED_COUNT", "value": desired_count})

        minimum_healthy_percent = service_config.get("minimumHealthyPercent")
        if minimum_healthy_percent is not None:
            minimum_healthy_percent = render.render_template(str(minimum_healthy_percent),
                                                             variables,
                                                             is_task_definition_config_env)
            try:
                int(minimum_healthy_percent)
            except ValueError:
                raise ParameterInvalidException("Service `{service_name}` parameter `minimumHealthyPercent` is int"
                                                .format(service_name=service_name))
            env.append({"name": "MINIMUM_HEALTHY_PERCENT", "value": minimum_healthy_percent})

        maximum_percent = service_config.get("maximumPercent")
        if maximum_percent is not None:
            maximum_percent = render.render_template(str(maximum_percent), variables, is_task_definition_config_env)
            try:
                int(maximum_percent)
            except ValueError:
                raise ParameterInvalidException(
                    "Service `{service_name}` parameter `maximumPercent` is int".format(service_name=service_name)
                )
            env.append({"name": "MAXIMUM_PERCENT", "value": str(maximum_percent)})

        distinct_instance = service_config.get("distinctInstance")
        if distinct_instance is not None:
            distinct_instance = render.render_template(str(distinct_instance), variables, is_task_definition_config_env)
            try:
                distinct_instance = bool(strtobool(distinct_instance))
            except ValueError:
                raise ParameterInvalidException("Service `{service_name}` parameter `distinctInstance` must be bool"
                                                .format(service_name=service_name))
            if distinct_instance:
                env.append({"name": "DISTINCT_INSTANCE", "value": "true"})

        placement_strategy = service_config.get("placementStrategy")
        placement_strategy_list = None
        if placement_strategy is not None:
            placement_strategy_list = []
            for strategy in placement_strategy:
                strategy = render.render_template(json.dumps(strategy), variables, is_task_definition_config_env)
                strategy = json.loads(strategy)
                placement_strategy_list.append(strategy)
            env.append({"name": "PLACEMENT_STRATEGY", "value": str(placement_strategy)})

        primary_placement = service_config.get("primaryPlacement")
        if primary_placement is not None:
            primary_placement = render.render_template(str(primary_placement), variables, is_task_definition_config_env)
            try:
                primary_placement = bool(strtobool(primary_placement))
            except ValueError:
                raise ParameterInvalidException("Service `{service_name}` parameter `primaryPlacement` must be bool"
                                                .format(service_name=service_name))
            if primary_placement:
                env.append({"name": "PRIMARY_PLACEMENT", "value": "true"})

        task_definition_template = service_config.get("taskDefinitionTemplate")
        if task_definition_template is None:
            raise ParameterNotFoundException("Service `{service_name}` requires parameter `taskDefinitionTemplate`"
                                             .format(service_name=service_name))
        service_task_definition_template = task_definition_template_dict.get(task_definition_template)
        if service_task_definition_template is None or len(service_task_definition_template) == 0:
            raise Exception("'%s' taskDefinitionTemplate not found. " % service_name)
        if not isinstance(service_task_definition_template, str):
            raise Exception("'%s' taskDefinitionTemplate specified template value must be str. " % service_name)

        try:
            task_definition_data = render.render_template(service_task_definition_template,
                                                          variables,
                                                          is_task_definition_config_env)
        except jinja2.exceptions.UndefinedError:
            logger.error("Service `%s` jinja2 varibles Undefined Error." % service_name)
            raise
        try:
            task_definition = json.loads(task_definition_data)
        except json.decoder.JSONDecodeError as e:
            raise Exception(
                "Service `{service}`: {e.__class__.__name__} {e}\njson:\n{json}".format(service=service_name, e=e,
                                                                                        json=task_definition_data))
        load_balancers = service_config.get("loadBalancers")
        rendered_balancers = None
        if load_balancers is not None:
            rendered_balancers = []
            for balancer in load_balancers:
                d = {}
                target_group_arn = balancer.get('targetGroupArn')
                load_balancer_name = balancer.get('loadBalancerName')
                if target_group_arn is None and load_balancer_name is None:
                    raise ParameterInvalidException("Service `{service_name}` parameter `loadBalancers`"
                                                    " required `targetGroupArn` or `loadBalancerName`"
                                                    .format(service_name=service_name))
                if target_group_arn is not None and load_balancer_name is not None:
                    raise ParameterInvalidException("Service `{service_name}` parameter `loadBalancers`"
                                                    " do not set `targetGroupArn` and `loadBalancerName`"
                                                    .format(service_name=service_name))
                if target_group_arn is not None:
                    target_group_arn = render.render_template(str(target_group_arn), variables,
                                                              is_task_definition_config_env)
                    d.update({"targetGroupArn": target_group_arn})
                if load_balancer_name is not None:
                    load_balancer_name = render.render_template(str(load_balancer_name), variables,
                                                                is_task_definition_config_env)
                    d.update({"loadBalancerName": load_balancer_name})
                container_name = balancer.get('containerName')
                if container_name is None:
                    raise ParameterInvalidException("Service `{service_name}` parameter `loadBalancers`"
                                                    " required `containerName`"
                                                    .format(service_name=service_name))
                container_name = render.render_template(str(container_name), variables, is_task_definition_config_env)
                d.update({"containerName": container_name})
                container_port = balancer.get('containerPort')
                if container_port is None:
                    raise ParameterInvalidException("Service `{service_name}` parameter `loadBalancers`"
                                                    " required `containerPort`"
                                                    .format(service_name=service_name))
                container_port = render.render_template(str(container_port), variables, is_task_definition_config_env)
                try:
                    container_port = int(container_port)
                except ValueError:
                    raise ParameterInvalidException("Service `{service_name}`"
                                                    " parameter `containerPort` in `loadBlancers` must be int"
                                                    .format(service_name=service_name))
                d.update({"containerPort": container_port})

                rendered_balancers.append(d)
                env.append({"name": "LOAD_BALANCER", "value": "true"})

        # set parameters to docker environment
        for container_definitions in task_definition.get("containerDefinitions"):
            task_environment = container_definitions.get("environment")
            container_env = copy.copy(env)
            if task_environment is not None:
                if not isinstance(task_environment, list):
                    raise Exception("'%s' taskDefinitionTemplate environment value must be list. " % service_name)
                container_env.extend(task_environment)
            container_definitions["environment"] = container_env

        # disabledになったらリストから外す
        disabled = service_config.get("disabled")
        if disabled is not None:
            disabled = render.render_template(str(disabled), variables, is_task_definition_config_env)
            try:
                disabled = bool(strtobool(disabled))
            except ValueError:
                raise ParameterInvalidException("Service `{service_name}` parameter `disabled` must be bool"
                                                .format(service_name=service_name))
            if disabled:
                continue

        # stop before deploy
        stop_before_deploy = service_config.get("stopBeforeDeploy")
        if stop_before_deploy is not None:
            stop_before_deploy = render.render_template(str(stop_before_deploy), variables, is_task_definition_config_env)
            try:
                stop_before_deploy = bool(strtobool(stop_before_deploy))
            except ValueError:
                raise ParameterInvalidException("Service `{service_name}` parameter `stop_before_deploy` must be bool"
                                                .format(service_name=service_name))
        else:
            stop_before_deploy = False

        service_list.append(
            Service(
                task_definition=task_definition,
                stop_before_deploy=stop_before_deploy,
                primary_placement=primary_placement,
                placement_strategy=placement_strategy_list,
                load_balancers=rendered_balancers
            )
        )
    return service_list
Exemplo n.º 25
0
def home():
    return render_template('index.html')
#!/usr/bin/python

import render
import os
import sys
import xmlrpclib
import subprocess
import settings
from datetime import datetime

config = settings.load_settings()

x = xmlrpclib.ServerProxy(config['xmlrpc_endpoint'])
page = x.wp.getPage(config['blog_id'], config['participants_page_id'],
                    config['username'], config['password'])

text = render.render_template('templates/users.tmpl',
                              datetime.now().strftime("%Y/%m/%d"))
page['description'] = text

x.wp.editPage(config['blog_id'], config['participants_page_id'],
              config['username'], config['password'], page, True)
Exemplo n.º 27
0
def check_jinja(request, response):
    data = render_template('check.html', title="Boorsok")
    response.text = data
Exemplo n.º 28
0
def chat_createchat(request, **kwargs):
    query = request.query
    return render_template(request, 'templates/chat/createchat.html', kwargs=kwargs)
Exemplo n.º 29
0
args = sys.argv[1:]
if args[0] == '-q':
    dry_run = True
    quick_view = True
    args = args[1:]

if args[0] == '-n':
    dry_run = True
    args = args[1:]

date = args[0]

with open('ledger', 'a') as f:
    f.write("\n")
    f.write(render.render_template('templates/ledger', date))

if not dry_run:
    subprocess.check_call(["git", "commit", "ledger", "-m", "Update for %s" % (date,)])

debts = render.get_debts()
punt = []

with open('ledger', 'a') as f:
    f.write("\n")
    for (user, debt) in debts:
        if debt < 30: continue
        punt.append(user)
        f.write("""\
%(date)s Punt
  Pool:Owed:%(user)s  $-%(debt)s
#!/usr/bin/python

import render
import os
import sys
import xmlrpclib
import subprocess
import settings
from datetime import datetime

config=settings.load_settings()

x = xmlrpclib.ServerProxy(config['xmlrpc_endpoint'])
page = x.wp.getPage(config['blog_id'], config['participants_page_id'], config['username'], config['password'])

text = render.render_template('templates/users.tmpl',datetime.now().strftime("%Y/%m/%d"))
page['description'] = text

x.wp.editPage(config['blog_id'], config['participants_page_id'], config['username'], config['password'],page,True)
Exemplo n.º 31
0
#!/usr/bin/python

import render
import xmlrpclib
import json

from config import *

with open('secret.txt', 'r') as f:
    secret = json.load(f)
    passwd = secret['wordpress']['password']

x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
page = x.wp.getPage(BLOG_ID, PARTICIPANTS_PAGE_ID, USER, passwd)

text = render.render_template('templates/users.tmpl')
page['description'] = text

x.wp.editPage(BLOG_ID, PARTICIPANTS_PAGE_ID, USER, passwd, page, True)
Exemplo n.º 32
0
    if args[0] == '-r':
        dry_run = True
        reminder = True
        args = args[1:]

    if args[0] == '-n':
        dry_run = True
        send_mail = False
        args = args[1:]

date = args[0]

with open('ledger', 'a') as f:
    f.write("\n")
    f.write(render.render_template('templates/ledger', date))

if not dry_run:
    subprocess.check_call(
        ["git", "commit", "ledger", "-m",
         "Update for %s" % (date, )])

debts = render.get_debts()
punt = []

with open('ledger', 'a') as f:
    f.write("\n")
    for (user, debt) in debts:
        if debt < 30: continue
        punt.append(user)
        f.write("""\
Exemplo n.º 33
0
def manage_index(request, **kwargs):
    user = request.auth_get_user()
    kwargs.setdefault('user', user)
    return render_template(request,
                           'templates/auth/manage/index.html',
                           kwargs=kwargs)
Exemplo n.º 34
0
# encoding: utf-8

import render
import os
import sys
import xmlrpclib
import subprocess
import datetime
import yaml
import settings

config = settings.load_settings()

dry_run = False

args = sys.argv[1:]
if args[0] == "-n":
    dry_run = True
    args = args[1:]

date = args[0]

debts = render.get_debts()

email = render.render_template("templates/email.txt", date, mail=config["mail"])
if dry_run:
    print email
if not dry_run:
    p = subprocess.Popen(["mutt", "-H", "-"], stdin=subprocess.PIPE)
    p.communicate(email)
Exemplo n.º 35
0
def links():
    return render_template('doc.html', doc=get_doc('links/index.md'))
Exemplo n.º 36
0
USER            = '******'
BLOG_ID         = 1

dry_run = False

args = sys.argv[1:]
if args[0] == '-n':
    dry_run = True
    args = args[1:]

date = args[0]
today = str(datetime.date.today())

with open('ledger', 'a') as f:
    f.write("\n")
    f.write(render.render_template('templates/ledger', date))

subprocess.check_call(["git", "commit", "ledger",
                       "-m", "Update for %s" % (date,)])

debts = render.get_debts()
punt = []

with open('ledger', 'a') as f:
    f.write("\n")
    for (user, debt) in debts:
        if debt < 30: continue
        punt.append(user)
        f.write("""\
%(today)s Punt
  Pool:Owed:%(user)s  $-%(debt)s
Exemplo n.º 37
0
def generate_email():
    dry_run = False

    args = sys.argv[1:]
    if args[0] == '-n':
        dry_run = True
        args = args[1:]

    date = args[0]

    with open('ledger', 'a') as f:
        f.write("\n")
        f.write(render.render_template('templates/ledger', date))

    if not dry_run:
        subprocess.check_call(["git", "commit", "ledger",
                               "-m", "Update for %s" % (date,)])

    debts = render.get_debts()
    punt = []

    with open('ledger', 'a') as f:
        f.write("\n")
        for (user, debt) in debts:
            if debt <= (FINE_SIZE * 6):
                continue
            punt.append(user)
            f.write(PUNT_TEXT % {'user': user, 'debt': debt, 'date': date})


    if not dry_run:
        text = render.render_template('templates/week.tmpl', date, punt=punt)

        lines = text.split("\n")
        title = lines[0]
        body  = "\n".join(lines[1:])

        page = dict(title = title, description = body)

        with open('secret.txt', 'r') as f:
            secret = json.load(f)
            passwd = secret['wordpress']['password']

        x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
        x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)

    email = render.render_template('templates/email.html', date, punt=punt)

    if dry_run:
        print email
    else:
        send_email('*****@*****.**', email)

    with open('out/email.txt', 'w') as f:
        f.write(email)

    if punt:
        with open('bloggers.yml') as b:
            bloggers = yaml.safe_load(b)
        for p in punt:
            if bloggers.get(p) and 'end' not in bloggers[p]:
                bloggers[p]['end'] = date
        with open('bloggers.yml','w') as b:
            yaml.safe_dump(bloggers, b)

        if not dry_run:
            subprocess.check_call(["git", "commit", "ledger", "bloggers.yml",
                                   "-m", "Punts for %s" % (date,)])

    # if it's a dry run, lets set the ledger back to the beginning state
    if dry_run:
        subprocess.check_call(["git", "checkout", "ledger"])

        if punt:
            subprocess.check_call(["git", "checkout", "bloggers.yml"])
Exemplo n.º 38
0
def manage_edit_password(request, **kwargs):
    kwargs.setdefault('message', '')
    return render_template(request,
                           'templates/auth/manage/edit_password.html',
                           kwargs=kwargs)
Exemplo n.º 39
0
def generate_email():
    dry_run = False

    args = sys.argv[1:]
    if args[0] == '-n':
        dry_run = True
        args = args[1:]

    date = args[0]

    with open('ledger', 'a') as f:
        f.write("\n")
        f.write(render.render_template('templates/ledger', date))

    if not dry_run:
        subprocess.check_call(
            ["git", "commit", "ledger", "-m",
             "Update for %s" % (date, )])

    debts = render.get_debts()
    punt = []

    with open('ledger', 'a') as f:
        f.write("\n")
        for (user, debt) in debts:
            if debt <= (FINE_SIZE * 6):
                continue
            punt.append(user)
            f.write(PUNT_TEXT % {'user': user, 'debt': debt, 'date': date})

    if not dry_run:
        text = render.render_template('templates/week.tmpl', date, punt=punt)

        lines = text.split("\n")
        title = lines[0]
        body = "\n".join(lines[1:])

        page = dict(title=title, description=body)

        with open('secret.txt', 'r') as f:
            secret = json.load(f)
            passwd = secret['wordpress']['password']

        x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
        x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)

    email = render.render_template('templates/email.html', date, punt=punt)

    if dry_run:
        print email
    else:
        send_email('*****@*****.**', email)

    with open('out/email.txt', 'w') as f:
        f.write(email)

    if punt:
        with open('bloggers.yml') as b:
            bloggers = yaml.safe_load(b)
        for p in punt:
            if bloggers.get(p) and 'end' not in bloggers[p]:
                bloggers[p]['end'] = date
        with open('bloggers.yml', 'w') as b:
            yaml.safe_dump(bloggers, b)

        if not dry_run:
            subprocess.check_call([
                "git", "commit", "ledger", "bloggers.yml", "-m",
                "Punts for %s" % (date, )
            ])

    # if it's a dry run, lets set the ledger back to the beginning state
    if dry_run:
        subprocess.check_call(["git", "checkout", "ledger"])

        if punt:
            subprocess.check_call(["git", "checkout", "bloggers.yml"])
Exemplo n.º 40
0
def home_page(request):
    company_info = CompanyInfo.objects.get(id=1)
    products = Product.objects.filter(is_valid=1).values("name", "id")
    return render_template("home_page.html", **locals())
Exemplo n.º 41
0
import settings

config = settings.load_settings()

dry_run = False

args = sys.argv[1:]
if args[0] == '-n':
    dry_run = True
    args = args[1:]

date = args[0]

debts = render.get_debts()

text = render.render_template('templates/week.tmpl', date)
if dry_run:
    print >>sys.stderr, "Dry run only, not posting:"
    print text
else:
    lines = text.split("\n")
    title = lines[0]
    body  = "\n".join(lines[1:])

    page = dict(title = title, description = body)

    passwd = config['password']

    x = xmlrpclib.ServerProxy(config['xmlrpc_endpoint'])
    x.metaWeblog.newPost(config['blog_id'], config['username'], passwd, page, config['publish'])
    if config['publish']:
Exemplo n.º 42
0
    if args[0] == '-r':
        dry_run = True
        reminder = True
        args = args[1:]

    if args[0] == '-n':
        dry_run = True
	send_mail = False
        args = args[1:]

date = args[0]

with open('ledger', 'a') as f:
    f.write("\n")
    f.write(render.render_template('templates/ledger', date))

if not dry_run:
    subprocess.check_call(["git", "commit", "ledger",
                           "-m", "Update for %s" % (date,)])

debts = render.get_debts()
punt = []

with open('ledger', 'a') as f:
    f.write("\n")
    for (user, debt) in debts:
        if debt < 30: continue
        punt.append(user)
        f.write("""\
%(date)s Punt
Exemplo n.º 43
0
    def GET(self):
        '''
        Method:get
        '''
        try:
            log.info("CI:Get")
            query = HTTPAdaptor.format_query(web.ctx.env["QUERY_STRING"])
            if not (query.has_key("author") and query.has_key("commit_id") and query.has_key("token")):
                raise InvalidQueryStringError
            author = query.get("author")
            commit_id = query.get("commit_id")
            token = query.get("token")
#            if not utils.validate_token( author = author, commit_id = commit_id, url = config.server["cvproxy"],token = token):
#                raise AuthenticationError
            
            sopt = SQLAdaptor()
            request_num = sopt.GetUnprocessedRequest(author)
            request_url = "/".join([config.server["cvproxy"],"myunprocessedrequests"])
                        
            author_info = {"name":author,
                           "request_url":request_url,
                           "request_num":request_num}
            
            dashboard_url = "/".join([config.server["cvproxy"], "dashboard"])
            navi = [
#                    {"name":"Dashboard",
#                     "url":dashboard_url,
#                     "theme":"unselected"
#                    },
                    {"name":"Current review request",
                     "url":"#",
                     "theme":"selected"
                    }
                    ]
            

            
            url = {"ignore":
                    {"absolute": "/".join([config.server["cvproxy"],"submitaction?action=ignore&commit_id=%s" % commit_id]),
                     "relative": "submitaction?action=Ignore&commit_id=%s" % commit_id},
                   "revoke":
                    {"absolute": "/".join([config.server["cvproxy"],"submitaction?action=revoke&commit_id=%s" % commit_id]),
                     "relative": "submitaction?action=Revoke&commit_id=%s" % commit_id}
                   }
            
            cijob = sopt.GetJobNameByCommit(commit_id)
            files_committed = sopt.GetCommitedFilesNum(commit_id)
            
            
            downstreamjobs = sopt.GetDownstreamJobs(cijob)
            if downstreamjobs:                
                project_info = sopt.GetProjectInfo(downstreamjobs[0])
                test_info = sopt.GetTestSummary(downstreamjobs)
                results, failed_jobs = sopt.GetTestResult(downstreamjobs)
                            
            else:
                project_info = sopt.GetProjectInfo(cijob) 
                test_info = sopt.GetTestSummary([cijob])
                results, failed_jobs = sopt.GetTestResult([cijob])
                    
            log.debug("downstream jobs: %s" % downstreamjobs)
            log.debug("project_info: %s" % project_info) 
            log.debug("test_info: %s" % test_info)
            
            
            info = {"product": project_info["product"],
                    "platform":project_info["platform"],
                    "version":project_info["version"],
                    "files_committed": files_committed,
                    "tests_executed": test_info["tests"],
                    "failures":test_info["failures"]}             

            ci_url = config.ciserver["urlprefix"]
            jobs = []

            jobs.append(
                       {"jobpage":"/".join([ci_url,cijob[0]]),
                        "name":cijob[0],
                        "overview": "/".join([ci_url,cijob[0],cijob[1]]),
                        "console": "/".join([ci_url,cijob[0],cijob[1],"console"]),
                        "workspace": "/".join([ci_url,cijob[0],"ws"]),
                        "testresult": "/".join([ci_url,cijob[0],cijob[1],"TestReport/?"]),
                        "logs": "/".join([ci_url,cijob[0],cijob[1],"artifact/logs"]),
                        "results": results,
                        "failed_jobs": opts.FormatFailedJobs(failed_jobs)
                        }                               
                        )    
                           
                  
                               
            categories = sopt.GetCategory()
            
            diff_list = sopt.GetDiffSetByCommit(commit_id)
            codes = opts.FormatDiffs(diff_list)
        
            return render.render_template('current_review_request.tmpl',
                           author = author_info,
                           navi = navi, 
                           url = url, 
                           commit_id = commit_id,
                           info = info,
                           categories = categories,
                           jobs = jobs,
                           codes = codes)
        except Exception, e:
            log.error(e)
            return HTTPAdaptor.format_response("error", "Request processing failed.")