File: putfile.py

package info (click to toggle)
subversion 1.4.2dfsg1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 37,268 kB
  • ctags: 32,888
  • sloc: ansic: 406,472; python: 38,378; sh: 15,248; cpp: 9,604; ruby: 8,313; perl: 5,308; java: 4,576; lisp: 3,860; xml: 3,298; makefile: 856
file content (66 lines) | stat: -rwxr-xr-x 1,649 bytes parent folder | download | duplicates (2)
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
64
65
66
#!/usr/bin/env python
#
# USAGE: putfile.py [-m commitmsg] [-u username] file repos-path 
#
# put a file into an SVN repository
#

import sys
import os
import getopt

from svn import fs, core, repos, delta

def putfile(fname, rpath, uname="", commitmsg=""):
  rpath = core.svn_path_canonicalize(rpath)
  repos_ptr = repos.open(rpath)
  fsob = repos.fs(repos_ptr)

  # open a transaction against HEAD
  rev = fs.youngest_rev(fsob)

  txn = repos.fs_begin_txn_for_commit(repos_ptr, rev, uname, commitmsg)

  root = fs.txn_root(txn)
  rev_root = fs.revision_root(fsob, rev)

  kind = fs.check_path(root, fname)
  if kind == core.svn_node_none:
    print "file '%s' does not exist, creating..." % fname
    fs.make_file(root, fname)
  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)

  ### 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)
  
  newrev = repos.fs_commit_txn(repos_ptr, txn)
  print "revision: ", newrev

def usage():
  print "USAGE: putfile.py [-m commitmsg] [-u username] file repos-path"
  sys.exit(1)

def main():
  opts, args = getopt.getopt(sys.argv[1:], 'm:u:')
  if len(args) != 2:
    usage()

  uname = commitmsg = ""

  for name, value in opts:
    if name == '-u':
      uname = value
    if name == '-m':
      commitmsg = value
  putfile(args[0], args[1], uname, commitmsg)

if __name__ == '__main__':
  main()