示例#1
0
def main(csv_name, version, overlay):
    with open(csv_name, mode='r') as csv_file:
        csv_reader = csv.DictReader(csv_file)
        line_count = 0
        total_func = 0
        done_func = 0
        total_byte = 0
        done_byte = 0
        for row in csv_reader:
            if (row["version"] == version):
                total_func += 1
                total_byte += int(row['length'])
                if row['matching'] == 'yes':
                    done_func += 1
                    done_byte += int(row['length'])
        percent = ((done_byte / total_byte) * 100)
        print("%s: bytes: %3.4f%% (%d/%d), funcs: %3.4f%% (%d/%d)" %
              (overlay, percent, done_byte, total_byte,
               ((done_func / total_func) * 100), done_func, total_func))
        green = min(255, round(min(1, (percent / 100) * 2) * 256))
        red = min(255, round(min(1, ((100 - percent) / 100) * 2) * 256))
        color = RGB_to_hex([red, green, 0])
        if overlay == 'total':
            badge = anybadge.Badge("Banjo-Kazooie (us.v10)",
                                   "%3.4f%%" % (percent),
                                   default_color=color)
        else:
            badge = anybadge.Badge(overlay,
                                   "%3.4f%%" % (percent),
                                   default_color=color)
        badge.write_badge('progress/progress_' + overlay + '.svg',
                          overwrite=True)
def pylint_check(int_only, create_badge):
    try:
        import re
        import anybadge
        from pylint import epylint

        pylint_stdout, pylint_stderr = epylint.py_run("hyperglass",
                                                      return_std=True)
        pylint_output = pylint_stdout.getvalue()
        pylint_score = re.search(
            r"Your code has been rated at (\d+\.\d+)\/10.*",
            pylint_output).group(1)
        if not pylint_score == "10.00":
            raise RuntimeError(f"Pylint score {pylint_score} not acceptable.")
        if create_badge:
            badge_file = os.path.join(working_directory, "pylint.svg")
            if os.path.exists(badge_file):
                os.remove(badge_file)
            ab_thresholds = {1: "red", 10: "green"}
            badge = anybadge.Badge("pylint",
                                   pylint_score,
                                   thresholds=ab_thresholds)
            badge.write_badge("pylint.svg")
        if not int_only:
            click.secho(f"Created Pylint badge for score: {pylint_score}",
                        fg="blue",
                        bold=True)
        if int_only:
            click.echo(pylint_score)
    except ImportError as error_exception:
        click.secho(f"Import error:\n{error_exception}", fg="red", bold=True)
示例#3
0
def badge_render():
    try:
        badge = anybadge.Badge('CI', report_status, thresholds={'PASS': '******', 'FAIL': 'red'})
        badge.write_badge(outdir + 'badge.svg')
        with open(outdir + 'ci-status.yml', 'w') as f:
            f.write('CI: "' + report_status + '"')
    except Exception as error:
        print(error)
示例#4
0
文件: badge.py 项目: puzanov/heimdall
def badge_generator(status):
    thresholds = {
        'critical': 'red',
        'minor': 'yellow',
        'passed': 'green',
        'processing': 'lightgrey',
    }
    badge = anybadge.Badge('Smart Contracts', status, thresholds=thresholds)
    return badge.badge_svg_text
示例#5
0
文件: ci.py 项目: thelamer/docker-ci
def badge_render():
    try:
        badge = anybadge.Badge('CI',
                               report_status,
                               thresholds={
                                   'PASS': '******',
                                   'FAIL': 'red'
                               })
        badge.write_badge(outdir + 'badge.svg')
    except Exception as error:
        print(error)
def generate_coverage_badge(coverage):
    badge_path = os.path.join(BASE_DIR, '.meta', 'media', 'coverage.svg')
    badge = anybadge.Badge('coverage',
                           coverage,
                           thresholds={
                               50: 'red',
                               60: 'orange',
                               80: 'yellow',
                               100: 'green'
                           },
                           value_suffix='%')
    os.remove(badge_path)
    badge.write_badge(badge_path)
示例#7
0
def generate_badge(target, layout, attribute):
    """
    Generate a badge
    :param target: Dict
    :param layout: Dict
    :param attribute: String
    :return:
    """
    thresholds = {50: 'red',
                  90: 'yellow',
                  100: 'green'}
    badge = anybadge.Badge(layout['label'], round(layout['value']), thresholds=thresholds)

    badge.write_badge(f'{utility.get_data_dir()}_{target["identifier"]}.{attribute}.svg', overwrite=True)
