Skip to content

Commit

Permalink
WIP, see CHANGES.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
ssteinerx committed Jun 23, 2017
1 parent ce0c151 commit d88a969
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ June 21, 2017 -- ssteinerX
WORK IN PROGRESS...

* Add CHANGES.txt (this file)
* Add TODO.txt
* Remove Python 3.1, 3.2, and 3.3 from tests. Versions are obsolete and are no longer supported.
* Add travis.yml
* Add Travis support & badge in README.rst
* Update GitHub page & maintainer info
*
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Yay, Travis status:
.. image:: https://travis-ci.org/ssteinerx/pingparser.svg?branch=master
:target: https://travis-ci.org/ssteinerx/pingparser


Usage
~~~~~
You can pipe ping command output into pingparser.py on the command line, which
Expand Down
19 changes: 19 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ToDo: June 22, 2017
-------------------
pingparser.py:

> Consolidate `format_replacements`, currently a list of tuples, then
duplicated in return statement of parse() function.

Make it an ordered dict and use it to build `default_format` and
JSON return value.

`default_format` should only be built JIT since it's not used when:
* pingparser is used as a library (i.e. when just calling parse() on results).
* when different formatting is given on the command line

> NOTE: pulled from my (ssteinerX) inline comments. Not sure exactly what I meant...it's not specific enough, but says:
"Make `minmax_matcher` more specific i.e. match a bit before the '=' sign"

> Completely remove "+" parameter formatting.
See related NOTE:s in pingparser.py near text: "+...format string"
31 changes: 17 additions & 14 deletions pingparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Parses the output of the system ping command.
"""
__version__ = '0.4'
__version__ = '0.5'

from optparse import OptionGroup, OptionParser

Expand All @@ -12,7 +12,6 @@

__all__ = ["parse",
"format_ping_result",
"main",
]

# Pull regex compilation out of parser() so it only gets done once
Expand All @@ -31,7 +30,6 @@
rslt_matcher = re.compile(r'(\d+) packets transmitted, (\d+) (?:packets )?received, (\d+\.?\d*)% packet loss')

# Pull out round-trip min/avg/max/stddev = 49.042/49.042/49.042/0.000 ms
# TODO: make this more specific i.e. match a bit before the '=' sign
minmax_matcher = re.compile(r'(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)')

# Available replacements
Expand Down Expand Up @@ -123,18 +121,22 @@ def main(argv=sys.argv):
# parser.add_option("+", dest="format",
# help="optional format string")

format_group = OptionGroup(parser,
"""FORMAT controls the output. Interpreted sequences are:
\t%h host name or IP address
\t%s packets sent
\t%r packets received
\t%p packet_loss
\t%m minimum ping in milliseconds
\t%a average ping in milliseconds
\t%M maximum ping in milliseconds
\t%j jitter in milliseconds
format_group = OptionGroup(
parser,
"""
FORMAT controls the output. Interpreted sequences are:
Default FORMAT is: """ + default_format)
\t%h host name or IP address
\t%s packets sent
\t%r packets received
\t%p packet_loss
\t%m minimum ping in milliseconds
\t%a average ping in milliseconds
\t%M maximum ping in milliseconds
\t%j jitter in milliseconds
Default FORMAT is: """ + default_format
)

parser.add_option_group(format_group)
(options, args) = parser.parse_args()
Expand Down Expand Up @@ -176,6 +178,7 @@ def main(argv=sys.argv):

sys.exit(0)


if __name__ == "__main__":
try:
main(sys.argv)
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ author = Gregg Gajic
author_email = [email protected]
summary = Parses the output of the system ping command.
description-file = README.rst
home_page = https://github.com/gg/pingparser
home_page = https://github.com/ssteinerx/pingparser
project_url =
Source repository,https://github.com/gg/pingparser
Source repository,https://github.com/ssteinerx/pingparser
license = UNLICENSE
maintainer = Steve Steiner
maintainer-email = [email protected]
Expand Down

0 comments on commit d88a969

Please sign in to comment.