Guido van Rossum | 097c55a | 1995-04-27 18:07:07 +0000 | [diff] [blame] | 1 | #! /usr/local/bin/python |
| 2 | |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 3 | """Remote CVS -- command line interface""" |
Guido van Rossum | 097c55a | 1995-04-27 18:07:07 +0000 | [diff] [blame] | 4 | |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 5 | # XXX To do: |
| 6 | # |
Guido van Rossum | 903afd0 | 1995-06-23 22:33:57 +0000 | [diff] [blame] | 7 | # Bugs: |
| 8 | # - if the remote file is deleted, "rcvs update" will fail |
| 9 | # |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 10 | # Functionality: |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 11 | # - cvs log |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 12 | # - cvs rm |
| 13 | # - descend into directories (alraedy done for update) |
| 14 | # - conflict resolution |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 15 | # - other relevant commands? |
| 16 | # - branches |
| 17 | # |
| 18 | # - Finesses: |
| 19 | # - retain file mode's x bits |
| 20 | # - complain when "nothing known about filename" |
| 21 | # - edit log message the way CVS lets you edit it |
| 22 | # - cvs diff -rREVA -rREVB |
| 23 | # - send mail the way CVS sends it |
| 24 | # |
| 25 | # Performance: |
| 26 | # - cache remote checksums (for every revision ever seen!) |
| 27 | # - translate symbolic revisions to numeric revisions |
| 28 | # |
| 29 | # Reliability: |
| 30 | # - remote locking |
| 31 | # |
| 32 | # Security: |
| 33 | # - Authenticated RPC? |
| 34 | |
| 35 | |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 36 | from cvslib import CVS, File |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 37 | import md5 |
| 38 | import os |
| 39 | import string |
| 40 | import sys |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 41 | from cmdfw import CommandFrameWork |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 42 | |
| 43 | |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 44 | DEF_LOCAL = 1 # Default -l |
| 45 | |
| 46 | |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 47 | class MyFile(File): |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 48 | |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 49 | def action(self): |
| 50 | """Return a code indicating the update status of this file. |
| 51 | |
| 52 | The possible return values are: |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 53 | |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 54 | '=' -- everything's fine |
| 55 | '0' -- file doesn't exist anywhere |
| 56 | '?' -- exists locally only |
| 57 | 'A' -- new locally |
| 58 | 'R' -- deleted locally |
| 59 | 'U' -- changed remotely, no changes locally |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 60 | (includes new remotely or deleted remotely) |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 61 | 'M' -- changed locally, no changes remotely |
| 62 | 'C' -- conflict: changed locally as well as remotely |
| 63 | (includes cases where the file has been added |
| 64 | or removed locally and remotely) |
Guido van Rossum | ba24468 | 1995-04-28 15:33:03 +0000 | [diff] [blame] | 65 | 'D' -- deleted remotely |
| 66 | 'N' -- new remotely |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 67 | 'r' -- get rid of entry |
| 68 | 'c' -- create entry |
| 69 | 'u' -- update entry |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 70 | |
| 71 | (and probably others :-) |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 72 | """ |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 73 | if not self.lseen: |
| 74 | self.getlocal() |
| 75 | if not self.rseen: |
| 76 | self.getremote() |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 77 | if not self.eseen: |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 78 | if not self.lsum: |
| 79 | if not self.rsum: return '0' # Never heard of |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 80 | else: |
| 81 | return 'N' # New remotely |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 82 | else: # self.lsum |
| 83 | if not self.rsum: return '?' # Local only |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 84 | # Local and remote, but no entry |
| 85 | if self.lsum == self.rsum: |
| 86 | return 'c' # Restore entry only |
| 87 | else: return 'C' # Real conflict |
| 88 | else: # self.eseen |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 89 | if not self.lsum: |
| 90 | if self.edeleted: |
| 91 | if self.rsum: return 'R' # Removed |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 92 | else: return 'r' # Get rid of entry |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 93 | else: # not self.edeleted |
| 94 | if self.rsum: |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 95 | print "warning:", |
| 96 | print self.file, |
| 97 | print "was lost" |
| 98 | return 'U' |
| 99 | else: return 'r' # Get rid of entry |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 100 | else: # self.lsum |
| 101 | if not self.rsum: |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 102 | if self.enew: return 'A' # New locally |
| 103 | else: return 'D' # Deleted remotely |
Guido van Rossum | 2f7ef91 | 1995-05-01 20:22:01 +0000 | [diff] [blame] | 104 | else: # self.rsum |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 105 | if self.enew: |
| 106 | if self.lsum == self.rsum: |
| 107 | return 'u' |
| 108 | else: |
| 109 | return 'C' |
| 110 | if self.lsum == self.esum: |
| 111 | if self.esum == self.rsum: |
| 112 | return '=' |
| 113 | else: |
| 114 | return 'U' |
| 115 | elif self.esum == self.rsum: |
| 116 | return 'M' |
| 117 | elif self.lsum == self.rsum: |
| 118 | return 'u' |
| 119 | else: |
| 120 | return 'C' |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 121 | |
| 122 | def update(self): |
| 123 | code = self.action() |
Guido van Rossum | 8b5e0fa | 1995-04-28 21:48:16 +0000 | [diff] [blame] | 124 | if code == '=': return |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 125 | print code, self.file |
Guido van Rossum | ba24468 | 1995-04-28 15:33:03 +0000 | [diff] [blame] | 126 | if code in ('U', 'N'): |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 127 | self.get() |
| 128 | elif code == 'C': |
| 129 | print "%s: conflict resolution not yet implemented" % \ |
| 130 | self.file |
Guido van Rossum | ba24468 | 1995-04-28 15:33:03 +0000 | [diff] [blame] | 131 | elif code == 'D': |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 132 | remove(self.file) |
Guido van Rossum | ba24468 | 1995-04-28 15:33:03 +0000 | [diff] [blame] | 133 | self.eseen = 0 |
| 134 | elif code == 'r': |
| 135 | self.eseen = 0 |
| 136 | elif code in ('c', 'u'): |
Guido van Rossum | d22f59f | 1995-04-28 15:37:22 +0000 | [diff] [blame] | 137 | self.eseen = 1 |
Guido van Rossum | ba24468 | 1995-04-28 15:33:03 +0000 | [diff] [blame] | 138 | self.erev = self.rrev |
| 139 | self.enew = 0 |
| 140 | self.edeleted = 0 |
| 141 | self.esum = self.rsum |
| 142 | self.emtime, self.ectime = os.stat(self.file)[-2:] |
Guido van Rossum | d22f59f | 1995-04-28 15:37:22 +0000 | [diff] [blame] | 143 | self.extra = '' |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 144 | |
| 145 | def commit(self, message = ""): |
| 146 | code = self.action() |
| 147 | if code in ('A', 'M'): |
| 148 | self.put(message) |
| 149 | elif code == 'R': |
| 150 | print "%s: committing removes not yet implemented" % \ |
| 151 | self.file |
| 152 | elif code == 'C': |
| 153 | print "%s: conflict resolution not yet implemented" % \ |
| 154 | self.file |
| 155 | |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 156 | def diff(self, opts = []): |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 157 | self.action() # To update lseen, rseen |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 158 | flags = '' |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 159 | rev = self.rrev |
| 160 | # XXX should support two rev options too! |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 161 | for o, a in opts: |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 162 | if o == '-r': |
| 163 | rev = a |
| 164 | else: |
| 165 | flags = flags + ' ' + o + a |
| 166 | if rev == self.rrev and self.lsum == self.rsum: |
| 167 | return |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 168 | flags = flags[1:] |
| 169 | fn = self.file |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 170 | data = self.proxy.get((fn, rev)) |
| 171 | sum = md5.new(data).digest() |
| 172 | if self.lsum == sum: |
| 173 | return |
| 174 | import tempfile |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 175 | tfn = tempfile.mktemp() |
| 176 | try: |
| 177 | tf = open(tfn, 'w') |
| 178 | tf.write(data) |
| 179 | tf.close() |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 180 | print 'diff %s -r%s %s' % (flags, rev, fn) |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 181 | sts = os.system('diff %s %s %s' % (flags, tfn, fn)) |
| 182 | if sts: |
| 183 | print '='*70 |
| 184 | finally: |
| 185 | remove(tfn) |
| 186 | |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 187 | def commitcheck(self): |
| 188 | return self.action() != 'C' |
| 189 | |
| 190 | def put(self, message = ""): |
Guido van Rossum | bafc14d | 1995-04-28 15:41:51 +0000 | [diff] [blame] | 191 | print "Checking in", self.file, "..." |
| 192 | data = open(self.file).read() |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 193 | if not self.enew: |
| 194 | self.proxy.lock(self.file) |
Guido van Rossum | bafc14d | 1995-04-28 15:41:51 +0000 | [diff] [blame] | 195 | messages = self.proxy.put(self.file, data, message) |
| 196 | if messages: |
| 197 | print messages |
Guido van Rossum | 8b5e0fa | 1995-04-28 21:48:16 +0000 | [diff] [blame] | 198 | self.setentry(self.proxy.head(self.file), self.lsum) |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 199 | |
| 200 | def get(self): |
| 201 | data = self.proxy.get(self.file) |
| 202 | f = open(self.file, 'w') |
| 203 | f.write(data) |
| 204 | f.close() |
Guido van Rossum | 8b5e0fa | 1995-04-28 21:48:16 +0000 | [diff] [blame] | 205 | self.setentry(self.rrev, self.rsum) |
| 206 | |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 207 | def add(self): |
| 208 | self.eseen = 0 # While we're hacking... |
| 209 | self.esum = self.lsum |
| 210 | self.emtime, self.ectime = 0, 0 |
| 211 | self.erev = '' |
| 212 | self.enew = 1 |
| 213 | self.edeleted = 0 |
| 214 | self.eseen = 1 # Done |
| 215 | self.extra = '' |
| 216 | |
Guido van Rossum | 8b5e0fa | 1995-04-28 21:48:16 +0000 | [diff] [blame] | 217 | def setentry(self, erev, esum): |
| 218 | self.eseen = 0 # While we're hacking... |
| 219 | self.esum = esum |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 220 | self.emtime, self.ectime = os.stat(self.file)[-2:] |
Guido van Rossum | 8b5e0fa | 1995-04-28 21:48:16 +0000 | [diff] [blame] | 221 | self.erev = erev |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 222 | self.enew = 0 |
| 223 | self.edeleted = 0 |
Guido van Rossum | 8b5e0fa | 1995-04-28 21:48:16 +0000 | [diff] [blame] | 224 | self.eseen = 1 # Done |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 225 | self.extra = '' |
| 226 | |
| 227 | |
| 228 | SENDMAIL = "/usr/lib/sendmail -t" |
| 229 | MAILFORM = """To: %s |
| 230 | Subject: CVS changes: %s |
| 231 | |
| 232 | ...Message from rcvs... |
| 233 | |
| 234 | Committed files: |
| 235 | %s |
| 236 | |
| 237 | Log message: |
| 238 | %s |
| 239 | """ |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 240 | |
| 241 | |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 242 | class RCVS(CVS): |
| 243 | |
| 244 | FileClass = MyFile |
| 245 | |
| 246 | def __init__(self): |
| 247 | CVS.__init__(self) |
| 248 | |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 249 | def update(self, files): |
| 250 | for e in self.whichentries(files, 1): |
| 251 | e.update() |
| 252 | |
| 253 | def commit(self, files, message = ""): |
| 254 | list = self.whichentries(files) |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 255 | if not list: return |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 256 | ok = 1 |
| 257 | for e in list: |
| 258 | if not e.commitcheck(): |
| 259 | ok = 0 |
| 260 | if not ok: |
| 261 | print "correct above errors first" |
| 262 | return |
| 263 | if not message: |
| 264 | message = raw_input("One-liner: ") |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 265 | committed = [] |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 266 | for e in list: |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 267 | committed.append(e.file) |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 268 | e.commit(message) |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 269 | self.mailinfo(committed, message) |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 270 | |
| 271 | def mailinfo(self, files, message = ""): |
| 272 | towhom = "sjoerd@cwi.nl, jack@cwi.nl" # XXX |
| 273 | mailtext = MAILFORM % (towhom, string.join(files), |
| 274 | string.join(files), message) |
| 275 | print '-'*70 |
| 276 | print mailtext |
| 277 | print '-'*70 |
| 278 | ok = raw_input("OK to mail to %s? " % towhom) |
| 279 | if string.lower(string.strip(ok)) in ('y', 'ye', 'yes'): |
| 280 | p = os.popen(SENDMAIL, "w") |
| 281 | p.write(mailtext) |
| 282 | sts = p.close() |
| 283 | if sts: |
| 284 | print "Sendmail exit status %s" % str(sts) |
| 285 | else: |
| 286 | print "Mail sent." |
| 287 | else: |
| 288 | print "No mail sent." |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 289 | |
| 290 | def report(self, files): |
| 291 | for e in self.whichentries(files): |
| 292 | e.report() |
| 293 | |
| 294 | def diff(self, files, opts): |
| 295 | for e in self.whichentries(files): |
| 296 | e.diff(opts) |
| 297 | |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 298 | def add(self, files): |
| 299 | if not files: |
| 300 | raise RuntimeError, "'cvs add' needs at least one file" |
| 301 | list = [] |
| 302 | for e in self.whichentries(files, 1): |
| 303 | code = e.action() |
| 304 | print code, e.file |
| 305 | e.report() |
| 306 | e.add() |
| 307 | code = e.action() |
| 308 | print code, e.file |
| 309 | e.report() |
| 310 | print '='*20 |
| 311 | |
| 312 | def rm(self, files): |
| 313 | if not files: |
| 314 | raise RuntimeError, "'cvs rm' needs at least one file" |
| 315 | raise RuntimeError, "'cvs rm' not yet imlemented" |
| 316 | |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 317 | def whichentries(self, files, localfilestoo = 0): |
| 318 | if files: |
| 319 | list = [] |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 320 | for file in files: |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 321 | if self.entries.has_key(file): |
| 322 | e = self.entries[file] |
| 323 | else: |
| 324 | e = self.FileClass(file) |
| 325 | self.entries[file] = e |
| 326 | list.append(e) |
| 327 | else: |
| 328 | list = self.entries.values() |
| 329 | for file in self.proxy.listfiles(): |
| 330 | if self.entries.has_key(file): |
| 331 | continue |
| 332 | e = self.FileClass(file) |
| 333 | self.entries[file] = e |
| 334 | list.append(e) |
| 335 | if localfilestoo: |
| 336 | for file in os.listdir(os.curdir): |
| 337 | if not self.entries.has_key(file) \ |
| 338 | and not self.ignored(file): |
| 339 | e = self.FileClass(file) |
| 340 | self.entries[file] = e |
| 341 | list.append(e) |
| 342 | list.sort() |
| 343 | if self.proxy: |
| 344 | for e in list: |
| 345 | if e.proxy is None: |
| 346 | e.proxy = self.proxy |
| 347 | return list |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 348 | |
| 349 | |
| 350 | class rcvs(CommandFrameWork): |
| 351 | |
Guido van Rossum | 903afd0 | 1995-06-23 22:33:57 +0000 | [diff] [blame] | 352 | GlobalFlags = 'd:h:p:qvL' |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 353 | UsageMessage = \ |
Guido van Rossum | 2d2a60e | 1995-04-28 19:24:50 +0000 | [diff] [blame] | 354 | "usage: rcvs [-d directory] [-h host] [-p port] [-q] [-v] [subcommand arg ...]" |
| 355 | PostUsageMessage = \ |
| 356 | "If no subcommand is given, the status of all files is listed" |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 357 | |
| 358 | def __init__(self): |
| 359 | """Constructor.""" |
| 360 | CommandFrameWork.__init__(self) |
| 361 | self.proxy = None |
| 362 | self.cvs = RCVS() |
| 363 | |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 364 | def recurse(self): |
| 365 | if self.proxy: |
| 366 | self.proxy._close() |
| 367 | self.proxy = None |
| 368 | names = os.listdir(os.curdir) |
| 369 | for name in names: |
| 370 | if name == os.curdir or name == os.pardir: |
| 371 | continue |
| 372 | if name == "CVS": |
| 373 | continue |
| 374 | if not os.path.isdir(name): |
| 375 | continue |
| 376 | if os.path.islink(name): |
| 377 | continue |
| 378 | print "--- entering subdirectory", name, "---" |
| 379 | os.chdir(name) |
| 380 | try: |
| 381 | if os.path.isdir("CVS"): |
| 382 | self.__class__().run() |
| 383 | else: |
| 384 | self.recurse() |
| 385 | finally: |
| 386 | os.chdir(os.pardir) |
| 387 | print "--- left subdirectory", name, "---" |
| 388 | |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 389 | def options(self, opts): |
| 390 | self.opts = opts |
| 391 | |
| 392 | def ready(self): |
| 393 | import rcsclient |
| 394 | self.proxy = rcsclient.openrcsclient(self.opts) |
| 395 | self.cvs.setproxy(self.proxy) |
| 396 | self.cvs.getentries() |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 397 | |
| 398 | def default(self): |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 399 | self.cvs.report([]) |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 400 | |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 401 | def do_report(self, opts, files): |
| 402 | self.cvs.report(files) |
| 403 | |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 404 | def do_update(self, opts, files): |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 405 | """update [-l] [-R] [file] ...""" |
| 406 | local = DEF_LOCAL |
| 407 | for o, a in opts: |
| 408 | if o == '-l': local = 1 |
| 409 | if o == '-R': local = 0 |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 410 | self.cvs.update(files) |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 411 | self.cvs.putentries() |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 412 | if not local and not files: |
| 413 | self.recurse() |
| 414 | flags_update = '-lR' |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 415 | do_up = do_update |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 416 | flags_up = flags_update |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 417 | |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 418 | def do_commit(self, opts, files): |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 419 | """commit [-m message] [file] ...""" |
| 420 | message = "" |
| 421 | for o, a in opts: |
| 422 | if o == '-m': message = a |
| 423 | self.cvs.commit(files, message) |
Guido van Rossum | 6bb4a51 | 1995-04-28 15:26:37 +0000 | [diff] [blame] | 424 | self.cvs.putentries() |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 425 | flags_commit = 'm:' |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 426 | do_com = do_commit |
| 427 | flags_com = flags_commit |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 428 | |
| 429 | def do_diff(self, opts, files): |
| 430 | """diff [difflags] [file] ...""" |
Guido van Rossum | ec8cfd4 | 1995-05-01 20:06:44 +0000 | [diff] [blame] | 431 | self.cvs.diff(files, opts) |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 432 | flags_diff = 'cbitwcefhnlr:sD:S:' |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 433 | do_dif = do_diff |
Guido van Rossum | d1972af | 1995-06-21 01:02:06 +0000 | [diff] [blame] | 434 | flags_dif = flags_diff |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 435 | |
Guido van Rossum | a79f5a3 | 1995-07-18 18:34:34 +0000 | [diff] [blame] | 436 | def do_add(self, opts, files): |
| 437 | """add file ...""" |
| 438 | if not files: |
| 439 | print "'rcvs add' requires at least one file" |
| 440 | return |
| 441 | self.cvs.add(files) |
| 442 | self.cvs.putentries() |
| 443 | |
| 444 | def do_remove(self, opts, files): |
| 445 | """remove file ...""" |
| 446 | if not files: |
| 447 | print "'rcvs remove' requires at least one file" |
| 448 | return |
| 449 | self.cvs.remove(files) |
| 450 | self.cvs.putentries() |
| 451 | do_rm = do_remove |
| 452 | |
| 453 | |
Guido van Rossum | 330e884 | 1995-04-28 17:56:32 +0000 | [diff] [blame] | 454 | |
| 455 | |
| 456 | def remove(fn): |
| 457 | try: |
| 458 | os.unlink(fn) |
| 459 | except os.error: |
| 460 | pass |
Guido van Rossum | ae21ced | 1995-04-28 14:32:26 +0000 | [diff] [blame] | 461 | |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 462 | |
Guido van Rossum | deb627c | 1995-04-27 21:28:53 +0000 | [diff] [blame] | 463 | def main(): |
Guido van Rossum | c218a7e | 1995-04-27 23:33:43 +0000 | [diff] [blame] | 464 | rcvs().run() |
Guido van Rossum | 097c55a | 1995-04-27 18:07:07 +0000 | [diff] [blame] | 465 | |
Guido van Rossum | 5f07b84 | 1995-04-26 22:57:11 +0000 | [diff] [blame] | 466 | |
| 467 | if __name__ == "__main__": |
Guido van Rossum | deb627c | 1995-04-27 21:28:53 +0000 | [diff] [blame] | 468 | main() |