Add simple_server.py as a script to make testing easier

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
This commit is contained in:
Vladimir Diaz 2017-02-15 15:07:36 -05:00
parent 38dada8a29
commit 7f8a6b16f0
No known key found for this signature in database
GPG key ID: 5DEE9B97B0E2289A
2 changed files with 60 additions and 1 deletions

View file

@ -109,6 +109,7 @@
packages = find_packages(exclude=['tests']),
scripts = [
'tuf/scripts/basic_client.py',
'tuf/scripts/tufcli.py'
'tuf/scripts/tufcli.py',
'tuf/scripts/simple_server.py'
]
)

58
tuf/scripts/simple_server.py Executable file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env python
"""
<Program>
simple_server.py
<Author>
Konstantin Andrianov.
<Started>
February 15, 2012.
<Copyright>
See LICENSE for licensing information.
<Purpose>
This is a basic server that was designed to be used in conjunction with
test_download.py to test download.py module.
<Reference>
SimpleHTTPServer:
http://docs.python.org/library/simplehttpserver.html#module-SimpleHTTPServer
"""
# Help with Python 3 compatibility, where the print statement is a function, an
# implicit relative import is invalid, and the '/' operator performs true
# division. Example: print 'hello world' raises a 'SyntaxError' exception.
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
import random
import six
PORT = 0
def _port_gen():
return random.randint(30000, 45000)
if len(sys.argv) > 1:
try:
PORT = int(sys.argv[1])
if PORT < 30000 or PORT > 45000:
raise ValueError
except ValueError:
PORT = _port_gen()
else:
PORT = _port_gen()
Handler = six.moves.SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = six.moves.socketserver.TCPServer(('', PORT), Handler)
httpd.serve_forever()