import sys
import httplib
import urlparse
def print_version(url):
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
if scheme == 'http':
conn = httplib.HTTPConnection(netloc)
elif scheme == 'https':
conn = httplib.HTTPSConnection(netloc)
else:
print('ERROR: this script only supports "http" and "https" URLs')
sys.exit(1)
conn.putrequest('OPTIONS', path)
conn.putheader('Host', netloc)
conn.endheaders()
resp = conn.getresponse()
status, msg, server = (resp.status, resp.msg, resp.getheader('Server'))
conn.close()
if status != 200 and status != 302:
print('ERROR: bad status response: %s %s' % (status, msg))
sys.exit(1)
if not server:
print('WARNING: missing header')
else:
for part in server.split(' '):
if part[:4] == 'SVN/':
print(part[4:])
break
else:
print('NOTICE: version unknown')
if __name__ == '__main__':
if len(sys.argv) != 2:
print('USAGE: %s URL' % sys.argv[0])
sys.exit(1)
print_version(sys.argv[1])