Compare commits

..

7 Commits

Author SHA1 Message Date
Sebastian Lohff f2594c2adf Release v0.5.0 2020-09-30 01:28:48 +02:00
Sebastian Lohff 95852ba11d Change project url to GitHub 2020-09-30 01:12:53 +02:00
Sebastian Lohff 14771695c4 Add README.md 2020-09-30 01:12:53 +02:00
Sebastian Lohff 5c78991bc8 Advertise python3.5 support
For now we don't break compability with python3.5, so why not advertise
it!
2020-09-29 22:13:30 +02:00
Sebastian Lohff ef41f65996 Workaround for python2 deprecation in tests
When checking the version the test now gets a
CryptographyDeprecationWarning plus an import code line instead of the
version. As a workaround we now ignore the first two lines when checking
for the version string.
2020-09-07 00:31:10 +02:00
Sebastian Lohff 19c1b000a4 Make servefile a python package
servefile is now a valid python package. The single servefile.py can
still be used as a script by just putting it into PATH and making it
executable. Additionally when installed via pip a wrapper script is
created, calling the module's main(). python -m servefile works as well.
2020-09-07 00:26:20 +02:00
Sebastian Lohff 3d46950d6c Use spaces instead of tabs for setup.py 2020-09-06 23:26:49 +02:00
8 changed files with 127 additions and 46 deletions

View File

@ -1,6 +1,19 @@
servefile changelog servefile changelog
=================== ===================
2020-10-29 v0.5.0
-----------------
0.5.0 released
* python3 support
* test suite
* fixed an endless redirect loop when serving ../
* added sorting for list view
* added lzma/xz as compression method
2015-11-10 v0.4.4 2015-11-10 v0.4.4
----------------- -----------------

33
README.md Normal file
View File

@ -0,0 +1,33 @@
Servefile
=========
Serve files from shell via a small HTTP server. The server redirects all HTTP
requests to the file, so only IP and port must be given to another user to
access the file. Its main purpose is to quickly send a file to users in your
local network, independent of their current setup (OS/software). Besides that
it also supports uploads, SSL, HTTP basic auth and directory listings.
Features:
* serve single file
* serve a directory with directory index
* file upload via webinterface
* HTTPS with on the fly generated self signed SSL certificates
* HTTP basic authentication
* serving files/directories as on request generated tar files
Install
-------
Via pip
```shell
pip install servefile
```
After installation either execute `servefile --help` or `python -m servefile --help`
Standalone:
If you don't have pip available just copy `servefile/servefile.py` onto the target machine, make it executable and you are ready to go.
```shell
$ wget https://raw.githubusercontent.com/sebageek/servefile/master/servefile/servefile.py -O servefile
$ chmod +x servefile
$ ./servefile --help
```

View File

@ -1,4 +1,4 @@
.TH SERVEFILE 1 "November 2015" "servefile 0.4.4" "User Commands" .TH SERVEFILE 1 "September 2020" "servefile 0.5.0" "User Commands"
.SH NAME .SH NAME
servefile \- small HTTP-Server for temporary file transfer servefile \- small HTTP-Server for temporary file transfer

0
servefile/__init__.py Normal file
View File

3
servefile/__main__.py Normal file
View File

@ -0,0 +1,3 @@
from . import servefile
servefile.main()

View File