示例#8
0
def public_stats(summary: int, label, badgesvg, badgeid, logfile):
    print('public_stats')
    badge = anybadge.Badge(label=label,
                           value=summary,
                           default_color='green',
                           num_padding_chars=1)
    badge.write_badge(badgesvg, overwrite=True)

    badge_put = requests.put(
        url=
        f'https://gitlab.com/api/v4/projects/{CI_PROJECT_ID}/badges/{badgeid}',
        json={
            'link_url': f'{CI_JOB_URL}/artifacts/raw/{logfile}',
            'image_url': f'{CI_JOB_URL}/artifacts/raw/{badgesvg}'
        },
        headers={'PRIVATE-TOKEN': PRIVATE_TOKEN})

    if badge_put.status_code in [200, 201]:
        pprint('badge published')
    else:
        pprint('badge publish failed')
        sys.exit(1)
示例#9
0
#!/usr/bin/python
"""
anybadge test module.
"""

import anybadge

if __name__ == '__main__':

    thresholds = {2: 'red', 4: 'orange', 6: 'green', 8: 'brightgreen'}

    badge = anybadge.Badge('test',
                           '2.22',
                           value_suffix='%',
                           thresholds=thresholds,
                           text_color='#010101,#101010')

    print(badge.badge_svg_text)
示例#10
0
    def setUpClass(cls):
        cls.my_db = Database(db_name="campusdb", dbs_type="mysql")

        # add tables
        cls.my_db.add_table(table_name="studiengang", n_rows=10)
        cls.my_db.add_table(table_name="student", n_rows=150)
        
        # add columns to studiengang table
        cls.my_db.tables["studiengang"].add_primary_key(
            column_name="studiengang_id"
        )

        cls.my_db.tables["studiengang"].add_column(
            column_name="bezeichnung",
            data_type="varchar(50)",
            data_target="name"
        )

        cls.my_db.tables["studiengang"].add_column(
            column_name="start_datum", 
            data_type="date",
            data_target="date"
        )

        # add columns to student table
        cls.my_db.tables["student"].add_primary_key(
            column_name="student_id"
        )
        
        cls.my_db.tables["student"].add_column(
            column_name="firstname",
            data_type="varchar(50)",
            data_target="first_name"
        )
        
        cls.my_db.tables["student"].add_column(
            column_name="lastname",
            data_type="varchar(50)",
            data_target="last_name"
        )
        
        cls.my_db.tables["student"].add_foreign_key(
            column_name="studiengang_id",
            target_table="studiengang",
            target_column="studiengang_id"
        )

        # generate data
        cls.my_db.generate_data()
        cls.my_db.export_sql("test_1.sql")

        # add recursive db
        cls.hr = Database(db_name="hr", dbs_type="mysql")
        cls.hr.add_table(table_name="employee", n_rows=10)

        cls.hr.tables["employee"].add_primary_key(column_name="emp_id")
        cls.hr.tables["employee"].add_column(column_name="firstname", data_type="varchar(50)", data_target="first_name")
        cls.hr.tables["employee"].add_column(column_name="lastname", data_type="varchar(50)", data_target="last_name")
        cls.hr.tables["employee"].add_foreign_key(column_name="boss_id", target_table="employee", target_column="emp_id")
        cls.hr.generate_data(recursive = True)
        cls.hr.export_sql("test_2.sql")


        # create test badge
        if os.path.exists('badges/dbsetup.svg'):
            os.remove('badges/dbsetup.svg')
            
        thresholds = {
            0.2: 'red',
            0.4: 'orange',
            0.6: 'yellow',
            1: 'green'
        }

        badge_runs = anybadge.Badge(
            'Database Setup',
            round(1, 2),
            thresholds=thresholds
        )

        badge_runs.write_badge('badges/dbsetup.svg')
示例#11
0
"""
Utility to run pylint and update the badge
"""
import re
import sys
import json
from io import StringIO
import anybadge

# Get the score
data = json.load(open(sys.argv[1], 'r'))
coverage_pct = round(data['totals']['percent_covered'])

# Define thresholds: <2=red, <4=orange <8=yellow <10=green
thresholds = {20: 'red',
              40: 'orange',
              70: 'yellow',
              90: 'green'}

badge = anybadge.Badge('coverage', coverage_pct,
                       thresholds=thresholds, value_suffix="%")
badge.write_badge('imgs/coverage.svg', overwrite=True)

# failunder
if coverage_pct < 90:
    exit(1)
示例#12
0
PARSER.add_argument("--gitHubPat", type=str, required=True)

ARGS = PARSER.parse_args()

PYLINT_CMD = ["pylint --exit-zero ./**/*.py"]

