File: server-version.py

package info (click to toggle)
subversion 1.5.1dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 41,860 kB
  • ctags: 43,900
  • sloc: ansic: 522,648; python: 64,596; sh: 12,784; ruby: 11,838; cpp: 9,584; java: 8,130; lisp: 7,131; perl: 5,686; makefile: 895; xml: 759
file content (63 lines) | stat: -rwxr-xr-x 1,779 bytes parent folder | download
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
56
57
58
59
60
61
62
63
#!/usr/bin/env python
#
# server-version.py: print a Subversion server's version number
#
# USAGE: server-version.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-version.py http://svn.collab.net/
#                   or
#   $ ./server-version.py https://svn.collab.net/
#
# Python 1.5.2 or later is required.
#

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()

  # Handle "OK" and Handle redirect requests, if requested resource
  # resides temporarily under a different URL
  if status != 200 and status != 302:
    print 'ERROR: bad status response: %s %s' % (status, msg)
    sys.exit(1)
  if not server:
    # a missing Server: header. Bad, bad server! Go sit in the corner!
    print 'WARNING: missing header'
  else:
    for part in server.split(' '):
      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])