Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/treesync.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 6cfe2982de42 |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
47100
diff
changeset
|
1 #! /usr/bin/env python3 |
|
6034
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 | 15 normalize the slave file |
| 16 if the files still differ: | |
| 17 copy the slave to the master | |
| 18 else (the master is newer): | |
| 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 |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
26 import os, sys, stat, getopt |
|
6034
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 | 40 if o == '-y': |
| 41 default_answer = "yes" | |
| 42 if o == '-n': | |
| 43 default_answer = "no" | |
| 44 if o == '-s': | |
| 45 write_slave = a | |
| 46 if o == '-m': | |
| 47 write_master = a | |
| 48 if o == '-d': | |
| 49 create_directories = a | |
| 50 if o == '-f': | |
| 51 create_files = a | |
| 52 if o == '-a': | |
| 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 | 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: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
57 print("usage: python", sys.argv[0] or "treesync.py", end=' ') |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
58 print("[-n] [-y] [-m y|n|a] [-s y|n|a] [-d y|n|a] [-f n|y|a]", end=' ') |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
59 print("slavedir masterdir") |
| 7735 | 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): |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
66 print("skipping master subdirectory", master) |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
67 print("-- not under CVS") |
| 7735 | 68 return |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
69 print("-"*40) |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
70 print("slave ", slave) |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
71 print("master", master) |
|
6034
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 | 73 if not okay("create slave directory %s?" % slave, |
| 74 answer=create_directories): | |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
75 print("skipping master subdirectory", master) |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
76 print("-- no corresponding slave", slave) |
| 7735 | 77 return |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
78 print("creating slave directory", slave) |
| 7735 | 79 try: |
| 80 os.mkdir(slave) | |
|
81017
6cfe2982de42
Use OESeeror instead of os.error (#16720)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
59522
diff
changeset
|
81 except OSError as msg: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
82 print("can't make slave directory", slave, ":", msg) |
| 7735 | 83 return |
| 84 else: | |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
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 | 90 mastername = os.path.join(master, name) |
| 91 slavename = os.path.join(slave, name) | |
| 92 if name == "CVS": | |
| 93 cvsdir = mastername | |
| 94 else: | |
| 95 if os.path.isdir(mastername) and not os.path.islink(mastername): | |
| 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 | 98 entries = os.path.join(cvsdir, "Entries") |
| 99 for e in open(entries).readlines(): | |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
100 words = e.split('/') |
| 7735 | 101 if words[0] == '' and words[1:]: |
| 102 name = words[1] | |
| 103 s = os.path.join(slave, name) | |
| 104 m = os.path.join(master, name) | |
| 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 | 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 | 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 | 113 sf = None |
|
6034
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 try: |
| 7735 | 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 | 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 | 119 if not mf: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
120 print("Neither master nor slave exists", master) |
| 7735 | 121 return |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
122 print("Creating missing slave", slave) |
| 7735 | 123 copy(master, slave, answer=create_files) |
| 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: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
126 print("Not updating missing master", master) |
| 7735 | 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 | 129 if identical(sf, mf): |
| 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 | 134 # Master is newer -- copy master to slave |
| 135 sf.close() | |
| 136 mf.close() | |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
137 print("Master ", master) |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
138 print("is newer than slave", slave) |
| 7735 | 139 copy(master, slave, answer=write_slave) |
| 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 |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
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: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
149 print("***UPDATING MASTER (BINARY COPY)***") |
| 7735 | 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: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
152 print("***UPDATING MASTER***") |
| 7735 | 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 | 159 sd = sf.read(BUFSIZE) |
| 160 md = mf.read(BUFSIZE) | |
| 161 if sd != md: return 0 | |
| 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 | 171 buf = f.read(BUFSIZE) |
| 172 if not buf: break | |
| 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'): |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
177 print("copying", src) |
|
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
178 print(" to", dst) |
|
6034
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 | 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 | 184 buf = f.read(BUFSIZE) |
| 185 if not buf: break | |
| 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 |
|
37045
081b4f0e81b7
Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents:
33074
diff
changeset
|
190 def raw_input(prompt): |
|
081b4f0e81b7
Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents:
33074
diff
changeset
|
191 sys.stdout.write(prompt) |
|
081b4f0e81b7
Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents:
33074
diff
changeset
|
192 sys.stdout.flush() |
|
081b4f0e81b7
Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents:
33074
diff
changeset
|
193 return sys.stdin.readline() |
|
081b4f0e81b7
Get rid of a bunch more raw_input references
Neal Norwitz <nnorwitz@gmail.com>
parents:
33074
diff
changeset
|
194 |
|
6034
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 def okay(prompt, answer='ask'): |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
196 answer = answer.strip().lower() |
|
6034
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 if not answer or answer[0] not in 'ny': |
|
47100
893a4dc17a91
Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents:
42427
diff
changeset
|
198 answer = input(prompt) |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
15930
diff
changeset
|
199 answer = answer.strip().lower() |
| 7735 | 200 if not answer: |
| 201 answer = default_answer | |
|
6034
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 if answer[:1] == 'y': |
| 7735 | 203 return 1 |
|
6034
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 if answer[:1] == 'n': |
| 7735 | 205 return 0 |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
40587
diff
changeset
|
206 print("Yes or No please -- try again:") |
|
6034
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 return okay(prompt) |
|
1cf79ea8ffa2
Source tree synchronization tool (for Windowes, mostly)
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
25219
diff
changeset
|
209 if __name__ == '__main__': |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
25219
diff
changeset
|
210 main() |