PYLINT_OUTPUT = subprocess.run(PYLINT_CMD,
                               check=True,
                               stdout=subprocess.PIPE,
                               shell=True).stdout.decode("utf-8")
PYLINT_SCORE = PYLINT_OUTPUT.split("at ", 1)[1].split("/", 1)[0]
print(f"[INFO] PYLINT_SCORE: {PYLINT_SCORE}")

ANYBADGE_THRESHOLDS = {2: "red", 4: "orange", 6: "yellow", 10: "green"}

BADGE = anybadge.Badge("pylint", PYLINT_SCORE, thresholds=ANYBADGE_THRESHOLDS)
BADGE.write_badge("pylint.svg")

SVG = open("pylint.svg", "r")
SVG_READ = SVG.read()

URL = "https://api.github.com/gists/{}".format(ARGS.gistId)
HEADERS = {"Authorization": f"token {ARGS.gitHubPat}"}
DATA = {
    "description": "Created via API",
    "files": {
        "pylint.svg": {
            "content": f"{SVG_READ}"
        }
    },
}
with open("build/reports/ci-metrics.json", "r") as json_file:
    data = json.load(json_file)

    ###############################################################################
    # BUILD STATUS
    ## GREEN BUILD DATE ===========================================================
    # Extract metric
    label = "green build"
    metric = data["build-status"]["green"]["timestamp"]

    timestamp = datetime.fromtimestamp(metric)
    value = timestamp.strftime("%Y/%m/%d %H:%M:%S")
    color = "lightgrey"

    # Create badge
    badge = anybadge.Badge(label=label, value=value, default_color=color, value_prefix=' ', value_suffix=' ')

    # Write badge
    badge.write_badge("build/badges/build_green_date.svg", overwrite=True)

    ## LAST BUILD STATUS ==========================================================
    # Extract metric
    label = "last build"
    metric = data["build-status"]["last"]["status"]
    value = metric

    if metric == "failed":
        # set colour
        color = "red"
    elif metric == "success":
        # set colour
示例#14
0
    options[_screens[i]['number']] = {
        'current': 0,
        'total': len(screens[_screens[i]['number']]['forwards'])
    }
    if options[_screens[i]['number']]['total'] > 1:
        nPaths += options[_screens[i]['number']]['total'] - 1

del _screens

maxStepsToEnding = 200

for _iPath in range(nPaths):
    iScreen = 0
    for i in range(maxStepsToEnding):
        iScreen, options = moveToNextScreen(iScreen, options, screens)
        if iScreen == 888:
            break
        if i == maxStepsToEnding - 1:
            raise ValueError('Potential loop found!')

print('All checks complete and successful!')

#Define thresholds: <2=red, <4=orange <8=yellow <10=green
thresholds = {4: 'red', 8: 'orange', 12: 'yellow', 16: 'green'}

badge = anybadge.Badge('Anzahl Geschichten',
                       str(int(nPaths)),
                       thresholds=thresholds)

