| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Archives a set of files or directories to an Isolate Server.""" | 6 """Archives a set of files or directories to an Isolate Server.""" |
| 7 | 7 |
| 8 __version__ = '0.4.8' | 8 __version__ = '0.4.8' |
| 9 | 9 |
| 10 import base64 | 10 import base64 |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 | 1211 |
| 1212 def __init__(self): | 1212 def __init__(self): |
| 1213 self._lock = threading_utils.LockWithAssert() | 1213 self._lock = threading_utils.LockWithAssert() |
| 1214 # Profiling values. | 1214 # Profiling values. |
| 1215 self._added = [] | 1215 self._added = [] |
| 1216 self._initial_number_items = 0 | 1216 self._initial_number_items = 0 |
| 1217 self._initial_size = 0 | 1217 self._initial_size = 0 |
| 1218 self._evicted = [] | 1218 self._evicted = [] |
| 1219 self._linked = [] | 1219 self._linked = [] |
| 1220 | 1220 |
| 1221 def __contains__(self, digest): |
| 1222 raise NotImplementedError() |
| 1223 |
| 1221 def __enter__(self): | 1224 def __enter__(self): |
| 1222 """Context manager interface.""" | 1225 """Context manager interface.""" |
| 1223 return self | 1226 return self |
| 1224 | 1227 |
| 1225 def __exit__(self, _exc_type, _exec_value, _traceback): | 1228 def __exit__(self, _exc_type, _exec_value, _traceback): |
| 1226 """Context manager interface.""" | 1229 """Context manager interface.""" |
| 1227 return False | 1230 return False |
| 1228 | 1231 |
| 1229 @property | 1232 @property |
| 1230 def added(self): | 1233 def added(self): |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 | 1298 |
| 1296 def __init__(self, file_mode_mask=0500): | 1299 def __init__(self, file_mode_mask=0500): |
| 1297 """Args: | 1300 """Args: |
| 1298 file_mode_mask: bit mask to AND file mode with. Default value will make | 1301 file_mode_mask: bit mask to AND file mode with. Default value will make |
| 1299 all mapped files to be read only. | 1302 all mapped files to be read only. |
| 1300 """ | 1303 """ |
| 1301 super(MemoryCache, self).__init__() | 1304 super(MemoryCache, self).__init__() |
| 1302 self._file_mode_mask = file_mode_mask | 1305 self._file_mode_mask = file_mode_mask |
| 1303 self._contents = {} | 1306 self._contents = {} |
| 1304 | 1307 |
| 1308 def __contains__(self, digest): |
| 1309 with self._lock: |
| 1310 return digest in self._contents |
| 1311 |
| 1305 def cached_set(self): | 1312 def cached_set(self): |
| 1306 with self._lock: | 1313 with self._lock: |
| 1307 return set(self._contents) | 1314 return set(self._contents) |
| 1308 | 1315 |
| 1309 def cleanup(self): | 1316 def cleanup(self): |
| 1310 pass | 1317 pass |
| 1311 | 1318 |
| 1312 def touch(self, digest, size): | 1319 def touch(self, digest, size): |
| 1313 with self._lock: | 1320 with self._lock: |
| 1314 return digest in self._contents | 1321 return digest in self._contents |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1388 # The items that must not be evicted during this run since they were | 1395 # The items that must not be evicted during this run since they were |
| 1389 # referenced. | 1396 # referenced. |
| 1390 self._protected = set() | 1397 self._protected = set() |
| 1391 # Cleanup operations done by self._load(), if any. | 1398 # Cleanup operations done by self._load(), if any. |
| 1392 self._operations = [] | 1399 self._operations = [] |
| 1393 with tools.Profiler('Setup'): | 1400 with tools.Profiler('Setup'): |
| 1394 with self._lock: | 1401 with self._lock: |
| 1395 # self._load() calls self._trim() which initializes self._free_disk. | 1402 # self._load() calls self._trim() which initializes self._free_disk. |
| 1396 self._load() | 1403 self._load() |
| 1397 | 1404 |
| 1405 def __contains__(self, digest): |
| 1406 with self._lock: |
| 1407 return digest in self._lru |
| 1408 |
| 1398 def __enter__(self): | 1409 def __enter__(self): |
| 1399 return self | 1410 return self |
| 1400 | 1411 |
| 1401 def __exit__(self, _exc_type, _exec_value, _traceback): | 1412 def __exit__(self, _exc_type, _exec_value, _traceback): |
| 1402 with tools.Profiler('CleanupTrimming'): | 1413 with tools.Profiler('CleanupTrimming'): |
| 1403 with self._lock: | 1414 with self._lock: |
| 1404 self._trim() | 1415 self._trim() |
| 1405 | 1416 |
| 1406 logging.info( | 1417 logging.info( |
| 1407 '%5d (%8dkb) added', | 1418 '%5d (%8dkb) added', |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 dispatcher = subcommand.CommandDispatcher(__name__) | 2298 dispatcher = subcommand.CommandDispatcher(__name__) |
| 2288 return dispatcher.execute(OptionParserIsolateServer(), args) | 2299 return dispatcher.execute(OptionParserIsolateServer(), args) |
| 2289 | 2300 |
| 2290 | 2301 |
| 2291 if __name__ == '__main__': | 2302 if __name__ == '__main__': |
| 2292 subprocess42.inhibit_os_error_reporting() | 2303 subprocess42.inhibit_os_error_reporting() |
| 2293 fix_encoding.fix_encoding() | 2304 fix_encoding.fix_encoding() |
| 2294 tools.disable_buffering() | 2305 tools.disable_buffering() |
| 2295 colorama.init() | 2306 colorama.init() |
| 2296 sys.exit(main(sys.argv[1:])) | 2307 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |