Compare commits

..

11 commits

Author SHA1 Message Date
Tobias Schmidl
e1d2ed9990 fixup! Extended type annotations 2019-07-19 06:58:24 +02:00
Tobias Schmidl
fde2556e47 added pylama.ini, extended style.yapf 2019-07-19 06:54:59 +02:00
Tobias Schmidl
1dd63d542e Extended type annotations 2019-07-19 06:54:40 +02:00
Tobias Schmidl
9a096252c4 added first draft 2019-06-13 05:45:09 +02:00
Tobias Schmidl
1278ad984c incorporated some of the findings of pylint 2019-06-13 05:23:35 +02:00
Tobias Schmidl
3fa40d3371 Added yapf config, applied yapf 2019-06-13 04:17:07 +02:00
Tobias Schmidl
9a4c15f533 Replace the if switch with a lambda and a for loop 2018-06-13 15:54:17 +02:00
Tobias Schmidl
51d6d25aa9 moved ping.1m+.py --> httping.py 2018-06-13 08:48:50 +02:00
Tobias Schmidl
a7a2eaab96 Added requirements 2018-06-13 08:47:42 +02:00
Tobias Schmidl
21f99d3c03 Added metadata for bitbar 2018-06-13 08:46:34 +02:00
Tobias Schmidl
01f6b58c4d Added ping.1m+.py 2018-06-13 07:59:34 +02:00
7 changed files with 167 additions and 46 deletions

1
.gitignore vendored
View file

@ -1 +0,0 @@
.pscaffold/.gitignore

106
.gitignore vendored Normal file
View file

@ -0,0 +1,106 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
/tags
/tags.*

View file

@ -1,22 +0,0 @@
image: python
test:pylama:
stage: test
only:
- master
- develop
before_script:
- if test -r requirements.txt; then pip install -r requirements.txt; fi
script:
if test -x "$(which pylama)"; then pylama *.py; fi
test:pytest:
stage: test
only:
- master
- develop
before_script:
- if test -r requirements.txt; then pip install -r requirements.txt; fi
script:
if test -x "$(which pytest)"; then pytest .; fi

3
.gitmodules vendored
View file

@ -1,3 +0,0 @@
[submodule ".pscaffold"]
path = .pscaffold
url = ../pscaffold.git

@ -1 +0,0 @@
Subproject commit bc09b49a828808ea9c0b42f80af0b06f90e207cc

View file

@ -1 +0,0 @@
.pscaffold/.style.yapf

33
.style.yapf Normal file
View file

@ -0,0 +1,33 @@
[style]
# Insert a blank line before a module docstring.
blank_line_before_module_docstring=True
# The column limit.
column_limit=120
# Split before the '.' if we need to split a longer expression:
#
# foo = ('This is a really long string: {}, {}, {}, {}'.format(a, b, c, d))
#
# would reformat to something like:
#
# foo = ('This is a really long string: {}, {}, {}, {}'
# .format(a, b, c, d))
split_before_dot=True
# Set to True to split list comprehensions and generators that have
# non-trivial expressions and multiple clauses before each of these
# clauses. For example:
#
# result = [
# a_long_var + 100 for a_long_var in xrange(1000)
# if a_long_var % 10]
#
# would reformat to something like:
#
# result = [
# a_long_var + 100
# for a_long_var in xrange(1000)
# if a_long_var % 10]
split_complex_comprehension=True

View file