badge.write_badge('paths.svg')
示例#15
0
def main():
    """
    Main function to check the implemementation files herein this repo
    and what is specced out in the TFC API docs.
    """
    non_admin_endpoints = get_docs_from_github()
    admin_endpoints = get_docs_from_github(is_admin=True)

    # Merge the endpoint types
    endpoints = non_admin_endpoints.copy()
    endpoints.update(admin_endpoints)
    endpoints = check_contributor_requirements(endpoints)
    endpoints = check_methods_implementation(endpoints)

    write_pretty_json_to_file("./ref/data/endpoint_data.raw.json", endpoints)

    # High level comparison which shows if the endpoint is implemented at all.
    # Build a markdown table for GitHub display
    endpoint_headers = [
        "Endpoint", "Module", "Has Implementation", "Has Test", "Has Docs"
    ]
    endpoint_rows = []

    # TODO: make sure implementation and test and docs work
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        endpoint_rows.append([
            f'[{ep_name.replace("_", " ").title()}]({endpoint["docs-url"]})',
            f'`{ep_name}`', "implementation" in endpoint, "test" in endpoint,
            "docs" in endpoint
        ])

    endpoint_rows.sort(key=lambda x: x[0])
    write_table_to_file("./CONTRIBUTING_REQS_TABLE.md", endpoint_rows,
                        endpoint_headers, "github")

    md_method_headers = [
        "API Endpoint", "Endpoint Description", "HTTP Method",
        "Terrasnek Method", "Implemented"
    ]
    md_method_rows = []
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        for method_header in endpoint["methods"]:
            method = endpoint["methods"][method_header]
            method_name = None

            if method["implementation-method-name"] is not None:
                method_name = f'`{ep_name}.{method["implementation-method-name"]}`'

            md_method_row = [
                ep_name.replace("_", " ").replace("-", " ").title(),
                f"[{method_header}]({method['permalink']})",
                method["http-paths"][0], method_name, method["implemented"]
            ]
            md_method_rows.append(md_method_row)

    md_method_rows.sort(key=lambda x: x[0])
    write_table_to_file("./TERRASNEK_API_COVERAGE_COMPLETENESS.md", \
        md_method_rows, md_method_headers, "github")

    # Build an RST table for the Sphinx Python Docs
    rst_method_headers = [
        "API Endpoint", "Endpoint Description", "HTTP Method",
        "Terrasnek Method", "Implemented", "Permalink"
    ]
    rst_method_rows = []
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        for method_header in endpoint["methods"]:
            method = endpoint["methods"][method_header]
            method_name = None

            if method["implementation-method-name"] is not None:
                method_name = f'`{ep_name}.{method["implementation-method-name"]}`'

            rst_method_row = [
                ep_name.replace("_", " ").title(), f'`{method_header}`',
                f'`{method["http-paths"][0]}`', method_name,
                method["implemented"], method["permalink"]
            ]
            rst_method_rows.append(rst_method_row)

    rst_method_rows.sort(key=lambda x: x[0])
    write_table_to_file("./docs/TERRASNEK_API_COVERAGE_COMPLETENESS.rst", \
        rst_method_rows, rst_method_headers, "rst")

    # Write a badge for the # of implemented methods vs the total # of method endpoints
    num_methods_implemented = 0
    num_total_methods = 0
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        for method_header in endpoint["methods"]:
            method = endpoint["methods"][method_header]
            num_total_methods += 1
            if method["implemented"]:
                num_methods_implemented += 1

    badge_text = f"{num_methods_implemented}/{num_total_methods} API endpoints implemented"
    print(badge_text)
    implemented_pct = round(
        ((num_methods_implemented / num_total_methods) * 100), 2)
    badge = anybadge.Badge(badge_text,
                           f"{implemented_pct}%",
                           default_color="lightgrey")
    badge.write_badge("api_endpoints_implemented.svg", overwrite=True)

    # We want this to error if we fall below 99% coverage so we know we have to do work
    if implemented_pct <= 99:
        sys.exit(1)
示例#16
0
import anybadge

if __name__ == '__main__':

    print("""| Color Name | Hex Code | Example |
    | ---------- | -------- | ------- |""")
    for color, hex in sorted(anybadge.COLORS.items()):

        file = 'examples/color_' + color + '.svg'

        url = 'https://cdn.rawgit.com/jongracecox/anybadge/master/' + file

        anybadge.Badge(label='Color', value=color, default_color=color).write_badge(file, overwrite=True)

        print("| {color} | {hex} | ![]({url}) |".format(color=color, hex=hex.upper(), url=url))
示例#17
0
def main():
    endpoints = scrape_endpoint_info()
    endpoints = check_contributor_requirements(endpoints)
    endpoints = check_methods_implementation(endpoints)

    # High level comparison which shows if the endpoint is implemented at all.
    # Build a markdown table for GitHub display
    endpoint_headers = [
        "Endpoint", "Module", "Has Implementation", "Has Test", "Has Docs"
    ]
    endpoint_rows = []
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        endpoint_rows.append([
            f'[{ep_name.replace("_", " ").title()}]({endpoint["url"]})',
            f'`{ep_name}`', "implementation" in endpoint, "test" in endpoint,
            "docs" in endpoint
        ])

    endpoint_rows.sort(key=lambda x: x[0])
    write_table_to_file("./CONTRIBUTING_REQS_TABLE.md", endpoint_rows,
                        endpoint_headers, "github")

    md_method_headers = [
        "API Endpoint", "Method Description", "HTTP Method",
        "Terrasnek Method", "Implemented"
    ]
    md_method_rows = []
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        for method in endpoint["methods"]:
            method_name = None

            if method["implementation-method-name"] is not None:
                method_name = f'`{ep_name}.{method["implementation-method-name"]}`'

            md_method_row = [
                ep_name.replace("_", " ").title(),
                f'[{method["description"]}]({endpoint["url"]}{method["permalink"]})',
                f'`{method["http-path"]}`', method_name, method["implemented"]
            ]
            md_method_rows.append(md_method_row)

    md_method_rows.sort(key=lambda x: x[0])
    write_table_to_file("./API_PARITY_TABLE.md", md_method_rows,
                        md_method_headers, "github")

    # Build an RST table for the Sphinx Python Docs
    rst_method_headers = [
        "API Endpoint", "Method Description", "HTTP Method",
        "Terrasnek Method", "Implemented", "Permalink"
    ]
    rst_method_rows = []
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        for method in endpoint["methods"]:
            method_name = None
            if method["implementation-method-name"] is not None:
                method_name = f'`{ep_name}.{method["implementation-method-name"]}`'

            rst_method_row = [
                ep_name.replace("_",
                                " ").title(), f'`{method["description"]}`',
                f'`{method["http-path"]}`', method_name, method["implemented"],
                f'{endpoint["url"]}{method["permalink"]}'
            ]
            rst_method_rows.append(rst_method_row)

    rst_method_rows.sort(key=lambda x: x[0])
    write_table_to_file("./docs/api_parity_table.rst", rst_method_rows,
                        rst_method_headers, "rst")

    # TODO: write the endpoints mapping out to a file

    # Write a badge for the # of implemented methods vs the total # of method endpoints
    num_methods_implemented = 0
    num_total_methods = 0
    for ep_name in endpoints:
        endpoint = endpoints[ep_name]
        for method in endpoint["methods"]:
            num_total_methods += 1
            if method["implemented"]:
                num_methods_implemented += 1

    badge_text = f"{num_methods_implemented}/{num_total_methods} API endpoints implemented"
    implemented_pct = round(
        ((num_methods_implemented / num_total_methods) * 100), 2)
    badge = anybadge.Badge(badge_text,
                           f"{implemented_pct}%",
                           default_color="lightgrey")
    badge.write_badge("api_endpoints_implemented.svg", overwrite=True)
