Beispiel #1
0
def print_output(results):
    if args.output is 'json':
        if args.verbose:
            for p in results:
                print(
                    utils.prettify_json(
                        json.dumps(p, sort_keys=True, indent=4, default=str)))
        else:
            for p in results:
                o = utils.simplify_patch_output(p)
                print(
                    utils.prettify_json(
                        json.dumps(o, sort_keys=True, indent=4, default=str)))
    else:
        x = PrettyTable()

        x.field_names = [
            'Patch', 'Priority', 'ubuntu/18.04', 'rhel/8', 'sle/12-SP4-AZURE'
        ]

        for p in results:
            x.add_row([
                Fore.LIGHTCYAN_EX + p['uhash'] + Style.RESET_ALL + '\n' +
                Fore.LIGHTMAGENTA_EX + p['subject'] + Style.RESET_ALL,
                p['priority'],
                next(d for d in p['distro'] if d['name'] == 'ubuntu'
                     and d['release'] == '18.04')['state'],
                next(d for d in p['distro']
                     if d['name'] == 'rhel' and d['release'] == '8')['state'],
                next(d for d in p['distro'] if d['name'] == 'sle'
                     and d['release'] == '12-SP4-AZURE')['state']
            ])

        print(x)
Beispiel #2
0
def update_job_info(n_intervals, statement_url):
    print("update_job_info")
    if "http" not in statement_url:
        return prettify_json({"state": None})

    livy = LivyRequests()
    job_info = livy.job_info(statement_url)
    return prettify_json(job_info)
Beispiel #3
0
def update_spark_info(n, spark_info_text):
    spark_info = parse_json(spark_info_text)
    livy = LivyRequests()
    if "session-url" not in spark_info.keys():
        print(spark_info)
        return prettify_json(spark_info)

    spark_info = livy.session_info(spark_info["session-url"])
    return prettify_json(spark_info)
Beispiel #4
0
def run():
    EDITOR = os.environ.get('EDITOR', 'vim')

    # get the patch
    try:
        p = dbutils.select_patch({'uhash': args.hash}).next()
    except StopIteration:
        print("Empty cursor!")

    pjson = json_util.dumps(p, indent=4, sort_keys=True)
    s = pjson.encode('UTF-8')

    with tempfile.NamedTemporaryFile(suffix=".tmp") as tf:
        tf.write(s)
        tf.flush()
        call([EDITOR, tf.name])

        tf.seek(0)
        edited_message = tf.read()

        # load the object from string

        newobj = json_util.loads(edited_message.decode("utf-8"))
        changes = [] # list of things that changed
        if newobj['subject'] != p['subject']:
            changes.append("subject")
        if newobj['author'] != p['author']:
            changes.append("author")
        if newobj['description'] != p['description']:
            changes.append("description")
        if newobj['priority'] != p['priority']:
            changes.append("priority")

        # send updated object to the database
        dbutils.edit_patch(newobj, changes)

        print(Fore.LIGHTCYAN_EX)
        print('Patch ' + args.hash + ' has been modified')
        print(Style.RESET_ALL)
        try:
            p = dbutils.select_patch({'uhash': args.hash}).next()
        except StopIteration:
            print("Empty cursor!")
        print(utils.prettify_json(json.dumps(p, sort_keys=True, indent=4, default=str)))
Beispiel #5
0
 def save_as_json(self, filename):
     with open(filename, 'w') as outf:
         print(utils.prettify_json(self.json), file=outf)
Beispiel #6
0
                                       methods=all_methods)
    template.add_apigateway_usage_plan(name=API_USAGE_PLAN_NAME,
                                       api_name=API_NAME,
                                       key_name=API_KEY_NAME,
                                       stage_name=API_STAGE_NAME,
                                       deployment_name=API_DEPLOYMENT_NAME)

    # Save a copy of the template
    template.save_as_json(STACK_NAME.lower() + '.json')

    # Submit the template to Cloud Formation for stack construction
    if client.stack_exists(session, STACK_NAME):
        print('Stack "{}" already exists!'.format(STACK_NAME))
        try:
            response = client.update_stack(session, STACK_NAME, template)
            print(utils.prettify_json(response))
        except:
            pass
    else:
        response = client.create_stack(session=session,
                                       stack_name=STACK_NAME,
                                       template=template)

        print('Template for stack "{}" uploaded.'.format(STACK_NAME))
        print('Creating... ', end='', flush=True)
        result = client.wait_for_completion(session=session,
                                            stack_name=STACK_NAME,
                                            api_name=API_NAME,
                                            key_name=API_KEY_NAME,
                                            region_name=REGION_NAME,
                                            stage_name=API_STAGE_NAME)
Beispiel #7
0
                        dcc.Dropdown(
                            id=dash_ids.TRANSFORM_FUNC_SELECT,
                            options=[
                                {"label": "log", "value": "log"},
                                {"label": "sine", "value": "sin"},
                            ],
                            value="log",
                        )
                    ],
                    style={"width": "48%", "float": "right", "display": "inline-block"},
                ),
            ]
        ),
        html.Button("RUN", id=dash_ids.RUN_BUTTON, n_clicks=0),
        dcc.Graph(id=dash_ids.CHART_1),
        html.Div(id=dash_ids.SPARK_SESSION_INFO, children=prettify_json(spark_info)),
        html.Div(
            id=dash_ids.CURRENT_STATEMENT_URL, children="", style={"display": "none"}
        ),
        html.Div(
            id=dash_ids.CURRENT_JOB_INFO,
            children=prettify_json({"state": job_states.NONE}),
        ),
    ]
)


@app.callback(
    Output(dash_ids.CURRENT_STATEMENT_URL, "children"),
    [Input(dash_ids.RUN_BUTTON, "n_clicks")],
    [