mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
https://github.com/internetarchive/warcprox/issues/9 record warcprox version in warcinfo metadata, and add --version command line option
This commit is contained in:
parent
b434e33fdd
commit
16f21b2e76
24
setup.py
24
setup.py
@ -5,6 +5,26 @@ from setuptools.command.test import test as TestCommand
|
||||
import sys
|
||||
import setuptools
|
||||
|
||||
VERSION_BYTES = b'1.3'
|
||||
|
||||
def full_version_bytes():
|
||||
import subprocess, time
|
||||
try:
|
||||
commit_bytes = subprocess.check_output(['git', 'log', '-1', '--pretty=format:%h'])
|
||||
|
||||
t_bytes = subprocess.check_output(['git', 'log', '-1', '--pretty=format:%ct'])
|
||||
t = int(t_bytes.strip().decode('utf-8'))
|
||||
tm = time.gmtime(t)
|
||||
timestamp_utc = time.strftime("%Y%m%d%H%M%S", time.gmtime(t))
|
||||
return VERSION_BYTES + b'-' + timestamp_utc.encode('utf-8') + b'-' + commit_bytes.strip()
|
||||
except subprocess.CalledProcessError:
|
||||
return VERSION_BYTES
|
||||
|
||||
version_bytes = full_version_bytes()
|
||||
with open('warcprox/version.txt', 'wb') as out:
|
||||
out.write(version_bytes)
|
||||
out.write(b'\n');
|
||||
|
||||
# special class needs to be added to support the pytest written dump-anydbm tests
|
||||
class PyTest(TestCommand):
|
||||
def finalize_options(self):
|
||||
@ -17,9 +37,8 @@ class PyTest(TestCommand):
|
||||
errno = pytest.main(self.test_args)
|
||||
sys.exit(errno)
|
||||
|
||||
|
||||
setuptools.setup(name='warcprox',
|
||||
version='1.2',
|
||||
version=version_bytes.decode('utf-8'),
|
||||
description='WARC writing MITM HTTP/S proxy',
|
||||
url='https://github.com/internetarchive/warcprox',
|
||||
author='Noah Levitt',
|
||||
@ -27,6 +46,7 @@ setuptools.setup(name='warcprox',
|
||||
long_description=open('README.rst').read(),
|
||||
license='GPL',
|
||||
packages=['warcprox'],
|
||||
package_data={'warcprox':['version.txt']},
|
||||
install_requires=['pyopenssl', 'warctools>=4.8.3'], # gdbm not in pip :(
|
||||
dependency_links=['git+https://github.com/internetarchive/warctools.git#egg=warctools-4.8.3'],
|
||||
tests_require=['requests>=2.0.1', 'pytest'], # >=2.0.1 for https://github.com/kennethreitz/requests/pull/1636
|
||||
|
@ -76,6 +76,14 @@ import base64
|
||||
import json
|
||||
import traceback
|
||||
|
||||
def _read_version_bytes():
|
||||
version_txt = os.path.sep.join(__file__.split(os.path.sep)[:-1] + ['version.txt'])
|
||||
with open(version_txt, 'rb') as fin:
|
||||
return fin.read().strip()
|
||||
|
||||
version_bytes = _read_version_bytes()
|
||||
version_str = version_bytes.strip().decode('utf-8')
|
||||
|
||||
class CertificateAuthority(object):
|
||||
logger = logging.getLogger('warcprox.CertificateAuthority')
|
||||
|
||||
@ -875,7 +883,7 @@ class WarcWriterThread(threading.Thread):
|
||||
headers.append((warctools.WarcRecord.DATE, warc_record_date))
|
||||
|
||||
warcinfo_fields = []
|
||||
warcinfo_fields.append(b'software: warcprox.py https://github.com/internetarchive/warcprox')
|
||||
warcinfo_fields.append(b'software: warcprox ' + version_bytes)
|
||||
hostname = socket.gethostname()
|
||||
warcinfo_fields.append('hostname: {}'.format(hostname).encode('latin1'))
|
||||
warcinfo_fields.append('ip: {0}'.format(socket.gethostbyname(hostname)).encode('latin1'))
|
||||
@ -1175,6 +1183,8 @@ def _build_arg_parser(prog=os.path.basename(sys.argv[0])):
|
||||
arg_parser.add_argument('--playback-index-db-file', dest='playback_index_db_file',
|
||||
default='./warcprox-playback-index.db',
|
||||
help='playback index database file (only used if --playback-port is specified)')
|
||||
arg_parser.add_argument('--version', action='version',
|
||||
version="warcprox {}".format(version_str))
|
||||
arg_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true')
|
||||
arg_parser.add_argument('-q', '--quiet', dest='quiet', action='store_true')
|
||||
# [--ispartof=warcinfo ispartof]
|
||||
|
Loading…
x
Reference in New Issue
Block a user