示例#18
0
    if os.path.exists('badges/errors.svg'):
        os.remove('badges/errors.svg')
    if os.path.exists('badges/failures.svg'):
        os.remove('badges/failures.svg')
    if os.path.exists('badges/tests.svg'):
        os.remove('badges/tests.svg')
    if os.path.exists('badges/total.svg'):
        os.remove('badges/total.svg')

    thresholds = {
        1: 'green',
        2: "orange",
        3: "red"
    }
    badge_errors = anybadge.Badge('Test errors', number_of_errors, thresholds=thresholds)
    badge_errors.write_badge('badges/errors.svg')

    thresholds = {
        1: 'green',
        2: "orange",
        3: "red"
    }
    badge_failures = anybadge.Badge('Tests failed', number_of_failures, thresholds=thresholds)
    badge_failures.write_badge('badges/failures.svg')

    thresholds = {
        0: 'green'
    }
    badge_runs = anybadge.Badge('Tests run', number_of_tests, thresholds=thresholds)
    badge_runs.write_badge('badges/tests.svg')
import anybadge
import coverage
import unittest

tresholds = {
    40: 'red',
    60: 'orange',
    80: 'yellow',
    100: 'green',
}

if __name__ == '__main__':
    cov = coverage.Coverage()
    cov.start()

    from tests import test  # Needs to be after cov.start to count lines with function definition
    suite = unittest.TestLoader().loadTestsFromModule(test)
    unittest.TextTestRunner(verbosity=2).run(suite)

    cov.stop()
    value = round(cov.report(morfs='src/to_be_tested.py'), 2)

    badge = anybadge.Badge("Coverage",
                           value,
                           thresholds=tresholds,
                           value_suffix='%')

    badge.write_badge("docs/img/Coverage.svg", overwrite=True)
示例#20
0
import anybadge
from pylint.lint import Run

results = Run(['fleet_management'], do_exit=False)
score = results.linter.stats['global_note']
thresholds = {2: 'red', 4: 'orange', 6: 'yellow', 10: 'green'}

badge = anybadge.Badge('pylint score', round(score, 2), thresholds=thresholds)

badge.write_badge('pylint.svg')
示例#21
0
from io import StringIO
import anybadge
from pylint.lint import Run
from pylint.reporters.text import TextReporter

# run pylint
output = StringIO()
Run(['--rcfile=.pylintrc', 'truvari'],
    reporter=TextReporter(output),
    exit=False)
output.seek(0)
output = output.read()

# Get the score
search = re.search("Your code has been rated at (?P<score>.*)/10", output)
pylint_score = float(search.groupdict()['score'])
if pylint_score == 10:
    pylint_score = int(pylint_score)

# Define thresholds: <2=red, <4=orange <8=yellow <10=green
thresholds = {2: 'red', 4: 'orange', 6: 'yellow', 10: 'green'}

badge = anybadge.Badge('pylint', pylint_score, thresholds=thresholds)
badge.write_badge('imgs/pylint.svg', overwrite=True)

sys.stdout.write(output)

# failunder
if pylint_score != 10:
    exit(1)