#!/usr/bin/env python

import os
import sqlite3
import sys

# helper
def usage():
  sys.stderr.write("USAGE: %s [PATH]\n" + \
                   "\n" + \
                   "Prints to stdout the format of the working copy at PATH.\n")

# parse argv
wc = (sys.argv[1:] + ['.'])[0]

# main()
entries = os.path.join(wc, '.svn', 'entries')
wc_db = os.path.join(wc, '.svn', 'wc.db')

if os.path.exists(entries):
  formatno = int(open(entries).readline())
elif os.path.exists(wc_db):
  formatno = sqlite3.connect(wc_db).execute('pragma user_version;').fetchone()[0]
else:
  usage()
  sys.exit(1)

# 1.0.x -> 1.3.x: format 4
# 1.4.x: format 8
# 1.5.x: format 9
# 1.6.x: format 10
# 1.7.x: format XXX
print("%s: %d" % (wc, formatno))


#!/usr/bin/env python

import os
import sqlite3
import sys


def print_format(wc_path):
  entries = os.path.join(wc_path, '.svn', 'entries')
  wc_db = os.path.join(wc_path, '.svn', 'wc.db')

  if os.path.exists(entries):
    formatno = int(open(entries).readline())
  elif os.path.exists(wc_db):
    conn = sqlite3.connect(wc_db)
    curs = conn.cursor()
    curs.execute('pragma user_version;')
    formatno = curs.fetchone()[0]
  else:
    formatno = 'not under version control'

  # see subversion/libsvn_wc/wc.h for format values and information
  #   1.0.x -> 1.3.x: format 4
  #   1.4.x: format 8
  #   1.5.x: format 9
  #   1.6.x: format 10
  #   1.7.x: format XXX
  print '%s: %s' % (wc_path, formatno)


if __name__ == '__main__':
  paths = sys.argv[1:]
  if not paths:
    paths = ['.']
  for wc_path in paths:
    print_format(wc_path)

Allow script to take multiple paths, and adjust to standard __main__ idiom for cmdline scripts.
Allow script to take multiple paths, and adjust to standard __main__ idiom
for cmdline scripts.

* tools/dev/wc-format.py:
  (usage): remove. all paths are allowed.
  (print_format): move guts of format fetching and printing into this
    function. print 'not under version control' for such a path, rather
    than bailing with USAGE. expand sqlite stuff to use normal pydb idioms
    (eg. execute is not supposed to return anything)
  (__main__): invoke print_format for each path provided


git-svn-id: f8a4e5e023278da1e04e203c7fe051e3c4285d88@1001109 13f79535-47bb-0310-9956-ffa450edef68
