mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
cli: improve wayback cli to take optional port, threads and working dir arguments
switch to waitress as default WSGI server instead of wsgiref
This commit is contained in:
parent
6a9a09d602
commit
e8db31d066
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1,4 +1,7 @@
|
|||||||
*.arc -text
|
*.arc -text
|
||||||
*.warc -text
|
*.warc -text
|
||||||
|
*.idx -text
|
||||||
|
*.idxj -text
|
||||||
*.cdx -text
|
*.cdx -text
|
||||||
|
*.cdxj -text
|
||||||
*.gz -text
|
*.gz -text
|
||||||
|
32
pywb/apps/cli.py
Normal file
32
pywb/apps/cli.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#=================================================================
|
||||||
|
def wayback(args=None):
|
||||||
|
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||||
|
|
||||||
|
parser = ArgumentParser('pywb Wayback Web Archive Replay')
|
||||||
|
parser.add_argument('-p', '--port', type=int, default=8080)
|
||||||
|
parser.add_argument('-t', '--threads', type=int, default=4)
|
||||||
|
|
||||||
|
help_dir='Specify root archive dir (default is current working directory)'
|
||||||
|
parser.add_argument('-d', '--directory', help=help_dir)
|
||||||
|
|
||||||
|
r = parser.parse_args(args)
|
||||||
|
if r.directory: #pragma: no cover
|
||||||
|
import os
|
||||||
|
os.chdir(r.directory)
|
||||||
|
|
||||||
|
# Load App
|
||||||
|
from pywb.apps.wayback import application
|
||||||
|
|
||||||
|
try:
|
||||||
|
from waitress import serve
|
||||||
|
serve(application, port=r.port, threads=r.threads)
|
||||||
|
except ImportError: # pragma: no cover
|
||||||
|
# Shouldn't ever happen as installing waitress, but just in case..
|
||||||
|
from pywb.framework.wsgi_wrappers import start_wsgi_server
|
||||||
|
start_wsgi_server(application, 'Wayback', default_port=r.port)
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================================
|
||||||
|
if __name__ == "__main__":
|
||||||
|
wayback()
|
||||||
|
|
@ -1,14 +1,8 @@
|
|||||||
from pywb.framework.wsgi_wrappers import init_app, start_wsgi_server
|
from pywb.framework.wsgi_wrappers import init_app
|
||||||
from pywb.webapp.pywb_init import create_wb_router
|
from pywb.webapp.pywb_init import create_wb_router
|
||||||
|
|
||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
# init pywb app
|
# init pywb app
|
||||||
#=================================================================
|
#=================================================================
|
||||||
application = init_app(create_wb_router, load_yaml=True)
|
application = init_app(create_wb_router, load_yaml=True)
|
||||||
|
|
||||||
|
|
||||||
def main(): # pragma: no cover
|
|
||||||
start_wsgi_server(application, 'Wayback')
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
@ -55,6 +55,10 @@ directory structure expected by pywb
|
|||||||
|
|
||||||
def list_colls(self):
|
def list_colls(self):
|
||||||
print('Collections:')
|
print('Collections:')
|
||||||
|
if not os.path.isdir(self.colls_dir):
|
||||||
|
msg = ('"Collections" directory not found. ' +
|
||||||
|
'To create a new collection, run:\n\n{0} init <name>')
|
||||||
|
raise IOError(msg.format(sys.argv[0]))
|
||||||
for d in os.listdir(self.colls_dir):
|
for d in os.listdir(self.colls_dir):
|
||||||
if os.path.isdir(os.path.join(self.colls_dir, d)):
|
if os.path.isdir(os.path.join(self.colls_dir, d)):
|
||||||
print('- ' + d)
|
print('- ' + d)
|
||||||
@ -87,8 +91,9 @@ directory structure expected by pywb
|
|||||||
|
|
||||||
def _assert_coll_exists(self):
|
def _assert_coll_exists(self):
|
||||||
if not os.path.isdir(self.curr_coll_dir):
|
if not os.path.isdir(self.curr_coll_dir):
|
||||||
raise IOError('Collection {0} does not exist'.
|
msg = ('Collection {0} does not exist. ' +
|
||||||
format(self.coll_name))
|
'To create a new collection, run\n\n{1} init {0}')
|
||||||
|
raise IOError(msg.format(self.coll_name, sys.argv[0]))
|
||||||
|
|
||||||
def add_warcs(self, warcs):
|
def add_warcs(self, warcs):
|
||||||
if not os.path.isdir(self.archive_dir):
|
if not os.path.isdir(self.archive_dir):
|
||||||
@ -466,7 +471,6 @@ def main_wrap_exc(): #pragma: no cover
|
|||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise
|
|
||||||
print('Error: ' + str(e))
|
print('Error: ' + str(e))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
3
setup.py
3
setup.py
@ -75,6 +75,7 @@ setup(
|
|||||||
'surt',
|
'surt',
|
||||||
'pyyaml',
|
'pyyaml',
|
||||||
'youtube_dl',
|
'youtube_dl',
|
||||||
|
'waitress',
|
||||||
'watchdog'
|
'watchdog'
|
||||||
],
|
],
|
||||||
tests_require=[
|
tests_require=[
|
||||||
@ -88,7 +89,7 @@ setup(
|
|||||||
test_suite='',
|
test_suite='',
|
||||||
entry_points="""
|
entry_points="""
|
||||||
[console_scripts]
|
[console_scripts]
|
||||||
wayback = pywb.apps.wayback:main
|
wayback = pywb.apps.cli:wayback
|
||||||
cdx-server = pywb.apps.cdx_server:main
|
cdx-server = pywb.apps.cdx_server:main
|
||||||
cdx-indexer = pywb.warc.cdxindexer:main
|
cdx-indexer = pywb.warc.cdxindexer:main
|
||||||
live-rewrite-server = pywb.apps.live_rewrite_server:main
|
live-rewrite-server = pywb.apps.live_rewrite_server:main
|
||||||
|
@ -70,6 +70,13 @@ class TestManagedColls(object):
|
|||||||
def _get_sample_warc(self, name):
|
def _get_sample_warc(self, name):
|
||||||
return os.path.join(get_test_dir(), 'warcs', name)
|
return os.path.join(get_test_dir(), 'warcs', name)
|
||||||
|
|
||||||
|
@patch('waitress.serve', lambda *args, **kwargs: None)
|
||||||
|
def test_run_cli(self):
|
||||||
|
""" test new wayback cli interface
|
||||||
|
"""
|
||||||
|
from pywb.apps.cli import wayback
|
||||||
|
wayback([])
|
||||||
|
|
||||||
def test_create_first_coll(self):
|
def test_create_first_coll(self):
|
||||||
""" Test first collection creation, with all required dirs
|
""" Test first collection creation, with all required dirs
|
||||||
"""
|
"""
|
||||||
@ -561,6 +568,10 @@ class TestManagedColls(object):
|
|||||||
|
|
||||||
shutil.rmtree(colls)
|
shutil.rmtree(colls)
|
||||||
|
|
||||||
|
# No Collections to list
|
||||||
|
with raises(IOError):
|
||||||
|
main(['list'])
|
||||||
|
|
||||||
# No Collections
|
# No Collections
|
||||||
self._create_app()
|
self._create_app()
|
||||||
resp = self.testapp.get('/test/', status=404)
|
resp = self.testapp.get('/test/', status=404)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user