Compare commits

..

30 Commits

Author SHA1 Message Date
Matt Martz
cbdbab3d16 Print share results, when --share is specified 2014-04-30 09:10:03 -05:00
Matt Martz
3695acb020 Fix descriptors 2014-04-30 09:09:37 -05:00
Matt Martz
f689af0fc6 While we don't have to worry about python caching results since we aren't a browser, some proxies cause inconsistent results as they are caching requests 2014-04-30 08:46:36 -05:00
Matt Martz
44bc5d2bef Additionally, don't run callback if the shutdown_event is set 2014-04-29 19:21:55 -05:00
Matt Martz
557e662a6c Don't run callback if a callback is not set 2014-04-28 14:11:47 -05:00
Matt Martz
395553f089 s/args\.mini/url/ 2014-04-17 16:34:13 -05:00
Matt Martz
16b8aec1d7 Better testing using tox 2014-04-17 16:21:25 -05:00
Matt Martz
93e13b528f When using --mini and no extension is found, try all of the standard upload extensions. 2014-04-17 16:20:02 -05:00
Matt Martz
5cba294b76 Some fixes for python2.4 2014-04-17 10:16:39 -05:00
Matt Martz
dfeb19ff68 Speed and memory improvement for populating StringIO 2014-04-12 22:58:57 -04:00
Matt Martz
6888a5aae1 Use socket logic to determine proper number of threads for upload 2014-03-10 12:19:08 -05:00
Matt Martz
0e7160e8e6 Fix python3 issues 2014-03-10 12:18:47 -05:00
Matt Martz
5ec8fa590d document FakeShutdownEvent 2014-03-10 11:41:07 -05:00
Matt Martz
f009711526 docstring updates 2014-03-10 11:32:34 -05:00
Matt Martz
de594188e5 Move exception classes higher in the file 2014-03-10 11:28:22 -05:00
Matt Martz
989c440700 Add ability to handle upload timeout threshold by using a stream for post data 2014-03-10 11:25:09 -05:00
Matt Martz
d28c8f18b0 pep8 logic fix 2014-03-09 22:41:34 -05:00
Matt Martz
3c81acc96c Allow callback to print before and after download/upload, and prefix Uploader and Downloader with HTTP 2014-03-09 22:05:42 -05:00
Matt Martz
8f5faafada pep8 fix 2014-03-08 18:19:31 -06:00
Matt Martz
3ffb447210 s/tagName/tag_name/g 2014-03-08 18:10:42 -06:00
Matt Martz
1f16fb3cfe Use custom user agent 2014-03-08 18:10:22 -06:00
Matt Martz
71b456594f messages for upload/download reversed 2014-03-08 18:02:46 -06:00
Matt Martz
feb7f6bff1 pep8 spacing fix 2014-03-06 11:57:35 -06:00
Matt Martz
79c3a19792 Add support for --csv and --json arguments as output types 2014-03-06 11:54:31 -06:00
Matt Martz
3b29d5701d cast server id to int to be more consistent with the rest of the data 2014-02-28 12:23:36 -06:00
Matt Martz
9ef5620b58 Don't require people to explicitly perform all steps, retrieve servers if not already retrieved, select closest if not already selected 2014-02-28 12:17:22 -06:00
Matt Martz
b846f4dd88 Handle issues determining distance to test servers 2014-02-28 12:16:46 -06:00
Matt Martz
bab7a9d88e Create a Fake shutdown event so that users of the API are not required to register a shutdown event 2014-02-28 12:16:27 -06:00
Matt Martz
88565d5acd Huge refactor, too many changes to really address individually 2014-02-27 16:38:19 -06:00
Matt Martz
42bbc21546 lowercase with underscores and move arg parsing into it's own function 2014-02-26 20:54:48 -06:00
10 changed files with 1139 additions and 2229 deletions

View File

