Reorganize the output to "svnserve --help".
[svn.git] / tools / client-side / server-version.py
blob7617ba26f5cef80a2e9f6bea4d75641cc7274dba
1 #!/usr/bin/env python
3 # server-version.py: print a Subversion server's version number
5 # USAGE: server-version.py URL
7 # The URL can contain any path on the server, as we are simply looking
8 # for Apache's response to OPTIONS, and its Server: header.
10 # EXAMPLE:
12 # $ ./server-version.py http://svn.collab.net/
13 # or
14 # $ ./server-version.py https://svn.collab.net/
16 # Python 1.5.2 or later is required.
19 import sys
20 import httplib
21 import urlparse
24 def print_version(url):
25 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
26 if scheme == 'http':
27 conn = httplib.HTTPConnection(netloc)
28 elif scheme == 'https':
29 conn = httplib.HTTPSConnection(netloc)
30 else:
31 print 'ERROR: this script only supports "http" and "https" URLs'
32 sys.exit(1)
33 conn.putrequest('OPTIONS', path)
34 conn.putheader('Host', netloc)
35 conn.endheaders()
36 resp = conn.getresponse()
37 status, msg, server = (resp.status, resp.msg, resp.getheader('Server'))
38 conn.close()
40 # Handle "OK" and Handle redirect requests, if requested resource
41 # resides temporarily under a different URL
42 if status != 200 and status != 302:
43 print 'ERROR: bad status response: %s %s' % (status, msg)
44 sys.exit(1)
45 if not server:
46 # a missing Server: header. Bad, bad server! Go sit in the corner!
47 print 'WARNING: missing header'
48 else:
49 for part in server.split(' '):
50 if part[:4] == 'SVN/':
51 print part[4:]
52 break
53 else:
54 # the server might be configured to hide this information, or it
55 # might not have mod_dav_svn loaded into it.
56 print 'NOTICE: version unknown'
59 if __name__ == '__main__':
60 if len(sys.argv) != 2:
61 print 'USAGE: %s URL' % sys.argv[0]
62 sys.exit(1)
63 print_version(sys.argv[1])