Example #1
0
def check_tags(frontmatter):
    '''Checks tags in frontmatter against VALID_TAGS list.'''
    errCount = 0
    error_list = list()
    try:
        if not frontmatter['tags']:
            error_list.append(
                COLOR.colorize('WARNING: "tag" list empty in frontmatter',
                               'warn'))
        for tag in frontmatter['tags']:
            if tag not in VALID_TAGS:
                errCount += 1
                error_list.append(
                    COLOR.colorize('ERROR: {} is not a valid tag'.format(tag),
                                   'error'))
    except KeyError:
        errCount += 1
        error_list.append(
            COLOR.colorize('ERROR: "tag" key not found in frontmatter',
                           'error'))
    except Exception as e:
        errCount += 1
        error_list.append(COLOR.colorize('ERROR: {}'.format(e), 'error'))

    ERRPRINT(errCount, test_name='tags')

    return (errCount, error_list)
def main(ignore_list, extra_args):
    file_list = helpers.get_posts()
    html_strings = dict()
    non_centered = dict()
    errCount = 0
    if 'skip-html' not in extra_args:
        print(COLOR.colorize('Checking for errant HTML tags', 'info'), end=' ')
        for filename in file_list:
            (html_found, errs) = get_html(filename, ignore_list)
            html_strings = helpers.merge_dicts(html_strings, html_found)
            errCount += errs
        if errs > 0:
            print(PRINT_FAIL)
        for key, entry in html_strings.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}: {}'.format(element[0], element[1]))
                print('')
        if errs == 0:
            print(PRINT_OK)

    if 'center-image' in extra_args:
        print(COLOR.colorize('\nVerifying images are centered', 'info'), end=' ')
        for filename in file_list:
            (found, errs) = check_image_centering(filename)
            non_centered = helpers.merge_dicts(found, non_centered)
            errCount += errs
        if errs > 0:
            print(PRINT_FAIL)
        for key, entry in non_centered.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}: {}'.format(element[0], element[1]), end='')
        if errs == 0:
            print(PRINT_OK)

    if 'center-eqs' in extra_args:
        non_centered = dict()
        print(COLOR.colorize('\nVerifying equations are centered', 'info'), end=' ')
        for filename in file_list:
            (found, errs) = check_eq_centering(filename)
            non_centered = helpers.merge_dicts(found, non_centered)
            errCount += errs
        if errs > 0:
            print(PRINT_FAIL)
        for key, entry in non_centered.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}: {}'.format(element[0], element[1], end=''))
        if errs == 0:
            print(PRINT_OK)

    print('\n')
    ERRPRINT(errCount, completion=True)

    return(0)
Example #3
0
def main(test_args, skip_list):
    errCount = 0
    file_list = helpers.get_posts()
    for filename in file_list:
        if re.sub(helpers.PATH, '', filename) not in skip_list:
            test_array = list()
            PRINT_FILE_STRING = COLOR.colorize(filename, 'text')
            print(PRINT_FILE_STRING, end=" - ")
            test_err_list = list()
            for arg in test_args:
                (test_errs, test_err_list) = run_test(filename, arg)
                errCount += test_errs
                test_array.append(test_err_list)
            print('')
            for error in test_err_list:
                print(error)

    ERRPRINT(errCount, completion=True)

    return (0)
Example #4
0
def check_feature_key(frontmatter):
    '''Verifies feature_image set if the post is set to be featured.'''
    errCount = 0
    error_list = list()

    if 'project' in frontmatter.keys():
        try:
            is_project = frontmatter['project']
            is_featured = frontmatter['feature']
        except KeyError:
            is_featured = False
            error_list.append(
                COLOR.colorize('ERROR: "feature" key not found', 'error'))
            errCount += 1

        try:
            if is_featured == 'true':
                feature_image = frontmatter['feature_image']
        except KeyError:
            error_list.append(
                COLOR.colorize(
                    'ERROR: "feature_image" key not found and "feature" is set to {}'
                    .format(is_featured), 'error'))
            errCount += 1
        except IndexError:
            errCount += 1
            error_list.append(
                COLOR.colorize(
                    'ERROR: Marked as a project but the "feature" key is not set',
                    'error'))
        except Exception as e:
            errCount += 1
            error_list.append(COLOR.colorize('ERROR: {}'.format(e), 'error'))
    else:
        errCount += 1
        error_list.append(
            COLOR.colorize('ERROR: Missing "project" key', 'error'))

    ERRPRINT(errCount, test_name='feature_key')

    return (errCount, error_list)
Example #5
0
def main(extra_args):
    file_list = helpers.get_posts()
    errCount = 0
    tag = extra_args["tag"]
    skip_diff = extra_args["skip_diff"]
    print(COLOR.colorize(f"\nLooking for {tag}\n", "warn"))
    for filename in file_list:
        entries = find_tags(filename, tag)
        if not entries:
            msg = COLOR.colorize("No image tags found", "error")
            print(f"{filename}: {msg}")
            continue
        msg = COLOR.colorize(f"{len(entries)} tags found!", "warn")
        msg2 = COLOR.colorize(f" lines: {list(entries.keys())}", "linenum")
        print(f"{filename}: {msg} {msg2}")
        replace_tags(filename, entries)
        errCount += diff_before_continue(filename, skip_diff)

    print('\n')
    ERRPRINT(errCount, completion=True)
    return(errCount)