@ -1,54 +1,35 @@
language: python
addons:
apt:
sources:
- deadsnakes
packages:
- python2.4
- python2.5
- python2.6
- python3.2
- python3.3
python:
- 2.7
matrix:
include:
- python: 2.7
env: TOXENV=flake8
- python: 2.7
env: TOXENV=py24
- python: 2.7
env: TOXENV=py25
- python: 2.7
env: TOXENV=py26
- python: 2.7
env: TOXENV=py27
- python: 2.7
env: TOXENV=py32
- python: 2.7
env: TOXENV=py33
- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: pypy
env: TOXENV=pypy
env:
- TOXENV=py24
- TOXENV=py25
- TOXENV=py26
- TOXENV=py27
- TOXENV=py31
- TOXENV=py32
- TOXENV=py33
- TOXENV=py34
- TOXENV=pypy
- TOXENV=flake8
before_install:
- if [[ $(echo "$TOXENV" | egrep -c "py35") != 0 ]]; then pyenv global system 3.5; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py3[14])") != 0 ]]; then sudo add-apt-repository -y ppa:fkrull/deadsnakes; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py3[14])") != 0 ]]; then sudo apt-get update -qq; fi;
- if [[ "$TOXENV" == "py24" ]]; then sudo apt-get install -y python2.4; fi;
- if [[ "$TOXENV" == "py25" ]]; then sudo apt-get install -y python2.5; fi;
- if [[ "$TOXENV" == "py31" ]]; then sudo apt-get install -y python3.1; fi;
- if [[ "$TOXENV" == "py34" ]]; then sudo apt-get install -y python3.4; fi;
- if [[ "$TOXENV" == "pypy" ]]; then sudo apt-get install -y pypy; fi;
install:
- if [[ $(echo "$TOXENV" | egrep -c "py32") != 0 ]]; then pip install setuptools==17.1.1; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py3[12])") != 0 ]]; then pip install virtualenv==1.7.2 tox==1.3; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py26|py33)") != 0 ]]; then pip install virtualenv==15.2.0 tox==2.9.1; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py2[456]|py3[123])") == 0 ]]; then pip install tox; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py31)") != 0 ]]; then pip install virtualenv==1.7.2 tox==1.3; fi;
- if [[ $(echo "$TOXENV" | egrep -c "(py2[45]|py31)") == 0 ]]; then pip install tox; fi;
script:
- tox
- tox
notifications:
email:

View File

@ -1,34 +1,14 @@
# Pull Requests
## Pull requests should be
1. Made against the `devel` branch.
1. Made from a git feature branch.
## Pull requests will not be accepted that
1. Are not made against the `devel` branch
1. Are submitted from a branch named `devel`
1. Do not pass pep8/pyflakes/flake8
1. Do not work with Python 2.4-3.4 or pypy
1. Add python modules not included with the Python standard library
1. Are made by editing files via the GitHub website
Pull requests should be made against the `working` branch.
# Coding Guidelines
In general, I follow strict pep8 and pyflakes. All code must pass these tests. Since we support python 2.4-3.4 and pypy, pyflakes reports unknown names in python 3. pyflakes is run in python 2.7 only in my tests.
## Some other points
1. Do not use `\` for line continuations, long strings should be wrapped in `()`. Imports should start a brand new line in the form of `from foo import...`
1. String quoting should be done with single quotes `'`, except for situations where you would otherwise have to escape an internal single quote
1. Docstrings should use three double quotes `"""`
1. All functions, classes and modules should have docstrings following both the PEP257 and PEP8 standards
1. Inline comments should only be used on code where it is not immediately obvious what the code achieves
In general, I follow strict pep8 and pyflakes. All code must pass these tests. Since we support python 2.4-3.4, pyflakes reports unknown names in python 3. pyflakes is run in python 2.7 only in my tests.
# Supported Python Versions
All code needs to support Python 2.4-3.4 and pypy.
All code needs to support Python 2.4-3.4.
# Permitted Python Modules

View File

