diff options
author | Guido van Rossum <guido@python.org> | 1998-03-24 05:30:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-03-24 05:30:29 (GMT) |
commit | ed5b3d8b3c8077c8c57c8a825cae06e319b0994d (patch) | |
tree | f200df16bbb012dcfe74b75a990c32709e80f44a /Tools/scripts/treesync.py | |
parent | 3db0e3713cd59d1c922002056f11ae5caf02805c (diff) | |
download | cpython-ed5b3d8b3c8077c8c57c8a825cae06e319b0994d.zip cpython-ed5b3d8b3c8077c8c57c8a825cae06e319b0994d.tar.gz cpython-ed5b3d8b3c8077c8c57c8a825cae06e319b0994d.tar.bz2 |
give in to tab police
Diffstat (limited to 'Tools/scripts/treesync.py')
-rwxr-xr-x | Tools/scripts/treesync.py | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/Tools/scripts/treesync.py b/Tools/scripts/treesync.py index 26c3cd5..ded0b17 100755 --- a/Tools/scripts/treesync.py +++ b/Tools/scripts/treesync.py @@ -12,11 +12,11 @@ entry in the master tree are synchronized. This means: If the files differ: if the slave file is newer: - normalize the slave file - if the files still differ: - copy the slave to the master - else (the master is newer): - copy the master to the slave + normalize the slave file + if the files still differ: + copy the slave to the master + else (the master is newer): + copy the master to the slave normalizing the slave means replacing CRLF with LF when the master doesn't use CRLF @@ -37,107 +37,107 @@ def main(): global create_directories, write_master, write_slave opts, args = getopt.getopt(sys.argv[1:], "nym:s:d:f:a:") for o, a in opts: - if o == '-y': - default_answer = "yes" - if o == '-n': - default_answer = "no" - if o == '-s': - write_slave = a - if o == '-m': - write_master = a - if o == '-d': - create_directories = a - if o == '-f': - create_files = a - if o == '-a': - create_files = create_directories = write_slave = write_master = a + if o == '-y': + default_answer = "yes" + if o == '-n': + default_answer = "no" + if o == '-s': + write_slave = a + if o == '-m': + write_master = a + if o == '-d': + create_directories = a + if o == '-f': + create_files = a + if o == '-a': + create_files = create_directories = write_slave = write_master = a try: - [slave, master] = args + [slave, master] = args except ValueError: - print "usage: python", sys.argv[0] or "treesync.py", - print "[-n] [-y] [-m y|n|a] [-s y|n|a] [-d y|n|a] [-f n|y|a]", - print "slavedir masterdir" - return + print "usage: python", sys.argv[0] or "treesync.py", + print "[-n] [-y] [-m y|n|a] [-s y|n|a] [-d y|n|a] [-f n|y|a]", + print "slavedir masterdir" + return process(slave, master) def process(slave, master): cvsdir = os.path.join(master, "CVS") if not os.path.isdir(cvsdir): - print "skipping master subdirectory", master - print "-- not under CVS" - return + print "skipping master subdirectory", master + print "-- not under CVS" + return print "-"*40 print "slave ", slave print "master", master if not os.path.isdir(slave): - if not okay("create slave directory %s?" % slave, - answer=create_directories): - print "skipping master subdirectory", master - print "-- no corresponding slave", slave - return - print "creating slave directory", slave - try: - os.mkdir(slave) - except os.error, msg: - print "can't make slave directory", slave, ":", msg - return - else: - print "made slave directory", slave + if not okay("create slave directory %s?" % slave, + answer=create_directories): + print "skipping master subdirectory", master + print "-- no corresponding slave", slave + return + print "creating slave directory", slave + try: + os.mkdir(slave) + except os.error, msg: + print "can't make slave directory", slave, ":", msg + return + else: + print "made slave directory", slave cvsdir = None subdirs = [] names = os.listdir(master) for name in names: - mastername = os.path.join(master, name) - slavename = os.path.join(slave, name) - if name == "CVS": - cvsdir = mastername - else: - if os.path.isdir(mastername) and not os.path.islink(mastername): - subdirs.append((slavename, mastername)) + mastername = os.path.join(master, name) + slavename = os.path.join(slave, name) + if name == "CVS": + cvsdir = mastername + else: + if os.path.isdir(mastername) and not os.path.islink(mastername): + subdirs.append((slavename, mastername)) if cvsdir: - entries = os.path.join(cvsdir, "Entries") - for e in open(entries).readlines(): - words = string.split(e, '/') - if words[0] == '' and words[1:]: - name = words[1] - s = os.path.join(slave, name) - m = os.path.join(master, name) - compare(s, m) + entries = os.path.join(cvsdir, "Entries") + for e in open(entries).readlines(): + words = string.split(e, '/') + if words[0] == '' and words[1:]: + name = words[1] + s = os.path.join(slave, name) + m = os.path.join(master, name) + compare(s, m) for (s, m) in subdirs: - process(s, m) + process(s, m) def compare(slave, master): try: - sf = open(slave, 'r') + sf = open(slave, 'r') except IOError: - sf = None + sf = None try: - mf = open(master, 'rb') + mf = open(master, 'rb') except IOError: - mf = None + mf = None if not sf: - if not mf: - print "Neither master nor slave exists", master - return - print "Creating missing slave", slave - copy(master, slave, answer=create_files) - return + if not mf: + print "Neither master nor slave exists", master + return + print "Creating missing slave", slave + copy(master, slave, answer=create_files) + return if not mf: - print "Not updating missing master", master - return + print "Not updating missing master", master + return if sf and mf: - if identical(sf, mf): - return + if identical(sf, mf): + return sft = mtime(sf) mft = mtime(mf) if mft > sft: - # Master is newer -- copy master to slave - sf.close() - mf.close() - print "Master ", master - print "is newer than slave", slave - copy(master, slave, answer=write_slave) - return + # Master is newer -- copy master to slave + sf.close() + mf.close() + print "Master ", master + print "is newer than slave", slave + copy(master, slave, answer=write_slave) + return # Slave is newer -- copy slave to master print "Slave is", sft-mft, "seconds newer than master" # But first check what to do about CRLF @@ -146,20 +146,20 @@ def compare(slave, master): mf.close() sf.close() if fun: - print "***UPDATING MASTER (BINARY COPY)***" - copy(slave, master, "rb", answer=write_master) + print "***UPDATING MASTER (BINARY COPY)***" + copy(slave, master, "rb", answer=write_master) else: - print "***UPDATING MASTER***" - copy(slave, master, "r", answer=write_master) + print "***UPDATING MASTER***" + copy(slave, master, "r", answer=write_master) BUFSIZE = 16*1024 def identical(sf, mf): while 1: - sd = sf.read(BUFSIZE) - md = mf.read(BUFSIZE) - if sd != md: return 0 - if not sd: break + sd = sf.read(BUFSIZE) + md = mf.read(BUFSIZE) + if sd != md: return 0 + if not sd: break return 1 def mtime(f): @@ -168,36 +168,36 @@ def mtime(f): def funnychars(f): while 1: - buf = f.read(BUFSIZE) - if not buf: break - if '\r' in buf or '\0' in buf: return 1 + buf = f.read(BUFSIZE) + if not buf: break + if '\r' in buf or '\0' in buf: return 1 return 0 def copy(src, dst, rmode="rb", wmode="wb", answer='ask'): print "copying", src print " to", dst if not okay("okay to copy? ", answer): - return + return f = open(src, rmode) g = open(dst, wmode) while 1: - buf = f.read(BUFSIZE) - if not buf: break - g.write(buf) + buf = f.read(BUFSIZE) + if not buf: break + g.write(buf) f.close() g.close() def okay(prompt, answer='ask'): answer = string.lower(string.strip(answer)) if not answer or answer[0] not in 'ny': - answer = raw_input(prompt) - answer = string.lower(string.strip(answer)) - if not answer: - answer = default_answer + answer = raw_input(prompt) + answer = string.lower(string.strip(answer)) + if not answer: + answer = default_answer if answer[:1] == 'y': - return 1 + return 1 if answer[:1] == 'n': - return 0 + return 0 print "Yes or No please -- try again:" return okay(prompt) |