3 "Remote RCS -- command line interface"
11 from rcsclient
import openrcsclient
14 sys
.stdout
= sys
.stderr
16 opts
, rest
= getopt
.getopt(sys
.argv
[1:], 'h:p:d:qvL')
20 cmd
, rest
= rest
[0], rest
[1:]
21 if not commands
.has_key(cmd
):
22 raise getopt
.error
, "unknown command"
23 coptset
, func
= commands
[cmd
]
24 copts
, files
= getopt
.getopt(rest
, coptset
)
25 except getopt
.error
, msg
:
27 print "usage: rrcs [options] command [options] [file] ..."
28 print "where command can be:"
29 print " ci|put # checkin the given files"
30 print " co|get # checkout"
31 print " info # print header info"
32 print " head # print revision of head branch"
33 print " list # list filename if valid"
34 print " log # print full log"
35 print " diff # diff rcs file and work file"
36 print "if no files are given, all remote rcs files are assumed"
38 x
= openrcsclient(opts
)
44 except (IOError, os
.error
), msg
:
45 print "%s: %s" % (fn
, msg
)
47 def checkin(x
, copts
, fn
):
51 new
= not x
.isvalid(fn
)
52 if not new
and same(x
, copts
, fn
, data
):
53 print "%s: unchanged since last checkin" % fn
55 print "Checking in", fn
, "..."
56 message
= asklogmessage(new
)
57 messages
= x
.put(fn
, data
, message
)
61 def checkout(x
, copts
, fn
):
67 def lock(x
, copts
, fn
):
70 def unlock(x
, copts
, fn
):
73 def info(x
, copts
, fn
):
78 print key
+ ':', dict[key
]
81 def head(x
, copts
, fn
):
85 def list(x
, copts
, fn
):
89 def log(x
, copts
, fn
):
92 flags
= flags
+ ' ' + o
+ a
94 messages
= x
.log(fn
, flags
)
97 def diff(x
, copts
, fn
):
98 if same(x
, copts
, fn
):
102 flags
= flags
+ ' ' + o
+ a
105 tf
= tempfile
.NamedTemporaryFile()
108 print 'diff %s -r%s %s' % (flags
, x
.head(fn
), fn
)
109 sts
= os
.system('diff %s %s %s' % (flags
, tf
.name
, fn
))
113 def same(x
, copts
, fn
, data
= None):
118 lsum
= md5
.new(data
).digest()
122 def asklogmessage(new
):
124 print "enter description,",
126 print "enter log message,",
127 print "terminate with single '.' or end of file:"
129 print "NOTE: This is NOT the log message!"
132 sys
.stderr
.write(">> ")
134 line
= sys
.stdin
.readline()
135 if not line
or line
== '.\n': break
136 message
= message
+ line
147 'put': ('', checkin
),
148 'co': ('', checkout
),
149 'get': ('', checkout
),
154 'unlock': ('', unlock
),
155 'log': ('bhLRtd:l:r:s:w:V:', log
),
159 if __name__
== '__main__':