You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2010/09/25 01:21:56 UTC
svn commit: r1001109 - /subversion/trunk/tools/dev/wc-format.py
Author: gstein
Date: Fri Sep 24 23:21:56 2010
New Revision: 1001109
URL: http://svn.apache.org/viewvc?rev=1001109&view=rev
Log:
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
Modified:
subversion/trunk/tools/dev/wc-format.py
Modified: subversion/trunk/tools/dev/wc-format.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dev/wc-format.py?rev=1001109&r1=1001108&r2=1001109&view=diff
==============================================================================
--- subversion/trunk/tools/dev/wc-format.py (original)
+++ subversion/trunk/tools/dev/wc-format.py Fri Sep 24 23:21:56 2010
@@ -4,31 +4,33 @@ 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))
+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)