@ -1,31 +1,23 @@
#Usage
$ curl -s https://git.spectre5.com/adamcruz/speedtest-cli-pub/raw/branch/master/speedtest.py | python -
speedtest-cli
=============
Command line interface for testing internet bandwidth using
speedtest.net
.. image:: https://img.shields.io/pypi/v/speedtest-cli.svg
.. image:: https://pypip.in/v/speedtest-cli/badge.png
:target: https://pypi.python.org/pypi/speedtest-cli/
:alt: Latest Version
.. image:: https://img.shields.io/travis/sivel/speedtest-cli.svg
.. image:: https://pypip.in/d/speedtest-cli/badge.png
:target: https://pypi.python.org/pypi/speedtest-cli/
:alt: Travis
.. image:: https://img.shields.io/pypi/l/speedtest-cli.svg
:alt: Downloads
.. image:: https://pypip.in/license/speedtest-cli/badge.png
:target: https://pypi.python.org/pypi/speedtest-cli/
:alt: License
Versions
--------
speedtest-cli works with Python 2.4-3.7
.. image:: https://img.shields.io/pypi/pyversions/speedtest-cli.svg
:target: https://pypi.python.org/pypi/speedtest-cli/
:alt: Versions
speedtest-cli works with Python 2.4-3.4
Installation
------------
@ -62,14 +54,14 @@ Just download (Like the way it used to be)
::
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
wget -O speedtest-cli https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
chmod +x speedtest-cli
or
::
curl -Lo speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
curl -o speedtest-cli https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
chmod +x speedtest-cli
Usage
@ -78,78 +70,21 @@ Usage
::
$ speedtest-cli -h
usage: speedtest-cli [-h] [--no-download] [--no-upload] [--bytes] [--share]
[--simple] [--csv] [--csv-delimiter CSV_DELIMITER]
[--csv-header] [--json] [--list] [--server SERVER]
[--exclude EXCLUDE] [--mini MINI] [--source SOURCE]
[--timeout TIMEOUT] [--secure] [--no-pre-allocate]
[--version]
usage: speedtest-cli [-h] [--share] [--simple] [--list] [--server SERVER]
[--mini MINI] [--source SOURCE] [--version]
Command line interface for testing internet bandwidth using speedtest.net.
--------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli
optional arguments:
-h, --help show this help message and exit
--no-download Do not perform download test
--no-upload Do not perform upload test
--bytes Display values in bytes instead of bits. Does not
affect the image generated by --share, nor output from
--json or --csv
--share Generate and provide a URL to the speedtest.net share
results image, not displayed with --csv
--simple Suppress verbose output, only show basic information
--csv Suppress verbose output, only show basic information
in CSV format. Speeds listed in bit/s and not affected
by --bytes
--csv-delimiter CSV_DELIMITER
Single character delimiter to use in CSV output.
Default ","
--csv-header Print CSV headers
--json Suppress verbose output, only show basic information
in JSON format. Speeds listed in bit/s and not
affected by --bytes
--list Display a list of speedtest.net servers sorted by
distance
--server SERVER Specify a server ID to test against. Can be supplied
multiple times
--exclude EXCLUDE Exclude a server from selection. Can be supplied
multiple times
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers
--no-pre-allocate Do not pre allocate upload data. Pre allocation is
enabled by default to improve upload performance. To
support systems with insufficient memory, use this
option to avoid a MemoryError
--version Show the version number and exit
-h, --help show this help message and exit
--share Generate and provide a URL to the speedtest.net share
results image
--simple Suppress verbose output, only show basic information
--list Display a list of speedtest.net servers sorted by distance
--server SERVER Specify a server ID to test against
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--version Show the version number and exit
Python API
----------
See the `wiki <https://github.com/sivel/speedtest-cli/wiki>`_.
Inconsistency
-------------
It is not a goal of this application to be a reliable latency reporting tool.
Latency reported by this tool should not be relied on as a value indicative of ICMP
style latency. It is a relative value used for determining the lowest latency server
for performing the actual speed test against.
There is the potential for this tool to report results inconsistent with Speedtest.net.
There are several concepts to be aware of that factor into the potential inconsistency:
1. Speedtest.net has migrated to using pure socket tests instead of HTTP based tests
2. This application is written in Python
3. Different versions of Python will execute certain parts of the code faster than others
4. CPU and Memory capacity and speed will play a large part in inconsistency between
Speedtest.net and even other machines on the same network
Issues relating to inconsistencies will be closed as wontfix and without
additional reason or context.

View File

@ -1,2 +0,0 @@
[wheel]
universal=1

View File