Example #6
0
def main(debug, checker=False):
    """Method to get list of tags."""
    all_posts = glob.glob("{}*.md".format(post_dir))
    all_tags = list()

    old_tags = glob.glob("{}*.md".format(tag_dir))

    if checker:
        errorCount = 0
        existing_tag_pages = list()
        for tag in old_tags:
            tagfile = os.path.basename(tag)
            tagname, ext = os.path.splitext(tagfile)
            existing_tag_pages.append(tagname)
        for valid_tag in VALID_TAGS:
            if valid_tag not in existing_tag_pages:
                print(
                    COLOR.colorize("Missing tag page {}".format(valid_tag),
                                   'error'))
                errorCount += 1
        ERRPRINT(errorCount, completion=True)
        sys.exit(0)
    else:
        for tag in old_tags:
            os.remove(tag)

        for tag in VALID_TAGS:
            tag_file = '{}{}.md'.format(tag_dir, tag)
            if debug:
                print("Generating {} tag page".format(tag_file))
            with open(tag_file, 'w') as ftag:
                out_str = "---\nlayout: tagpage\ntitle: \"Tag: {}\"\ntag: {}\nrobots: noindex\n---\n".format(
                    tag, tag)
                ftag.write(out_str)

        print('Generated {} Tags'.format(VALID_TAGS.__len__()))
Example #7
0
def main(ignore_list, extra_args):
    file_list = helpers.get_posts()
    html_strings = dict()
    non_centered = dict()
    found_tags = dict()
    errCount = 0
    if not extra_args['skip-html']:
        print(COLOR.colorize('Checking for errant HTML tags', 'info'), end=' ')
        errs_here = 0
        for filename in file_list:
            (html_found, errs) = get_html(filename, ignore_list)
            html_strings = helpers.merge_dicts(html_strings, html_found)
            errs_here += errs
            errCount += errs
        if errs_here > 0:
            print(PRINT_FAIL)
        for key, entry in html_strings.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}: {}'.format(element[0], element[1]))
                print('')
        if errs_here == 0:
            print(PRINT_OK)

    if extra_args['img-tag']:
        tag = extra_args['img-tag']
        print(COLOR.colorize('\nVerifying all image tags have been updated',
                             'info'),
              end=' ')
        errs_here = 0
        for filename in file_list:
            (found, errs) = check_image_tags(filename, tag)
            found_tags = helpers.merge_dicts(found, found_tags)
            errs_here += errs
            errCount += errs
        if errs_here > 0:
            print(PRINT_FAIL)
        for key, entry in found_tags.items():
            if entry:
                print(f"{key}\n{PRINT_ERROR}")
                for element in entry:
                    print(f"{element[0]}: {element[1]}", end='')
        if errs_here == 0:
            print(PRINT_OK)
        else:
            print(COLOR.colorize('Must run ./script/gen_img!', 'warn'))

    if extra_args['center-image']:
        print(COLOR.colorize('\nVerifying images are centered', 'info'),
              end=' ')
        errs_here = 0
        for filename in file_list:
            (found, errs) = check_image_centering(filename)
            non_centered = helpers.merge_dicts(found, non_centered)
            errs_here += errs
            errCount += errs
        if errs_here > 0:
            print(PRINT_FAIL)
        for key, entry in non_centered.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}: {}'.format(element[0], element[1]), end='')
        if errs_here == 0:
            print(PRINT_OK)

    if extra_args['center-eqs']:
        non_centered = dict()
        errs_here = 0
        print(COLOR.colorize('\nVerifying equations are centered', 'info'),
              end=' ')
        for filename in file_list:
            (found, errs) = check_eq_centering(filename)
            non_centered = helpers.merge_dicts(found, non_centered)
            errs_here += errs
            errCount += errs
        if errs_here > 0:
            print(PRINT_FAIL)
        for key, entry in non_centered.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}: {}'.format(element[0], element[1], end=''))
        if errs_here == 0:
            print(PRINT_OK)

    if not extra_args['skip-eq-tags']:
        bad_tags = dict()
        errs_here = 0
        print(COLOR.colorize('\nVerifying equation tags', 'info'), end=' ')
        for filename in file_list:
            (found, errs) = check_old_eq_delim(filename)
            bad_tags = helpers.merge_dicts(found, bad_tags)
            errs_here += errs
            errCount += errs
        if errs_here > 0:
            print(PRINT_FAIL)
        for key, entry in bad_tags.items():
            if entry:
                print('{}\n{}'.format(key, PRINT_ERROR))
                for element in entry:
                    print('{}, '.format(element[0]), end='')
                print()
        if errs_here == 0:
            print(PRINT_OK)

    print('\n')
    ERRPRINT(errCount, completion=True)

    return (0)