3 # USAGE: putfile.py [-m commitmsg] [-u username] file repos-path
5 # put a file into an SVN repository
12 my_getopt
= getopt
.gnu_getopt
13 except AttributeError:
14 my_getopt
= getopt
.getopt
16 from svn
import fs
, core
, repos
, delta
18 def putfile(fname
, rpath
, uname
="", commitmsg
=""):
19 rpath
= core
.svn_path_canonicalize(rpath
)
20 repos_ptr
= repos
.open(rpath
)
21 fsob
= repos
.fs(repos_ptr
)
23 # open a transaction against HEAD
24 rev
= fs
.youngest_rev(fsob
)
26 txn
= repos
.fs_begin_txn_for_commit(repos_ptr
, rev
, uname
, commitmsg
)
28 root
= fs
.txn_root(txn
)
29 rev_root
= fs
.revision_root(fsob
, rev
)
31 kind
= fs
.check_path(root
, fname
)
32 if kind
== core
.svn_node_none
:
33 print "file '%s' does not exist, creating..." % fname
34 fs
.make_file(root
, fname
)
35 elif kind
== core
.svn_node_dir
:
36 print "File '%s' is a dir." % fname
39 print "Updating file '%s'" % fname
41 handler
, baton
= fs
.apply_textdelta(root
, fname
, None, None)
43 ### it would be nice to get an svn_stream_t. for now, just load in the
44 ### whole file and shove it into the FS.
45 delta
.svn_txdelta_send_string(open(fname
, 'rb').read(),
48 newrev
= repos
.fs_commit_txn(repos_ptr
, txn
)
49 print "revision: ", newrev
52 print "USAGE: putfile.py [-m commitmsg] [-u username] file repos-path"
56 opts
, args
= my_getopt(sys
.argv
[1:], 'm:u:')
60 uname
= commitmsg
= ""
62 for name
, value
in opts
:
67 putfile(args
[0], args
[1], uname
, commitmsg
)
69 if __name__
== '__main__':