File: server-vsn.py

package info (click to toggle)
subversion 1.4.2dfsg1-3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,284 kB
  • ctags: 32,888
  • sloc: ansic: 406,472; python: 38,378; sh: 15,438; cpp: 9,604; ruby: 8,313; perl: 5,308; java: 4,576; lisp: 3,860; xml: 3,298; makefile: 856
file content (55 lines) | stat: -rwxr-xr-x 1,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
#
# server-vsn.py: print a Subversion server's version number
#
# USAGE: server-vsn.py URL
#
# The URL can contain any path on the server, as we are simply looking
# for Apache's response to OPTIONS, and its Server: header.
#
# EXAMPLE:
#
#   $ ./server-vsn.py http://svn.collab.net/
#
# Python 1.5.2 or later is required.
#

import sys
import httplib
import urlparse
import string


def print_version(url):
  scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
  if scheme != 'http':
    print 'ERROR: this script only supports "http" URLs'
    sys.exit(1)
  conn = httplib.HTTP(netloc)
  conn.putrequest('OPTIONS', path)
  conn.putheader('Host', netloc)
  conn.endheaders()
  status, msg, headers = conn.getreply()
  if status != 200:
    print 'ERROR: bad status response: %s %s' % (status, msg)
    sys.exit(1)
  server = headers.getheader('Server')
  if not server:
    # a missing Server: header. Bad, bad server! Go sit in the corner!
    print 'WARNING: missing header'
  else:
    for part in string.split(server):
      if part[:4] == 'SVN/':
        print part[4:]
        break
    else:
      # the server might be configured to hide this information, or it
      # might not have mod_dav_svn loaded into it.
      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])