Changeset 6d4a8bc in trunk
- Timestamp:
- 2016-01-15T19:15:38Z (9 years ago)
- Branches:
- master
- Children:
- 6226f6b
- Parents:
- 41cf6008 (diff), f282445 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/allmydata
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/node.py ¶
r41cf6008 r6d4a8bc 13 13 from allmydata.util.fileutil import abspath_expanduser_unicode 14 14 from allmydata.util.encodingutil import get_filesystem_encoding, quote_output 15 from allmydata.util import configutil 15 16 16 17 # Add our application versions to the data that Foolscap's LogPublisher … … 134 135 return default 135 136 136 def set_config(self, section, option, value):137 if not self.config.has_section(section):138 self.config.add_section(section)139 self.config.set(section, option, value)140 assert self.config.get(section, option) == value141 142 137 def read_config(self): 143 138 self.error_about_old_config_files() … … 146 141 tahoe_cfg = os.path.join(self.basedir, "tahoe.cfg") 147 142 try: 148 f = open(tahoe_cfg, "rb") 149 try: 150 # Skip any initial Byte Order Mark. Since this is an ordinary file, we 151 # don't need to handle incomplete reads, and can assume seekability. 152 if f.read(3) != '\xEF\xBB\xBF': 153 f.seek(0) 154 self.config.readfp(f) 155 finally: 156 f.close() 143 self.config = configutil.get_config(tahoe_cfg) 157 144 except EnvironmentError: 158 145 if os.path.exists(tahoe_cfg): … … 166 153 try: 167 154 file_tubport = fileutil.read(self._portnumfile).strip() 168 self.set_config("node", "tub.port", file_tubport)155 configutil.set_config(self.config, "node", "tub.port", file_tubport) 169 156 except EnvironmentError: 170 157 if os.path.exists(self._portnumfile): -
TabularUnified src/allmydata/scripts/common.py ¶
r41cf6008 r6d4a8bc 58 58 59 59 def parseArgs(self, basedir=None): 60 if self.parent['node-directory'] and self['basedir']: 60 # This finds the node-directory option correctly even if we are in a subcommand. 61 root = self.parent 62 while root.parent is not None: 63 root = root.parent 64 65 if root['node-directory'] and self['basedir']: 61 66 raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) options cannot both be used.") 62 if self.parent['node-directory'] and basedir:67 if root['node-directory'] and basedir: 63 68 raise usage.UsageError("The --node-directory (or -d) option and a basedir argument cannot both be used.") 64 69 if self['basedir'] and basedir: … … 69 74 elif self['basedir']: 70 75 b = argv_to_abspath(self['basedir']) 71 elif self.parent['node-directory']:72 b = argv_to_abspath( self.parent['node-directory'])76 elif root['node-directory']: 77 b = argv_to_abspath(root['node-directory']) 73 78 elif self.default_nodedir: 74 79 b = self.default_nodedir … … 76 81 raise usage.UsageError("No default basedir available, you must provide one with --node-directory, --basedir, or a basedir argument") 77 82 self['basedir'] = b 83 self['node-directory'] = b 78 84 79 85 def postOptions(self): -
TabularUnified src/allmydata/scripts/tahoe_add_alias.py ¶
r41cf6008 r6d4a8bc 2 2 import os.path 3 3 import codecs 4 5 from allmydata.util.assertutil import precondition 6 4 7 from allmydata import uri 5 8 from allmydata.scripts.common_http import do_http, check_http_error … … 30 33 nodedir = options['node-directory'] 31 34 alias = options.alias 35 precondition(isinstance(alias, unicode), alias=alias) 32 36 cap = options.cap 33 37 stdout = options.stdout … … 57 61 nodedir = options['node-directory'] 58 62 alias = options.alias 63 precondition(isinstance(alias, unicode), alias=alias) 59 64 stdout = options.stdout 60 65 stderr = options.stderr -
TabularUnified src/allmydata/test/test_cli.py ¶
r41cf6008 r6d4a8bc 37 37 from allmydata.util.assertutil import precondition 38 38 from allmydata.util.encodingutil import listdir_unicode, unicode_platform, \ 39 get_io_encoding, get_filesystem_encoding 39 get_io_encoding, get_filesystem_encoding, unicode_to_argv 40 40 41 41 timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s … … 50 50 class CLITestMixin(ReallyEqualMixin): 51 51 def do_cli(self, verb, *args, **kwargs): 52 precondition(not [True for arg in args if not isinstance(arg, str)], 53 "arguments to do_cli must be strs -- convert using unicode_to_argv", args=args) 54 55 # client_num is used to execute client CLI commands on a specific client. 56 client_num = kwargs.get("client_num", 0) 57 52 58 nodeargs = [ 53 "--node-directory", self.get_clientdir(),59 "--node-directory", unicode_to_argv(self.get_clientdir(i=client_num)), 54 60 ] 55 61 argv = nodeargs + [verb] + list(args) -
TabularUnified src/allmydata/test/test_encodingutil.py ¶
r41cf6008 r6d4a8bc 401 401 402 402 def test_quote_output_default(self): 403 encodingutil.io_encoding = 'ascii'403 self.patch(encodingutil, 'io_encoding', 'ascii') 404 404 self.test_quote_output_ascii(None) 405 405 406 encodingutil.io_encoding = 'latin1'406 self.patch(encodingutil, 'io_encoding', 'latin1') 407 407 self.test_quote_output_latin1(None) 408 408 409 encodingutil.io_encoding = 'utf-8'409 self.patch(encodingutil, 'io_encoding', 'utf-8') 410 410 self.test_quote_output_utf8(None) 411 411 -
TabularUnified src/allmydata/uri.py ¶
r41cf6008 r6d4a8bc 731 731 def from_string(u, deep_immutable=False, name=u"<unknown name>"): 732 732 if not isinstance(u, str): 733 raise TypeError(" unknown URI type: %s.." % str(u)[:100])733 raise TypeError("URI must be str: %r" % (u,)) 734 734 735 735 # We allow and check ALLEGED_READONLY_PREFIX or ALLEGED_IMMUTABLE_PREFIX -
TabularUnified src/allmydata/util/encodingutil.py ¶
r41cf6008 r6d4a8bc 89 89 (quote_output(s), io_encoding)) 90 90 91 def argv_to_abspath(s ):91 def argv_to_abspath(s, **kwargs): 92 92 """ 93 93 Convenience function to decode an argv element to an absolute path, with ~ expanded. 94 94 If this fails, raise a UsageError. 95 95 """ 96 return abspath_expanduser_unicode(argv_to_unicode(s)) 96 decoded = argv_to_unicode(s) 97 if decoded.startswith(u'-'): 98 raise usage.UsageError("Path argument %s cannot start with '-'.\nUse %s if you intended to refer to a file." 99 % (quote_output(s), quote_output(os.path.join('.', s)))) 100 return abspath_expanduser_unicode(decoded, **kwargs) 97 101 98 102 def unicode_to_argv(s, mangle=False): -
TabularUnified src/allmydata/util/fileutil.py ¶
r41cf6008 r6d4a8bc 4 4 5 5 import sys, exceptions, os, stat, tempfile, time, binascii 6 7 if sys.platform == "win32": 8 from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, c_ulonglong, \ 9 create_unicode_buffer, get_last_error 10 from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR 6 11 7 12 from twisted.python import log … … 336 341 have_GetDiskFreeSpaceExW = False 337 342 if sys.platform == "win32": 338 from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_ulonglong, create_unicode_buffer, \339 get_last_error340 from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR341 342 343 # <http://msdn.microsoft.com/en-us/library/windows/desktop/ms683188%28v=vs.85%29.aspx> 343 344 GetEnvironmentVariableW = WINFUNCTYPE( 344 DWORD, 345 LPCWSTR, LPWSTR, DWORD, 345 DWORD, LPCWSTR, LPWSTR, DWORD, 346 346 use_last_error=True 347 347 )(("GetEnvironmentVariableW", windll.kernel32)) 348 348 349 349 try: … … 353 353 # <http://msdn.microsoft.com/en-us/library/aa364937%28VS.85%29.aspx> 354 354 GetDiskFreeSpaceExW = WINFUNCTYPE( 355 BOOL, 356 LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER, 355 BOOL, LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER, 357 356 use_last_error=True 358 357 )(("GetDiskFreeSpaceExW", windll.kernel32)) 359 358 360 359 have_GetDiskFreeSpaceExW = True … … 404 403 if err == ERROR_ENVVAR_NOT_FOUND: 405 404 return None 406 raise OSError("Win dows error %dattempting to read size of environment variable %r"407 % ( err, name))405 raise OSError("WinError: %s\n attempting to read size of environment variable %r" 406 % (WinError(err), name)) 408 407 if n == 1: 409 408 # Avoid an ambiguity between a zero-length string and an error in the return value of the … … 417 416 if err == ERROR_ENVVAR_NOT_FOUND: 418 417 return None 419 raise OSError("Win dows error %dattempting to read environment variable %r"420 % ( err, name))418 raise OSError("WinError: %s\n attempting to read environment variable %r" 419 % (WinError(err), name)) 421 420 if retval >= n: 422 421 raise OSError("Unexpected result %d (expected less than %d) from GetEnvironmentVariableW attempting to read environment variable %r" … … 460 459 byref(n_free_for_root)) 461 460 if retval == 0: 462 raise OSError("Win dows error %dattempting to get disk statistics for %r"463 % ( get_last_error(), whichdir))461 raise OSError("WinError: %s\n attempting to get disk statistics for %r" 462 % (WinError(get_last_error()), whichdir)) 464 463 free_for_nonroot = n_free_for_nonroot.value 465 464 total = n_total.value -
TabularUnified src/allmydata/windows/fixups.py ¶
r41cf6008 r6d4a8bc 10 10 11 11 import codecs, re 12 from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_int12 from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, c_int, get_last_error 13 13 from ctypes.wintypes import BOOL, HANDLE, DWORD, UINT, LPWSTR, LPCWSTR, LPVOID 14 14 15 from allmydata.util import log 15 16 from allmydata.util.encodingutil import canonical_encoding 16 17 17 18 # <https://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx> 18 SetErrorMode = WINFUNCTYPE(UINT, UINT)(("SetErrorMode", windll.kernel32)) 19 SetErrorMode = WINFUNCTYPE( 20 UINT, UINT, 21 use_last_error=True 22 )(("SetErrorMode", windll.kernel32)) 23 19 24 SEM_FAILCRITICALERRORS = 0x0001 20 25 SEM_NOOPENFILEERRORBOX = 0x8000 … … 51 56 # BOOL WINAPI GetConsoleMode(HANDLE hConsole, LPDWORD lpMode); 52 57 53 GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(("GetStdHandle", windll.kernel32)) 58 GetStdHandle = WINFUNCTYPE( 59 HANDLE, DWORD, 60 use_last_error=True 61 )(("GetStdHandle", windll.kernel32)) 62 54 63 STD_OUTPUT_HANDLE = DWORD(-11) 55 64 STD_ERROR_HANDLE = DWORD(-12) 56 GetFileType = WINFUNCTYPE(DWORD, DWORD)(("GetFileType", windll.kernel32)) 65 66 GetFileType = WINFUNCTYPE( 67 DWORD, DWORD, 68 use_last_error=True 69 )(("GetFileType", windll.kernel32)) 70 57 71 FILE_TYPE_CHAR = 0x0002 58 72 FILE_TYPE_REMOTE = 0x8000 59 GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(("GetConsoleMode", windll.kernel32)) 73 74 GetConsoleMode = WINFUNCTYPE( 75 BOOL, HANDLE, POINTER(DWORD), 76 use_last_error=True 77 )(("GetConsoleMode", windll.kernel32)) 78 60 79 INVALID_HANDLE_VALUE = DWORD(-1).value 61 80 … … 89 108 90 109 if real_stdout or real_stderr: 110 # <https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401%28v=vs.85%29.aspx> 91 111 # BOOL WINAPI WriteConsoleW(HANDLE hOutput, LPWSTR lpBuffer, DWORD nChars, 92 112 # LPDWORD lpCharsWritten, LPVOID lpReserved); 93 113 94 WriteConsoleW = WINFUNCTYPE(BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD), LPVOID) \ 95 (("WriteConsoleW", windll.kernel32)) 114 WriteConsoleW = WINFUNCTYPE( 115 BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD), LPVOID, 116 use_last_error=True 117 )(("WriteConsoleW", windll.kernel32)) 96 118 97 119 class UnicodeOutput: … … 140 162 # passed to WriteConsoleW (see #1232). 141 163 retval = WriteConsoleW(self._hConsole, text, min(remaining, 10000), byref(n), None) 142 if retval == 0 or n.value == 0: 143 raise IOError("WriteConsoleW returned %r, n.value = %r" % (retval, n.value)) 164 if retval == 0: 165 raise IOError("WriteConsoleW failed with WinError: %s" % (WinError(get_last_error()),)) 166 if n.value == 0: 167 raise IOError("WriteConsoleW returned %r, n.value = 0" % (retval,)) 144 168 remaining -= n.value 145 169 if remaining == 0: break … … 170 194 171 195 # This works around <http://bugs.python.org/issue2128>. 172 GetCommandLineW = WINFUNCTYPE(LPWSTR)(("GetCommandLineW", windll.kernel32)) 173 CommandLineToArgvW = WINFUNCTYPE(POINTER(LPWSTR), LPCWSTR, POINTER(c_int)) \ 174 (("CommandLineToArgvW", windll.shell32)) 196 197 # <https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156%28v=vs.85%29.aspx> 198 GetCommandLineW = WINFUNCTYPE( 199 LPWSTR, 200 use_last_error=True 201 )(("GetCommandLineW", windll.kernel32)) 202 203 # <https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391%28v=vs.85%29.aspx> 204 CommandLineToArgvW = WINFUNCTYPE( 205 POINTER(LPWSTR), LPCWSTR, POINTER(c_int), 206 use_last_error=True 207 )(("CommandLineToArgvW", windll.shell32)) 175 208 176 209 argc = c_int(0) 177 210 argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc)) 211 if argv_unicode is None: 212 raise WinError(get_last_error()) 178 213 179 214 # Because of <http://bugs.python.org/issue8775> (and similar limitations in
Note: See TracChangeset
for help on using the changeset viewer.