@ -7,7 +7,7 @@
from __future__ import print_function from __future__ import print_function
__version__ = '0.4.4' __version__ = '0.5.0'
import argparse import argparse
import base64 import base64
@ -1109,7 +1109,7 @@ class AuthenticationHandler():
def main(): def main():
parser = argparse.ArgumentParser(description='Serve a single file via HTTP.') parser = argparse.ArgumentParser(prog='servefile', description='Serve a single file via HTTP.')
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('target', metavar='file/directory', type=str) parser.add_argument('target', metavar='file/directory', type=str)
parser.add_argument('-p', '--port', type=int, default=8080, \ parser.add_argument('-p', '--port', type=int, default=8080, \

View File

@ -1,15 +1,19 @@
#!/usr/bin/python #!/usr/bin/env python
from setuptools import setup from setuptools import setup
with open("README.md") as f:
long_description = f.read()
setup( setup(
name='servefile', name='servefile',
description='Serve files from shell via a small HTTP server', description='Serve files from shell via a small HTTP server',
long_description='Serve files from shell via a small HTTP server. The server redirects all HTTP requests to the file, so only IP and port must be given to another user to access the file. Its main purpose is to quickly send a file to users in your local network, independent of their current setup (OS/software). Beneath that it also supports uploads, SSL, HTTP basic auth and directory listings.', long_description=long_description,
long_description_content_type='text/markdown',
platforms='posix', platforms='posix',
version='0.4.4', version='0.5.0',
license='GPLv3 or later', license='GPLv3 or later',
url='https://seba-geek.de/stuff/servefile/', url='https://github.com/sebageek/servefile/',
author='Sebastian Lohff', author='Sebastian Lohff',
author_email='seba@someserver.de', author_email='seba@someserver.de',
install_requires=['pyopenssl'], install_requires=['pyopenssl'],
@ -18,7 +22,12 @@ setup(
'pytest', 'pytest',
'requests', 'requests',
], ],
scripts=['servefile'], packages=["servefile"],
entry_points={
"console_scripts": [
"servefile = servefile.servefile:main",
],
},
classifiers=[ classifiers=[
'Development Status :: 5 - Production/Stable', 'Development Status :: 5 - Production/Stable',
'Environment :: Console', 'Environment :: Console',
@ -29,6 +38,7 @@ setup(
'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.8',

View File

@ -27,9 +27,15 @@ def run_servefile():
def _run_servefile(args, **kwargs): def _run_servefile(args, **kwargs):
if not isinstance(args, list): if not isinstance(args, list):
args = [args] args = [args]
print("running with args", args) if kwargs.pop('standalone', None):
servefile_path = str(Path(__file__).parent.parent / 'servefile') # directly call servefile.py
p = subprocess.Popen([sys.executable, servefile_path] + args, **kwargs) servefile_path = [str(Path(__file__).parent.parent / 'servefile' / 'servefile.py')]
else:
# call servefile as python module
servefile_path = ['-m', 'servefile']
print("running {} with args {}".format(", ".join(servefile_path), args))
p = subprocess.Popen([sys.executable] + servefile_path + args, **kwargs)
time.sleep(kwargs.get('timeout', 0.3)) time.sleep(kwargs.get('timeout', 0.3))
instances.append(p) instances.append(p)
@ -85,14 +91,29 @@ def check_download(expected_data=None, path='/', fname=None, status_code=200, **
return r # for additional tests return r # for additional tests
def test_version(run_servefile): def _test_version(run_servefile, standalone):
# we expect the version on stdout (python3.4+) or stderr(python2.6-3.3) # we expect the version on stdout (python3.4+) or stderr(python2.6-3.3)
s = run_servefile('--version', stdout=subprocess.PIPE, stderr=subprocess.STDOUT) s = run_servefile('--version', standalone=standalone, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
s.wait() s.wait()
version = s.stdout.readline().decode().strip() version = s.stdout.readline().decode().strip()
# python2 is deprecated, but we still want our tests to run for it
# CryptographyDeprecationWarnings get in the way for this
if 'CryptographyDeprecationWarning' in version:
s.stdout.readline() # ignore "from x import y" line
version = s.stdout.readline().decode().strip()
# hardcode version as string until servefile is a module # hardcode version as string until servefile is a module
assert version == 'servefile 0.4.4' assert version == 'servefile 0.5.0'
def test_version(run_servefile):
_test_version(run_servefile, standalone=False)
def test_version_standalone(run_servefile):
# test if servefile also works by calling servefile.py directly
_test_version(run_servefile, standalone=True)
def test_correct_headers(run_servefile, datadir): def test_correct_headers(run_servefile, datadir):
@ -325,6 +346,7 @@ def test_https(run_servefile, datadir):
urllib3.disable_warnings() urllib3.disable_warnings()
check_download(data, protocol='https', verify=False) check_download(data, protocol='https', verify=False)
def test_https_big_download(run_servefile, datadir): def test_https_big_download(run_servefile, datadir):
# test with about 10 mb of data # test with about 10 mb of data
data = "x" * (10 * 1024 ** 2) data = "x" * (10 * 1024 ** 2)