Hi!
I have updated a few example scripts. Now:
- they call repos.svn_repos_open instead of fs.new,
- use everywhere core.run_app
- use repos transaction functions, instead of fs ones,
- they run :-)
Is the patch format ok?
Greetings,
Tomek
Log: update of the most example scripts, now they don't raise exeptions, and:
* they call repos.svn_repos_open instead of fs.new,
* use everywhere core.run_app
* use repos transaction functions, instead of fs ones
Index: tools/examples/putfile.py
===================================================================
--- tools/examples/putfile.py (revision 6640)
+++ tools/examples/putfile.py (working copy)
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#
-# USAGE: putfile.py [-h DBHOME] file repos-path
+# USAGE: putfile.py [-m commitmsg] [-u username] file repos-path
#
# put a file into an SVN repository
#
@@ -9,57 +9,61 @@
import os
import getopt
-from svn import fs, _util, _delta
+from svn import fs, core, repos, delta
-def putfile(fname, rpath, home='.'):
- _util.apr_initialize()
- pool = _util.svn_pool_create(None)
+def putfile(pool, fname, rpath, uname="", commitmsg=""):
+ if rpath[-1] == "/":
+ rpath = rpath[:-1]
- db_path = os.path.join(home, 'db')
- if not os.path.exists(db_path):
- db_path = home
+ repos_ptr = repos.svn_repos_open(rpath, pool)
+ fsob = repos.svn_repos_fs(repos_ptr)
- fsob = fs.new(pool)
- fs.open_berkeley(fsob, db_path)
-
# open a transaction against HEAD
rev = fs.youngest_rev(fsob, pool)
- txn = fs.begin_txn(fsob, rev, pool)
- print `txn`
+ txn = repos.svn_repos_fs_begin_txn_for_commit(repos_ptr, rev, uname, commitmsg, pool)
root = fs.txn_root(txn, pool)
- fs.make_file(root, rpath, pool)
+ rev_root = fs.revision_root(fsob, rev, pool)
- handler, baton = fs.apply_textdelta(root, rpath, pool)
+ kind = fs.check_path(root, fname, pool)
+ if kind == core.svn_node_none:
+ print "file '%s' does not exist, creating..." % fname
+ fs.make_file(root, fname, pool)
+ elif kind == core.svn_node_dir:
+ print "File '%s' is a dir." % fname
+ return
+ else:
+ print "Updating file '%s'" % fname
+ handler, baton = fs.apply_textdelta(root, fname, None, None, pool)
+
### it would be nice to get an svn_stream_t. for now, just load in the
### whole file and shove it into the FS.
- _delta.svn_txdelta_send_string(open(fname, 'rb').read(),
- handler, baton,
- pool)
+ delta.svn_txdelta_send_string(open(fname, 'rb').read(),
+ handler, baton,
+ pool)
- conflicts, new_rev = fs.commit_txn(txn)
- if conflicts:
- print 'conflicts:', conflicts
- print 'New revision:', new_rev
+ newrev = repos.svn_repos_fs_commit_txn(repos_ptr, txn)
+ print "revision: ", newrev
- _util.svn_pool_destroy(pool)
- _util.apr_terminate()
-
def usage():
- print "USAGE: putfile.py [-h DBHOME] file repos-path"
+ print "USAGE: putfile.py [-m commitmsg] [-u username] file repos-path"
sys.exit(1)
def main():
- opts, args = getopt.getopt(sys.argv[1:], 'h:')
+ opts, args = getopt.getopt(sys.argv[1:], 'm:u:')
if len(args) != 2:
usage()
- home = '.'
+
+ uname = commitmsg = ""
+
for name, value in opts:
- if name == '-h':
- home = value
- putfile(args[0], args[1], home)
+ if name == '-u':
+ uname = value
+ if name == '-m':
+ commitmsg = value
+ core.run_app(putfile, args[0], args[1], uname, commitmsg)
if __name__ == '__main__':
main()
Index: tools/examples/revplist.py
===================================================================
--- tools/examples/revplist.py (revision 6640)
+++ tools/examples/revplist.py (working copy)
@@ -19,7 +19,7 @@
import os
import getopt
-from svn import fs, util
+from svn import fs, util, core
def plist(pool, rev=None, home='.', *props):
Index: tools/examples/dumpprops.py
===================================================================
--- tools/examples/dumpprops.py (revision 6640)
+++ tools/examples/dumpprops.py (working copy)
@@ -1,6 +1,6 @@
#!/usr/bin/env python2.2
#
-# USAGE: dumprops.py [-r REV] [-h DBHOME] repos-path
+# USAGE: dumprops.py [-r REV] repos-path [file]
#
# dump out the properties on a given path (recursively if given a dir)
#
@@ -10,25 +10,24 @@
import getopt
import pprint
-from svn import fs, core
+from svn import fs, core, repos
-def dumpprops(pool, path='', rev=None, home='.'):
+def dumpprops(pool, path, filename='', rev=None):
- db_path = os.path.join(home, 'db')
- if not os.path.exists(db_path):
- db_path = home
+ if path[-1] == "/":
+ path = path[:-1]
- fsob = fs.new(pool)
- fs.open_berkeley(fsob, db_path)
+ repos_ptr = repos.svn_repos_open(path, pool)
+ fsob = repos.svn_repos_fs(repos_ptr)
if rev is None:
rev = fs.youngest_rev(fsob, pool)
root = fs.revision_root(fsob, rev, pool)
- print_props(root, path, pool)
- if fs.is_dir(root, path, pool):
- walk_tree(root, path, pool)
+ print_props(root, filename, pool)
+ if fs.is_dir(root, filename, pool):
+ walk_tree(root, filename, pool)
def print_props(root, path, pool):
raw_props = fs.node_proplist(root, path, pool)
@@ -42,8 +41,8 @@
def walk_tree(root, path, pool):
subpool = core.svn_pool_create(pool)
- try:
- for name in fs.entries(root, path, subpool).keys():
+ try:
+ for name in fs.dir_entries(root, path, subpool).keys():
full = path + '/' + name
print_props(root, full, subpool)
if fs.is_dir(root, full, subpool):
@@ -53,21 +52,21 @@
core.svn_pool_destroy(subpool)
def usage():
- print "USAGE: dumpprops.py [-r REV] [-h DBHOME] repos-path"
+ print "USAGE: dumpprops.py [-r REV] repos-path [file]"
sys.exit(1)
def main():
- opts, args = getopt.getopt(sys.argv[1:], 'r:h:')
- if len(args) != 1:
- usage()
+ opts, args = getopt.getopt(sys.argv[1:], 'r:')
rev = None
- home = '.'
for name, value in opts:
if name == '-r':
rev = int(value)
- elif name == '-h':
- home = value
- core.run_app(dumpprops, args[0], rev, home)
+ if len(args) == 2:
+ core.run_app(dumpprops, args[0], args[1], rev)
+ elif len(args) == 1:
+ core.run_app(dumpprops, args[0], "", rev)
+ else:
+ usage()
if __name__ == '__main__':
main()
Index: tools/examples/svnshell.py
===================================================================
--- tools/examples/svnshell.py (revision 6640)
+++ tools/examples/svnshell.py (working copy)
@@ -211,13 +211,7 @@
print rev
core.svn_pool_clear(self.taskpool)
- def do_EOF(self, arg):
- self.do_exit(arg)
-
def do_exit(self, arg):
- # Make sure a newline is printed and the shell begins on a newline
- # afterwards
- print ''
sys.exit(0)
def _path_to_parts(self, path):
Index: tools/examples/getfile.py
===================================================================
--- tools/examples/getfile.py (revision 6640)
+++ tools/examples/getfile.py (working copy)
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#
-# USAGE: getfile.py [-r REV] [-h DBHOME] repos-path
+# USAGE: getfile.py [-r REV] repos-path file
#
# gets a file from an SVN repository, puts it to sys.stdout
#
@@ -9,24 +9,25 @@
import os
import getopt
-from svn import fs, core
+from svn import fs, core, repos
CHUNK_SIZE = 16384
-def getfile(pool, path, rev=None, home='.'):
+def getfile(pool, path, filename, rev=None):
+ #since the backslash on the end of path is not allowed,
+ #we truncate it
+ if path[-1] == "/":
+ path = path[:-1]
- db_path = os.path.join(home, 'db')
- if not os.path.exists(db_path):
- db_path = home
+ repos_ptr = repos.svn_repos_open(path, pool)
+ fsob = repos.svn_repos_fs(repos_ptr)
- fsob = fs.new(pool)
- fs.open_berkeley(fsob, db_path)
-
if rev is None:
rev = fs.youngest_rev(fsob, pool)
-
+ print "Using youngest revision ", rev
+
root = fs.revision_root(fsob, rev, pool)
- file = fs.file_contents(root, path, pool)
+ file = fs.file_contents(root, filename, pool)
while 1:
data = core.svn_stream_read(file, CHUNK_SIZE)
if not data:
@@ -34,21 +35,18 @@
sys.stdout.write(data)
def usage():
- print "USAGE: getfile.py [-r REV] [-h DBHOME] repos-path"
+ print "USAGE: getfile.py [-r REV] repos-path file"
sys.exit(1)
def main():
- opts, args = getopt.getopt(sys.argv[1:], 'r:h:')
- if len(args) != 1:
+ opts, args = getopt.getopt(sys.argv[1:], 'r:')
+ if len(args) != 2:
usage()
rev = None
- home = '.'
for name, value in opts:
if name == '-r':
rev = int(value)
- elif name == '-h':
- home = value
- core.run_app(getfile, args[0], rev, home)
+ core.run_app(getfile, args[0], args[1], rev)
if __name__ == '__main__':
main()
Index: tools/examples/blame.py
===================================================================
--- tools/examples/blame.py (revision 6640)
+++ tools/examples/blame.py (working copy)
@@ -1,31 +1,31 @@
#!/usr/bin/env python2
#
-# USAGE: blame.py [-r REV] [-h DBHOME] repos-path
+# USAGE: blame.py [-r REV] repos-path file
#
import sys
import os
import getopt
import difflib
-from svn import fs, core
+from svn import fs, core, repos
CHUNK_SIZE = 100000
-def getfile(pool, path, rev=None, home='.'):
+def getfile(pool, path, filename, rev=None):
- db_path = os.path.join(home, 'db')
- if not os.path.exists(db_path):
- db_path = home
annotresult = {}
- fsob = fs.new(pool)
- fs.open_berkeley(fsob, db_path)
-
+ if path[-1] == "/":
+ path = path[:-1]
+
+ repos_ptr = repos.svn_repos_open(path, pool)
+ fsob = repos.svn_repos_fs(repos_ptr)
+
if rev is None:
rev = fs.youngest_rev(fsob, pool)
filedata = ''
for i in xrange(0, rev+1):
root = fs.revision_root(fsob, i, pool)
- if fs.check_path(root, path, pool) != core.svn_node_none:
+ if fs.check_path(root, filename, pool) != core.svn_node_none:
first = i
break
print "First revision is %d" % first
@@ -34,10 +34,10 @@
previousroot = root
root = fs.revision_root(fsob, i, pool)
if i != first:
- if not fs.contents_changed(root, path, previousroot, path, pool):
+ if not fs.contents_changed(root, filename, previousroot, filename, pool):
continue
- file = fs.file_contents(root, path, pool)
+ file = fs.file_contents(root, filename, pool)
previousdata = filedata
filedata = ''
while 1:
@@ -73,21 +73,18 @@
annotresult[x][1]))
def usage():
- print "USAGE: blame.py [-r REV] [-h DBHOME] repos-path"
+ print "USAGE: blame.py [-r REV] repos-path file"
sys.exit(1)
def main():
- opts, args = getopt.getopt(sys.argv[1:], 'r:h:')
- if len(args) != 1:
+ opts, args = getopt.getopt(sys.argv[1:], 'r:')
+ if len(args) != 2:
usage()
rev = None
- home = '.'
for name, value in opts:
if name == '-r':
rev = int(value)
- elif name == '-h':
- home = value
- core.run_app(getfile, args[0], rev, home)
+ core.run_app(getfile, args[0], args[1], rev)
if __name__ == '__main__':
main()
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Aug 4 00:05:41 2003