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.
12 # $ ./server-version.py http://svn.collab.net/
14 # $ ./server-version.py https://svn.collab.net/
16 # Python 1.5.2 or later is required.
24 def print_version(url
):
25 scheme
, netloc
, path
, params
, query
, fragment
= urlparse
.urlparse(url
)
27 conn
= httplib
.HTTPConnection(netloc
)
28 elif scheme
== 'https':
29 conn
= httplib
.HTTPSConnection(netloc
)
31 print 'ERROR: this script only supports "http" and "https" URLs'
33 conn
.putrequest('OPTIONS', path
)
34 conn
.putheader('Host', netloc
)
36 resp
= conn
.getresponse()
37 status
, msg
, server
= (resp
.status
, resp
.msg
, resp
.getheader('Server'))
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
)
46 # a missing Server: header. Bad, bad server! Go sit in the corner!
47 print 'WARNING: missing header'
49 for part
in server
.split(' '):
50 if part
[:4] == 'SVN/':
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]
63 print_version(sys
.argv
[1])