1995-04-27 15:07:07 -03:00
|
|
|
#! /usr/local/bin/python
|
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
"""Remote CVS -- command line interface"""
|
1995-04-27 15:07:07 -03:00
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
from cvslib import CVS, File
|
1995-04-26 19:57:11 -03:00
|
|
|
import md5
|
|
|
|
import os
|
|
|
|
import string
|
|
|
|
import sys
|
1995-04-27 20:33:43 -03:00
|
|
|
from cmdfw import CommandFrameWork
|
1995-04-26 19:57:11 -03:00
|
|
|
|
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
class MyFile(File):
|
1995-04-26 19:57:11 -03:00
|
|
|
|
1995-04-28 11:32:26 -03:00
|
|
|
def action(self):
|
|
|
|
"""Return a code indicating the update status of this file.
|
|
|
|
|
|
|
|
The possible return values are:
|
1995-04-27 20:33:43 -03:00
|
|
|
|
1995-04-28 11:32:26 -03:00
|
|
|
'=' -- everything's fine
|
|
|
|
'0' -- file doesn't exist anywhere
|
|
|
|
'?' -- exists locally only
|
|
|
|
'A' -- new locally
|
|
|
|
'R' -- deleted locally
|
|
|
|
'U' -- changed remotely, no changes locally
|
|
|
|
'M' -- changed locally, no changes remotely
|
|
|
|
'C' -- conflict: changed locally as well as remotely
|
|
|
|
(includes cases where the file has been added
|
|
|
|
or removed locally and remotely)
|
|
|
|
"""
|
|
|
|
if not self.eseen:
|
|
|
|
pass
|
|
|
|
return '?'
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
code = self.action()
|
|
|
|
print code, self.file
|
|
|
|
if code == 'U':
|
|
|
|
self.get()
|
|
|
|
elif code == 'C':
|
|
|
|
print "%s: conflict resolution not yet implemented" % \
|
|
|
|
self.file
|
|
|
|
|
|
|
|
def commit(self, message = ""):
|
|
|
|
code = self.action()
|
|
|
|
if code in ('A', 'M'):
|
|
|
|
self.put(message)
|
|
|
|
elif code == 'R':
|
|
|
|
print "%s: committing removes not yet implemented" % \
|
|
|
|
self.file
|
|
|
|
elif code == 'C':
|
|
|
|
print "%s: conflict resolution not yet implemented" % \
|
|
|
|
self.file
|
|
|
|
|
|
|
|
def commitcheck(self):
|
|
|
|
return self.action() != 'C'
|
|
|
|
|
|
|
|
def put(self, message = ""):
|
|
|
|
print "%s: put not yet implemented" % self.file
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
data = self.proxy.get(self.file)
|
|
|
|
f = open(self.file, 'w')
|
|
|
|
f.write(data)
|
|
|
|
f.close()
|
|
|
|
self.eseen = 1
|
|
|
|
self.esum = self.rsum
|
|
|
|
self.emtime, self.ectime = os.stat(self.file)[-2:]
|
|
|
|
self.erev = self.rrev
|
|
|
|
self.enew = 0
|
|
|
|
self.edeleted = 0
|
|
|
|
# XXX anything else?
|
1995-04-26 19:57:11 -03:00
|
|
|
|
1995-04-27 15:07:07 -03:00
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
class RCVS(CVS):
|
1995-04-27 15:07:07 -03:00
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
FileClass = MyFile
|
1995-04-27 15:07:07 -03:00
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
def __init__(self):
|
|
|
|
CVS.__init__(self)
|
1995-04-27 15:07:07 -03:00
|
|
|
|
1995-04-27 20:33:43 -03:00
|
|
|
def checkfiles(self, files):
|
|
|
|
if not files:
|
|
|
|
def ok(file, self=self):
|
|
|
|
e = self.entries[file]
|
|
|
|
return e.eseen or e.rseen
|
|
|
|
files[:] = filter(ok, self.entries.keys())
|
|
|
|
files.sort()
|
1995-04-28 11:32:26 -03:00
|
|
|
if not files:
|
|
|
|
print "no files to be processed"
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
sts = None
|
|
|
|
for file in files:
|
|
|
|
if not self.entries.has_key(file):
|
|
|
|
print "%s: nothing known" % file
|
|
|
|
sts = 1
|
|
|
|
return sts
|
1995-04-27 20:33:43 -03:00
|
|
|
|
|
|
|
|
|
|
|
class rcvs(CommandFrameWork):
|
|
|
|
|
|
|
|
GlobalFlags = 'd:h:p:qv'
|
|
|
|
UsageMessage = \
|
|
|
|
"usage: rcvs [-d directory] [-h host] [-p port] [-q] [-v] subcommand arg ..."
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Constructor."""
|
|
|
|
CommandFrameWork.__init__(self)
|
|
|
|
self.proxy = None
|
|
|
|
self.cvs = RCVS()
|
|
|
|
|
|
|
|
def options(self, opts):
|
|
|
|
self.opts = opts
|
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
import rcsclient
|
|
|
|
self.proxy = rcsclient.openrcsclient(self.opts)
|
|
|
|
self.cvs.setproxy(self.proxy)
|
|
|
|
self.cvs.getentries()
|
|
|
|
self.cvs.getlocalfiles()
|
|
|
|
self.cvs.getremotefiles(self.proxy)
|
|
|
|
|
|
|
|
def default(self):
|
1995-04-28 11:32:26 -03:00
|
|
|
files = []
|
|
|
|
if self.cvs.checkfiles(files):
|
|
|
|
return 1
|
1995-04-27 20:33:43 -03:00
|
|
|
self.cvs.report()
|
|
|
|
|
|
|
|
def do_update(self, opts, files):
|
1995-04-28 11:32:26 -03:00
|
|
|
"""update [file] ..."""
|
|
|
|
if self.cvs.checkfiles(files):
|
|
|
|
return 1
|
1995-04-27 20:33:43 -03:00
|
|
|
for file in files:
|
|
|
|
if not self.cvs.entries.has_key(file):
|
|
|
|
print "%s: not found" % file
|
|
|
|
else:
|
|
|
|
self.cvs.entries[file].update()
|
1995-04-26 19:57:11 -03:00
|
|
|
|
1995-04-28 11:32:26 -03:00
|
|
|
def do_commit(self, opts, files):
|
|
|
|
"""commit [file] ..."""
|
|
|
|
if self.cvs.checkfiles(files):
|
|
|
|
return 1
|
|
|
|
sts = 0
|
|
|
|
for file in files:
|
|
|
|
if not self.entries[file].commitcheck():
|
|
|
|
sts = 1
|
|
|
|
if sts:
|
|
|
|
return sts
|
|
|
|
message = raw_input("One-liner: ")
|
|
|
|
for file in files:
|
|
|
|
self.entries[file].commit(message)
|
|
|
|
|
1995-04-26 19:57:11 -03:00
|
|
|
|
1995-04-27 18:28:53 -03:00
|
|
|
def main():
|
1995-04-27 20:33:43 -03:00
|
|
|
rcvs().run()
|
1995-04-27 15:07:07 -03:00
|
|
|
|
1995-04-26 19:57:11 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
1995-04-27 18:28:53 -03:00
|
|
|
main()
|