@ -1,96 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2012-2018 Matt Martz
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import re
import codecs
import setuptools
from setuptools import setup
here = os.path.abspath(os.path.dirname(__file__))
# Read the version number from a source file.
# Why read it, and not import?
# see https://groups.google.com/d/topic/pypa-dev/0PkjVpcxTzQ/discussion
def find_version(*file_paths):
# Open in Latin-1 so that we avoid encoding errors.
# Use codecs.open for Python 2 compatibility
try:
f = codecs.open(os.path.join(here, *file_paths), 'r', 'latin1')
version_file = f.read()
f.close()
except:
raise RuntimeError("Unable to find version string.")
# The version line must have the form
# __version__ = 'ver'
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
# Get the long description from the relevant file
try:
f = codecs.open('README.rst', encoding='utf-8')
long_description = f.read()
f.close()
except:
long_description = ''
setup(
setuptools.setup(
name='speedtest-cli',
version=find_version('speedtest.py'),
version='0.2.5',
description=('Command line interface for testing internet bandwidth using '
'speedtest.net'),
long_description=long_description,
keywords='speedtest speedtest.net',
long_description=open('README.rst').read(),
author='Matt Martz',
author_email='matt@sivel.net',
url='https://github.com/sivel/speedtest-cli',
license='Apache License, Version 2.0',
py_modules=['speedtest'],
py_modules=['speedtest_cli'],
entry_points={
'console_scripts': [
'speedtest=speedtest:main',
'speedtest-cli=speedtest:main'
'speedtest=speedtest_cli:main',
'speedtest-cli=speedtest_cli:main'
]
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Environment :: Console',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Operating System :: OS Independent'
]
)

View File

@ -1,9 +1,9 @@
.TH "speedtest-cli" 1 "2018-01-05" "speedtest-cli"
.TH "speedtest-cli" 1 "2014-01-26" "speedtest-cli"
.SH NAME
speedtest\-cli \- Command line interface for testing internet bandwidth using speedtest.net
speedtest\-cli \- Test your bandwidth througput using speedtest.net
.SH SYNOPSIS
.B speedtest\-cli
[OPTION...]
[OPTION]...
.SH DESCRIPTION
Speedtest.net is a web service for testing your broadband connection by downloading a file
from a nearby speedtest.net server on the web. This tool allows you to access the service
@ -23,24 +23,9 @@ Displays usage for the tool.
.B Options
\fB\-\-no\-download\fR
.RS
Do not perform download test
.RE
\fB\-\-no\-upload\fR
.RS
Do not perform upload test
.RE
\fB\-\-bytes\fR
.RS
Display values in bytes instead of bits. Does not affect the image generated by \-\-share, nor output from \-\-json or \-\-csv
.RE
\fB\-\-share\fR
.RS
Generate and provide a URL to the speedtest.net share results image, not displayed with \-\-csv
Generate and provide a URL to the speedtest.net share results image
.RE
\fB\-\-simple\fR
@ -48,26 +33,6 @@ Generate and provide a URL to the speedtest.net share results image, not display
Suppress verbose output, only show basic information
.RE
\fB\-\-csv\fR
.RS
Suppress verbose output, only show basic information in CSV format. Speeds listed in bit/s and not affected by \-\-bytes
.RE
\fB\-\-csv\-delimiter CSV_DELIMITER\fR
.RS
Single character delimiter to use in CSV output. Default ","
.RE
\fB\-\-csv\-header\fR
.RS
Print CSV headers
.RE
\fB\-\-json\fR
.RS
Suppress verbose output, only show basic information in JSON format. Speeds listed in bit/s and not affected by \-\-bytes
.RE
\fB\-\-list\fR
.RS
Display a list of speedtest.net servers sorted by distance
@ -75,12 +40,7 @@ Display a list of speedtest.net servers sorted by distance
\fB\-\-server SERVER\fR
.RS
Specify a server ID to test against. Can be supplied multiple times
.RE
\fB\-\-exclude EXCLUDE\fR
.RS
Exclude a server from selection. Can be supplied multiple times
Specify a server ID to test against
.RE
\fB\-\-mini MINI\fR
@ -93,21 +53,6 @@ URL of the Speedtest Mini server
Source IP address to bind to
.RE
\fB\-\-timeout TIMEOUT\fR
.RS
HTTP timeout in seconds. Default 10
.RE
\fB\-\-secure\fR
.RS
Use HTTPS instead of HTTP when communicating with speedtest.net operated servers
.RE
\fB\-\-no\-pre\-allocate\fR
.RS
Do not pre allocate upload data. Pre allocation is enabled by default to improve upload performance. To support systems with insufficient memory, use this option to avoid a MemoryError
.RE
\fB\-\-version\fR
.RS
Show the version number and exit

File diff suppressed because it is too large Load Diff

1077
speedtest_cli.py Executable file

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2018 Matt Martz
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import sys
import subprocess
cmd = [sys.executable, 'speedtest.py', '--source', '127.0.0.1']
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = p.communicate()
if p.returncode != 1:
raise SystemExit('%s did not fail with exit code 1' % ' '.join(cmd))
if 'Invalid argument'.encode() not in stderr:
raise SystemExit(
'"Invalid argument" not found in stderr:\n%s' % stderr.decode()
)

12
tox.ini
View File

@ -4,22 +4,16 @@ skipsdist=true
[testenv]
commands =
{envpython} -V
{envpython} -m compileall speedtest.py
{envpython} speedtest.py
{envpython} speedtest.py --source 172.17.0.1
{envpython} tests/scripts/source.py
{envpython} speedtest_cli.py
[testenv:flake8]
basepython=python
deps=flake8
commands =
{envpython} -V
flake8 speedtest.py
flake8 speedtest_cli.py
[testenv:pypy]
commands =
pypy -V
pypy -m compileall speedtest.py
pypy speedtest.py
pypy speedtest.py --source 172.17.0.1
pypy tests/scripts/source.py
pypy speedtest_cli.py