Ticket #1274: no-pywin32.darcs.patch

File no-pywin32.darcs.patch, 12.4 KB (added by davidsarah, at 2010-12-31T22:17:20Z)

Eliminate direct dependencies of Tahoe-LAFS on pywin32 (updated to trunk post-#1195). refs #1274

Line 
11 patch for repository davidsarah@dev.allmydata.org:/home/darcs/tahoe/trunk:
2
3Fri Dec 31 21:27:45 GMT Standard Time 2010  david-sarah@jacaranda.org
4  * Eliminate direct dependencies of Tahoe-LAFS on pywin32 (updated to trunk post-#1195). refs #1274
5
6New patches:
7
8[Eliminate direct dependencies of Tahoe-LAFS on pywin32 (updated to trunk post-#1195). refs #1274
9david-sarah@jacaranda.org**20101231212745
10 Ignore-this: 1a64ebf2ddcd2e7d02a9a86ca2e3aaa9
11] {
12hunk ./src/allmydata/_auto_deps.py 68
13 ##    # it is going to offer iocp reactor.  We currently require process management.  It would be
14 ##    # better if Twisted would declare that it requires pywin32 if it is going to offer process
15 ##    # management.  That is twisted ticket #3238 -- http://twistedmatrix.com/trac/ticket/3238 .
16-##    # On the other hand, Tahoe also depends on pywin32 for getting free disk space statistics
17-##    # (although that is not a hard requirement: if win32api can't be imported then we don't
18-##    # rely on having the disk stats).
19 ##    install_requires.append('pywin32')
20 
21 if hasattr(sys, 'frozen'): # for py2exe
22hunk ./src/allmydata/util/fileutil.py 308
23     # there is always at least one Unicode path component.
24     return os.path.normpath(path)
25 
26-windows = False
27-try:
28-    import win32api, win32con
29-except ImportError:
30-    pass
31-else:
32-    windows = True
33-    # <http://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx>
34-    win32api.SetErrorMode(win32con.SEM_FAILCRITICALERRORS |
35-                          win32con.SEM_NOOPENFILEERRORBOX)
36+
37+have_GetDiskFreeSpaceExW = False
38+if sys.platform == "win32":
39+    try:
40+        from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_ulonglong
41+        from ctypes.wintypes import BOOL, DWORD, LPCWSTR
42+
43+        # <http://msdn.microsoft.com/en-us/library/aa383742%28v=VS.85%29.aspx>
44+        PULARGE_INTEGER = POINTER(c_ulonglong)
45+
46+        # <http://msdn.microsoft.com/en-us/library/aa364937%28VS.85%29.aspx>
47+        GetDiskFreeSpaceExW = WINFUNCTYPE(BOOL, LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER)(
48+            ("GetDiskFreeSpaceExW", windll.kernel32))
49+
50+        # <http://msdn.microsoft.com/en-us/library/ms679360%28v=VS.85%29.aspx>
51+        GetLastError = WINFUNCTYPE(DWORD)(("GetLastError", windll.kernel32))
52+
53+        have_GetDiskFreeSpaceExW = True
54+    except Exception:
55+        import traceback
56+        traceback.print_exc()
57 
58 def get_disk_stats(whichdir, reserved_space=0):
59     """Return disk statistics for the storage disk, in the form of a dict
60hunk ./src/allmydata/util/fileutil.py 352
61     filesystem as reserved_space.
62     """
63 
64-    if windows:
65-        # For Windows systems, where os.statvfs is not available, use GetDiskFreeSpaceEx.
66-        # <http://docs.activestate.com/activepython/2.5/pywin32/win32api__GetDiskFreeSpaceEx_meth.html>
67-        #
68-        # Although the docs say that the argument should be the root directory
69-        # of a disk, GetDiskFreeSpaceEx actually accepts any path on that disk
70-        # (like its Win32 equivalent).
71+    if have_GetDiskFreeSpaceExW:
72+        # If this is a Windows system and GetDiskFreeSpaceExW is available, use it.
73+        # (This might put up an error dialog unless
74+        # SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX) has been called,
75+        # which we do in allmydata.windows.fixups.initialize().)
76 
77hunk ./src/allmydata/util/fileutil.py 358
78-        (free_for_nonroot, total, free_for_root) = win32api.GetDiskFreeSpaceEx(whichdir)
79+        n_free_for_nonroot = c_ulonglong(0)
80+        n_total            = c_ulonglong(0)
81+        n_free_for_root    = c_ulonglong(0)
82+        retval = GetDiskFreeSpaceExW(whichdir, byref(n_free_for_nonroot),
83+                                               byref(n_total),
84+                                               byref(n_free_for_root))
85+        if retval == 0:
86+            raise OSError("Windows error %d attempting to get disk statistics for %r"
87+                          % (GetLastError(), whichdir))
88+        free_for_nonroot = n_free_for_nonroot.value
89+        total            = n_total.value
90+        free_for_root    = n_free_for_root.value
91     else:
92         # For Unix-like systems.
93         # <http://docs.python.org/library/os.html#os.statvfs>
94hunk ./src/allmydata/util/fileutil.py 395
95     used = total - free_for_root
96     avail = max(free_for_nonroot - reserved_space, 0)
97 
98-    return { 'total': total, 'free_for_root': free_for_root,
99+    return { 'total': total,
100+             'free_for_root': free_for_root,
101              'free_for_nonroot': free_for_nonroot,
102hunk ./src/allmydata/util/fileutil.py 398
103-             'used': used, 'avail': avail, }
104+             'used': used,
105+             'avail': avail,
106+           }
107 
108 def get_available_space(whichdir, reserved_space):
109     """Returns available space for share storage in bytes, or None if no
110hunk ./src/allmydata/windows/fixups.py 11
111         return True
112     done = True
113 
114+    import codecs, re
115+    from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_int
116+    from ctypes.wintypes import BOOL, HANDLE, DWORD, UINT, LPWSTR, LPCWSTR, LPVOID
117+    from allmydata.util import log
118+    from allmydata.util.encodingutil import canonical_encoding
119+
120+    # <http://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx>
121+    SetErrorMode = WINFUNCTYPE(UINT, UINT)(("SetErrorMode", windll.kernel32))
122+    SEM_FAILCRITICALERRORS = 0x0001
123+    SEM_NOOPENFILEERRORBOX = 0x8000
124+
125+    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX)
126+
127     original_stderr = sys.stderr
128 
129     # If any exception occurs in this code, we'll probably try to print it on stderr,
130hunk ./src/allmydata/windows/fixups.py 34
131         print >>original_stderr, isinstance(message, str) and message or repr(message)
132         log.msg(message, level=log.WEIRD)
133 
134-    import codecs, re
135-    from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_int
136-    from ctypes.wintypes import BOOL, HANDLE, DWORD, LPWSTR, LPCWSTR, LPVOID
137-    from allmydata.util import log
138-    from allmydata.util.encodingutil import canonical_encoding
139-
140     # Work around <http://bugs.python.org/issue6058>.
141     codecs.register(lambda name: name == 'cp65001' and codecs.lookup('utf-8') or None)
142 
143}
144
145Context:
146
147[test_storage.py: leave at least 512 MiB free when running test_large_share. refs #1195
148david-sarah@jacaranda.org**20101231203215
149 Ignore-this: b2144c0341c3452b5d4ba219e284ea0e
150]
151[storage: use fileutil's version of get_disk_stats() and get_available_space(), use mockery/fakery in tests, enable large share test on platforms with sparse files and if > 4 GiB of disk space is currently available
152zooko@zooko.com**20100910173629
153 Ignore-this: 1304f1164c661de6d5304f993eb9b27b
154]
155[fileutil: copy in the get_disk_stats() and get_available_space() functions from storage/server.py
156zooko@zooko.com**20100910173520
157 Ignore-this: 8b15569715f710f4fc5092f7ca109253
158]
159[Update foolscap version requirement to 0.6.0, to address http://foolscap.lothar.com/trac/ticket/167
160david-sarah@jacaranda.org**20101231060039
161 Ignore-this: 98d2b8086a1a500b9f4565bca5a3810
162]
163[docs/webapi.rst: typos.
164david-sarah@jacaranda.org**20101230034422
165 Ignore-this: d1f5166d72cc711f7e0d9981eac9105e
166]
167[docs/webapi.rst: capitalization, formatting of section on URL character encoding, and a correction about Internet Explorer.
168david-sarah@jacaranda.org**20101230034049
169 Ignore-this: b3b9819d2fb264b4cdc5c8afd4e8c48d
170]
171[docs: corrections and clarifications.
172david-sarah@jacaranda.org**20101227051056
173 Ignore-this: e33202858c7644c58f3f924b164294b6
174]
175[docs: more formatting cleanups and corrections. Spell webapi and wapi as web-API.
176david-sarah@jacaranda.org**20101227050533
177 Ignore-this: 18b23cbfb780df585d8a722a1ec63e94
178]
179[docs/debian.rst: bring description of building dependencies from source up-to-date, and change hostname from allmydata.com to tahoe-lafs.org.
180david-sarah@jacaranda.org**20101212222912
181 Ignore-this: f38462afc88b4475195610385a28391c
182]
183[docs/architecture.rst: correct rst syntax.
184david-sarah@jacaranda.org**20101212202003
185 Ignore-this: 3fbe12feb28bec6f1c63aedbc79aad21
186]
187[docs/architecture.rst: formatting.
188david-sarah@jacaranda.org**20101212201719
189 Ignore-this: 305fa5dfc2939355eaf6d0d2161eb1ff
190]
191[docs: linkification, wording improvements.
192david-sarah@jacaranda.org**20101212201234
193 Ignore-this: 4e67287f527a8bc728cfbd93255d2aae
194]
195[docs: formatting.
196david-sarah@jacaranda.org**20101212201115
197 Ignore-this: 2e0ed394ac7726651d3a4f2c4b0d3798
198]
199[docs/configuration.rst: more formatting tweaks; which -> that.
200david-sarah@jacaranda.org**20101212195522
201 Ignore-this: a7becb7021854ca5a90edd892b36fdd7
202]
203[docs/configuration.rst: more changes to formatting.
204david-sarah@jacaranda.org**20101212194511
205 Ignore-this: 491aac33e5f5268d224359f1447d10be
206]
207[docs/configuration.rst: changes to formatting (mainly putting commands and filenames in monospace).
208david-sarah@jacaranda.org**20101212181828
209 Ignore-this: 8a1480e2d5f43bee678476424615b50f
210]
211[scripts/backupdb.py: more accurate comment about path field.
212david-sarah@jacaranda.org**20101212170320
213 Ignore-this: 50e47a2228a85207bbcd188a78a0d4e6
214]
215[scripts/cli.py: fix missing 'put' in usage example for 'tahoe put'.
216david-sarah@jacaranda.org**20101212170207
217 Ignore-this: 2cbadf066fff611fc03d3c0ff97ce6ec
218]
219[docs/frontends/CLI.rst: changes to formatting (mainly putting commands and filenames in monospace), and to command syntax to reflect that DIRCAP/... is accepted. Clarify the syntax of 'tahoe put' and other minor corrections. Tahoe -> Tahoe-LAFS.
220david-sarah@jacaranda.org**20101212165800
221 Ignore-this: a123ef6b564aa8624d1e79c97068ea12
222]
223[docs/frontends/CLI.rst: Unicode arguments to 'tahoe' work on Windows as of v1.7.1.
224david-sarah@jacaranda.org**20101212063740
225 Ignore-this: 3977a99dfa86ac33a44171deaf43aaab
226]
227[docs/known_issues.rst: fix title and linkify another URL. refs #1225
228david-sarah@jacaranda.org**20101212062817
229 Ignore-this: cc91287f7fb51c23440b3d2fe79c449c
230]
231[docs/known_issues.rst: fix an external link. refs #1225
232david-sarah@jacaranda.org**20101212062435
233 Ignore-this: b8cbf12f353131756c358965c48060ec
234]
235[Fix a link from uri.rst to dirnodes.rst. refs #1225
236david-sarah@jacaranda.org**20101212054502
237 Ignore-this: af6205299f5c9a33229cab259c00f9d5
238]
239[Fix a link from webapi.rst to FTP-and-SFTP.rst. refs #1225
240david-sarah@jacaranda.org**20101212053435
241 Ignore-this: 2b9f88678c3447ea860d6b61e8799858
242]
243[More specific hyperlink to architecture.rst from helper.rst. refs #1225
244david-sarah@jacaranda.org**20101212052607
245 Ignore-this: 50424c768fca481252fabf58424852dc
246]
247[Update hyperlinks between docs, and linkify some external references. refs #1225
248david-sarah@jacaranda.org**20101212051459
249 Ignore-this: cd43a4c3d3de1f832abfa88d5fc4ace1
250]
251[docs/specifications/dirnodes.rst: fix references to mutable.rst. refs #1225
252david-sarah@jacaranda.org**20101212012720
253 Ignore-this: 6819b4b4e06e947ee48b365e840db37d
254]
255[docs/specifications/mutable.rst: correct the magic string for v1 mutable containers. refs #1225
256david-sarah@jacaranda.org**20101212011400
257 Ignore-this: 99a5fcdd40cef83dbb08f323f6cdaaca
258]
259[Move .txt files in docs/frontends and docs/specifications to .rst. refs #1225
260david-sarah@jacaranda.org**20101212010251
261 Ignore-this: 8796d35d928370f7dc6ad2dafdc1c0fe
262]
263[Convert docs/frontends and docs/specifications to reStructuredText format (not including file moves).
264david-sarah@jacaranda.org**20101212004632
265 Ignore-this: e3ceb2d832d73875abe48624ddbb5622
266]
267[scripts/cli.py: remove the disclaimer in the help for 'tahoe cp' that it does not handle non-ASCII filenames well. (At least, we intend to handle them.)
268david-sarah@jacaranda.org**20101130002145
269 Ignore-this: 94c003efaa20b9eb4a83503d79844ca
270]
271[relnotes.txt: fifth -> sixth labor-of-love release
272zooko@zooko.com**20101129045647
273 Ignore-this: 21c245015268b38916e3a138d256c09d
274]
275[Makefile: BB_BRANCH is set to the empty string for trunk, not the string 'trunk'.
276david-sarah@jacaranda.org**20101128233512
277 Ignore-this: 5a7ef8eb10475636d21b91e25b56c369
278]
279[relnotes.txt: eleventh -> twelfth release.
280david-sarah@jacaranda.org**20101128223321
281 Ignore-this: 1e26410156a665271c1170803dea2c0d
282]
283[relnotes.tst: point to known_issues.rst, not known_issues.txt.
284david-sarah@jacaranda.org**20101128222918
285 Ignore-this: 60194eb4544cac446fe4f60b3e34b887
286]
287[quickstart.html: fix link to point to allmydata-tahoe-1.8.1.zip.
288david-sarah@jacaranda.org**20101128221728
289 Ignore-this: 7b3ee86f8256aa12f5d862f689f3ee29
290]
291[TAG allmydata-tahoe-1.8.1
292david-sarah@jacaranda.org**20101128212336
293 Ignore-this: 9c18bdeaef4822f590d2a0d879e00621
294]
295Patch bundle hash:
2963621174e5b51bf0e0e60b2e0890cb787893bd621