Skip to content

Commit

Permalink
summary print
Browse files Browse the repository at this point in the history
  • Loading branch information
digitronik committed Oct 29, 2019
1 parent 6d27382 commit 0960c24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ Options:
--help Show this message and exit.
```

![linkstatus](https://user-images.githubusercontent.com/11618054/67754970-5a930d80-fa5d-11e9-851c-afd38147cf28.png)
![linkstatus](https://user-images.githubusercontent.com/11618054/67764478-0fcec100-fa70-11e9-9c3c-04c1f432f620.png)



**Note: Skip `link` check for any line by adding `noqa` (no quality assurance) as inline comment
**Note: Skip link check for any line by adding `noqa` (no quality assurance) as inline comment
.** like `<-- noqa -->` for `html` and `markdown`, `#noqa` for `python` etc...
26 changes: 20 additions & 6 deletions linkstatus/linkstatus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import glob
import os
from shutil import get_terminal_size

import click
import requests
Expand Down Expand Up @@ -52,6 +53,10 @@ def all_files(source, recursive=False):
@click.option("-rt", "--retry", default=2, help="Retry link status (default 2 time)")
def main(source, recursive, timeout, retry):
exit_code = 0
up_count = 0
down_count = 0
skip_count = 0

files = all_files(source, recursive=recursive)

for f in files:
Expand All @@ -63,6 +68,7 @@ def main(source, recursive, timeout, retry):
for link in links:
for url in link.urls:
if link.skip:
skip_count += 1
click.echo(
"{icon} L{ln} : {url} (skip)".format(
icon=click.style("…", fg="blue", bold=True),
Expand All @@ -80,10 +86,12 @@ def main(source, recursive, timeout, retry):
if status:
fg = "green"
icon = "✓"
up_count += 1
else:
fg = "red"
icon = "✗"
exit_code = 1
down_count += 1

click.echo(
"{icon} L{ln} : {url} {code}".format(
Expand All @@ -94,13 +102,19 @@ def main(source, recursive, timeout, retry):
)
)

# Print summary
columns = get_terminal_size().columns
click.echo("=" * columns)
click.echo(click.style("Links Status Summary".center(columns), bold=True))
click.echo(click.style("Links UP: {}".format(up_count).center(columns), fg="green"))
click.echo(click.style("Links SKIP: {}".format(skip_count).center(columns), fg="blue"))
click.echo(click.style("Links DOWN: {}".format(down_count).center(columns), fg="red"))

if exit_code == 1:
click.echo(
click.style(
"Warning: Use `noqa` inline comment to skip link check. "
"like, response code 403 due to header restrictions etc...",
fg="red",
bold=True,
)
"Warning: Use `noqa` inline comment to skip link check. "
"like, response code 403 due to header restrictions etc..."
)

click.echo("=" * columns)
exit(exit_code)

0 comments on commit 0960c24

Please sign in to comment.