@ -1,35 +1,35 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Simulates httping for `argos <https://github.com/p-e-w/argos>`.""" """ Simulates httping for `argos <https://github.com/p-e-w/argos>`"""
# <bitbar.title>httping</bitbar.title> # <bitbar.title>httping</bitbar.title>
# <bitbar.version>v1.0</bitbar.version> # <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Tobias Schmidl</bitbar.author> # <bitbar.author>Tobias Schmidl</bitbar.author>
# <bitbar.author.github>schtobia</bitbar.author.github> # <bitbar.author.github>schtobia</bitbar.author.github>
# <bitbar.desc>Simulates httping.</bitbar.desc> # <bitbar.desc>Short description of what your plugin does.</bitbar.desc>
# <bitbar.image></bitbar.image> # <bitbar.image></bitbar.image>
# <bitbar.dependencies>python,requests</bitbar.dependencies> # <bitbar.dependencies>python,requests</bitbar.dependencies>
# <bitbar.abouturl>https://gitlab.com/schtobia/argos-httping/blob/master/httping.py</bitbar.abouturl> # <bitbar.abouturl>https://github.com/schtobia/argos-httping/blob/master/httping.py</bitbar.abouturl>
from __future__ import annotations from __future__ import annotations
import datetime # for the whole ms → s and vice versa stuff import datetime # for the whole ms → s and vice versa stuff
import statistics # for median and stdev import statistics # for median and stdev
import sys # for redirecting print to stderr import sys # for redirecting print to stderr
from typing import Dict, List, Optional, Tuple from typing import Generic, List, Sequence, TypeVar, Optional, Tuple, Dict, Union
import requests # for the central HTTP HEAD request import requests # for the central HTTP HEAD request
__author__ = "Tobias Schmidl" __author__ = "Tobias Schmidl"
__copyright__ = "Copyright 2021, Tobias Schmidl" __copyright__ = "Copyright 2018, Tobias Schmidl"
__license__ = "MIT" __license__ = "MIT"
__version__ = "1.0" __version__ = "0.0.1"
__maintainer__ = "Tobias Schmidl" __maintainer__ = "Tobias Schmidl"
MAX_PING: datetime.timedelta = datetime.timedelta(milliseconds=1000) # in seconds MAX_PING: datetime.timedelta = datetime.timedelta(milliseconds=1000) # in seconds
TARGETS: List[str] = ["https://www.google.de", "https://www.bing.com", "https://www.wikipedia.org"] TARGETS: List[str] = ["https://www.google.de", "https://www.bing.com", "https://www.wikipedia.org"]
T = TypeVar('T')
Bucket = Tuple[int, int] Bucket = Tuple[int, int]
BucketList = List[Bucket] BucketList = List[Bucket]
@ -37,18 +37,17 @@ MAX_PING_IN_MS: int = int(MAX_PING.total_seconds() * 1000)
def in_bucket(element: int, bucket: Bucket) -> bool: def in_bucket(element: int, bucket: Bucket) -> bool:
"""Return True if element is in bucket.""" """ Returns True if element is in bucket """
return bucket[0] <= element <= bucket[1] return bucket[0] <= element <= bucket[1]
def generate_buckets(min_val: int, max_val: int, step_width: int = 2) -> BucketList: def generate_buckets(min_val: int, max_val: int, step_width: int = 2) -> BucketList:
"""Generate a list of partitioned lists between min_val and max_val.""" """ Generates a list of partitioned lists between min_val and max_val."""
return [(x, x + step_width - 1) for x in range(min_val, max_val, step_width)] return [(x, x + step_width - 1) for x in range(min_val, max_val, step_width)]
class Themes: class Themes:
"""Maintain a list of themes and generates buckets between 0 and MAX_PING_IN_MS based on the selected theme.""" """Maintains a list of themes and generates buckets between 0 and MAX_PING_IN_MS based on the selected theme."""
# Themes are from http://colorbrewer2.org/ # Themes are from http://colorbrewer2.org/
purple_green: List[str] = ["#762a83", "#9970ab", "#c2a5cf", "#a6dba0", "#5aae61", "#1b7837"] purple_green: List[str] = ["#762a83", "#9970ab", "#c2a5cf", "#a6dba0", "#5aae61", "#1b7837"]
red_green: List[str] = ["#d73027", "#fc8d59", "#fee08b", "#d9ef8b", "#91cf60", "#1a9850"] red_green: List[str] = ["#d73027", "#fc8d59", "#fee08b", "#d9ef8b", "#91cf60", "#1a9850"]
@ -57,7 +56,6 @@ class Themes:
buckets: BucketList = [] buckets: BucketList = []
def __init__(self, selected_colors): def __init__(self, selected_colors):
"""Initialize class with a selected theme."""
self.selected_colors = selected_colors self.selected_colors = selected_colors
self.buckets = generate_buckets(0, int(MAX_PING_IN_MS), int(MAX_PING_IN_MS / (len(selected_colors) - 1))) self.buckets = generate_buckets(0, int(MAX_PING_IN_MS), int(MAX_PING_IN_MS / (len(selected_colors) - 1)))
@ -94,16 +92,14 @@ def httping(targets: List[str]) -> Tuple[Dict[str, Optional[float]], Optional[fl
if __name__ == "__main__": if __name__ == "__main__":
responses, median, stddev = httping(TARGETS) responses, median, stddev = httping(TARGETS)
if isinstance(median, float) and median != MAX_PING_IN_MS: if isinstance(median, float) and median != MAX_PING_IN_MS:
print("⦿ | color=" + CURRENT_THEME.colorize(median)) # type: ignore print("⦿ " + str(round(median, 2)) + "±" + str(round(stddev, 2)) + " | color=" +
CURRENT_THEME.colorize(median)) # type: ignore
else: else:
print("☠ | color=" + CURRENT_THEME.selected_colors[0]) print("☠ | color=" + CURRENT_THEME.selected_colors[0])
print("---") print("---")
for current_host, current_response in responses.items(): for current_host, current_response in responses.items():
if isinstance(current_response, float): if isinstance(current_response, float):
print(current_host + ": " + str(round(current_response, 2)) + " | color=" + print(current_host + ": " + str(round(current_response, 2)) + " | color=" +
CURRENT_THEME.colorize(current_response) + " | bash=\"httping -K " + current_host + "\"") CURRENT_THEME.colorize(current_response))
else: else:
print(current_host + ": ☠ | color=" + CURRENT_THEME.selected_colors[0]) print(current_host + ": ☠ | color=" + CURRENT_THEME.selected_colors[0])
print("---")
print("Average: " + str(round(median, 2)) + "±" + str(round(stddev, 2)) + " | color=" +
CURRENT_THEME.colorize(median))

View file

@ -1 +0,0 @@
.pscaffold/pylama.ini

15
pylama.ini Normal file
View file

@ -0,0 +1,15 @@
[pylama]
format = pylint
linters = mccabe,pep257,pydocstyle,pep8,pycodestyle,pyflakes,pylint,isort,mypy
ignore = D203
skip=.env/*
[pylama:pycodestyle]
max_line_length = 120
[pylama:pep8]
max_line_length = 120
[pylama:pylint]
max_line_length = 120