annotate Tools/scripts/treesync.py @ 24042:63fbbed10714 legacy-trunk

Simplify HTTPSConnection constructor. See discussion in SF bug 458463.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 28 Jun 2002 23:38:14 +0000
parents 14a27acc755a
children 8a7a2f1f88f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 """Script to synchronize two source trees.
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Invoke with two arguments:
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 python treesync.py slave master
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 The assumption is that "master" contains CVS administration while
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 slave doesn't. All files in the slave tree that have a CVS/Entries
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 entry in the master tree are synchronized. This means:
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 If the files differ:
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if the slave file is newer:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
15 normalize the slave file
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
16 if the files still differ:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
17 copy the slave to the master
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
18 else (the master is newer):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
19 copy the master to the slave
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 7735
diff changeset
20
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 normalizing the slave means replacing CRLF with LF when the master
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 doesn't use CRLF
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 """
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 import os, sys, stat, string, getopt
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 # Interactivity options
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 default_answer = "ask"
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 create_files = "yes"
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 create_directories = "no"
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 write_slave = "ask"
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 write_master = "ask"
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 def main():
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 global always_no, always_yes
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 global create_directories, write_master, write_slave
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 opts, args = getopt.getopt(sys.argv[1:], "nym:s:d:f:a:")
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 for o, a in opts:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
40 if o == '-y':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
41 default_answer = "yes"
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
42 if o == '-n':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
43 default_answer = "no"
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
44 if o == '-s':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
45 write_slave = a
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
46 if o == '-m':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
47 write_master = a
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
48 if o == '-d':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
49 create_directories = a
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
50 if o == '-f':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
51 create_files = a
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
52 if o == '-a':
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
53 create_files = create_directories = write_slave = write_master = a
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 try:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
55 [slave, master] = args
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 except ValueError:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
57 print "usage: python", sys.argv[0] or "treesync.py",
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
58 print "[-n] [-y] [-m y|n|a] [-s y|n|a] [-d y|n|a] [-f n|y|a]",
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
59 print "slavedir masterdir"
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
60 return
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 process(slave, master)
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 7735
diff changeset
62
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 def process(slave, master):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 cvsdir = os.path.join(master, "CVS")
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 if not os.path.isdir(cvsdir):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
66 print "skipping master subdirectory", master
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
67 print "-- not under CVS"
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
68 return
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 print "-"*40
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 print "slave ", slave
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 print "master", master
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 if not os.path.isdir(slave):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
73 if not okay("create slave directory %s?" % slave,
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
74 answer=create_directories):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
75 print "skipping master subdirectory", master
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
76 print "-- no corresponding slave", slave
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
77 return
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
78 print "creating slave directory", slave
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
79 try:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
80 os.mkdir(slave)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
81 except os.error, msg:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
82 print "can't make slave directory", slave, ":", msg
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
83 return
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
84 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
85 print "made slave directory", slave
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 cvsdir = None
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 subdirs = []
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 names = os.listdir(master)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 for name in names:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
90 mastername = os.path.join(master, name)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
91 slavename = os.path.join(slave, name)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
92 if name == "CVS":
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
93 cvsdir = mastername
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
94 else:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
95 if os.path.isdir(mastername) and not os.path.islink(mastername):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
96 subdirs.append((slavename, mastername))
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 if cvsdir:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
98 entries = os.path.join(cvsdir, "Entries")
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
99 for e in open(entries).readlines():
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
100 words = string.split(e, '/')
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
101 if words[0] == '' and words[1:]:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
102 name = words[1]
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
103 s = os.path.join(slave, name)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
104 m = os.path.join(master, name)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
105 compare(s, m)
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 for (s, m) in subdirs:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
107 process(s, m)
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 def compare(slave, master):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 try:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
111 sf = open(slave, 'r')
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 except IOError:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
113 sf = None
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 try:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
115 mf = open(master, 'rb')
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 except IOError:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
117 mf = None
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 if not sf:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
119 if not mf:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
120 print "Neither master nor slave exists", master
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
121 return
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
122 print "Creating missing slave", slave
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
123 copy(master, slave, answer=create_files)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
124 return
6553
2c6f2d92b315 When checking for equality, open the slave file in text mode so it
Guido van Rossum <guido@python.org>
parents: 6101
diff changeset
125 if not mf:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
126 print "Not updating missing master", master
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
127 return
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 if sf and mf:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
129 if identical(sf, mf):
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
130 return
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 sft = mtime(sf)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 mft = mtime(mf)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 if mft > sft:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
134 # Master is newer -- copy master to slave
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
135 sf.close()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
136 mf.close()
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
137 print "Master ", master
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
138 print "is newer than slave", slave
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
139 copy(master, slave, answer=write_slave)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
140 return
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 # Slave is newer -- copy slave to master
6553
2c6f2d92b315 When checking for equality, open the slave file in text mode so it
Guido van Rossum <guido@python.org>
parents: 6101
diff changeset
142 print "Slave is", sft-mft, "seconds newer than master"
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 # But first check what to do about CRLF
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 mf.seek(0)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 fun = funnychars(mf)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 mf.close()
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 sf.close()
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 if fun:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
149 print "***UPDATING MASTER (BINARY COPY)***"
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
150 copy(slave, master, "rb", answer=write_master)
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 else:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
152 print "***UPDATING MASTER***"
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
153 copy(slave, master, "r", answer=write_master)
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 BUFSIZE = 16*1024
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 def identical(sf, mf):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
159 sd = sf.read(BUFSIZE)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
160 md = mf.read(BUFSIZE)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
161 if sd != md: return 0
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
162 if not sd: break
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 return 1
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
164
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 def mtime(f):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 st = os.fstat(f.fileno())
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 return st[stat.ST_MTIME]
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 def funnychars(f):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
171 buf = f.read(BUFSIZE)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
172 if not buf: break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
173 if '\r' in buf or '\0' in buf: return 1
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 return 0
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 def copy(src, dst, rmode="rb", wmode="wb", answer='ask'):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 print "copying", src
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 print " to", dst
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 if not okay("okay to copy? ", answer):
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
180 return
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 f = open(src, rmode)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 g = open(dst, wmode)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 while 1:
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
184 buf = f.read(BUFSIZE)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
185 if not buf: break
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
186 g.write(buf)
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 f.close()
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 g.close()
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
189
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 def okay(prompt, answer='ask'):
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 answer = string.lower(string.strip(answer))
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 if not answer or answer[0] not in 'ny':
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
193 answer = raw_input(prompt)
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
194 answer = string.lower(string.strip(answer))
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
195 if not answer:
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
196 answer = default_answer
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 if answer[:1] == 'y':
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
198 return 1
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 if answer[:1] == 'n':
7735
7a9afaba88d8 give in to tab police
Guido van Rossum <guido@python.org>
parents: 6553
diff changeset
200 return 0
6034
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 print "Yes or No please -- try again:"
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 return okay(prompt)
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
203
1cf79ea8ffa2 Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 main()