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.8.0' | 8 __version__ = '0.8.0' |
9 | 9 |
10 import errno | 10 import errno |
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 logging.info(msg) | 1712 logging.info(msg) |
1713 last_update = time.time() | 1713 last_update = time.time() |
1714 | 1714 |
1715 # Cache could evict some items we just tried to fetch, it's a fatal error. | 1715 # Cache could evict some items we just tried to fetch, it's a fatal error. |
1716 if not fetch_queue.verify_all_cached(): | 1716 if not fetch_queue.verify_all_cached(): |
1717 raise isolated_format.MappingError( | 1717 raise isolated_format.MappingError( |
1718 'Cache is too small to hold all requested files') | 1718 'Cache is too small to hold all requested files') |
1719 return bundle | 1719 return bundle |
1720 | 1720 |
1721 | 1721 |
1722 def directory_to_metadata(root, algo, blacklist): | 1722 def directory_to_metadata(root, algo, blacklist, collapse_symlinks): |
1723 """Returns the FileItem list and .isolated metadata for a directory.""" | 1723 """Returns the FileItem list and .isolated metadata for a directory.""" |
1724 root = file_path.get_native_path_case(root) | 1724 root = file_path.get_native_path_case(root) |
1725 paths = isolated_format.expand_directory_and_symlink( | 1725 paths = isolated_format.expand_directory_and_symlink( |
1726 root, '.' + os.path.sep, blacklist, sys.platform != 'win32') | 1726 root, '.' + os.path.sep, blacklist, sys.platform != 'win32') |
1727 metadata = { | 1727 metadata = { |
1728 relpath: isolated_format.file_to_metadata( | 1728 relpath: isolated_format.file_to_metadata( |
1729 os.path.join(root, relpath), {}, 0, algo, False) | 1729 os.path.join(root, relpath), {}, 0, algo, collapse_symlinks) |
1730 for relpath in paths | 1730 for relpath in paths |
1731 } | 1731 } |
1732 for v in metadata.itervalues(): | 1732 for v in metadata.itervalues(): |
1733 v.pop('t') | 1733 v.pop('t') |
1734 items = [ | 1734 items = [ |
1735 FileItem( | 1735 FileItem( |
1736 path=os.path.join(root, relpath), | 1736 path=os.path.join(root, relpath), |
1737 digest=meta['h'], | 1737 digest=meta['h'], |
1738 size=meta['s'], | 1738 size=meta['s'], |
1739 high_priority=relpath.endswith('.isolated')) | 1739 high_priority=relpath.endswith('.isolated')) |
(...skipping 25 matching lines...) Expand all Loading... |
1765 tempdir = None | 1765 tempdir = None |
1766 try: | 1766 try: |
1767 # TODO(maruel): Yield the files to a worker thread. | 1767 # TODO(maruel): Yield the files to a worker thread. |
1768 items_to_upload = [] | 1768 items_to_upload = [] |
1769 for f in files: | 1769 for f in files: |
1770 try: | 1770 try: |
1771 filepath = os.path.abspath(f) | 1771 filepath = os.path.abspath(f) |
1772 if fs.isdir(filepath): | 1772 if fs.isdir(filepath): |
1773 # Uploading a whole directory. | 1773 # Uploading a whole directory. |
1774 items, metadata = directory_to_metadata( | 1774 items, metadata = directory_to_metadata( |
1775 filepath, storage.hash_algo, blacklist) | 1775 filepath, storage.hash_algo, blacklist, False) |
1776 | 1776 |
1777 # Create the .isolated file. | 1777 # Create the .isolated file. |
1778 if not tempdir: | 1778 if not tempdir: |
1779 tempdir = tempfile.mkdtemp(prefix=u'isolateserver') | 1779 tempdir = tempfile.mkdtemp(prefix=u'isolateserver') |
1780 handle, isolated = tempfile.mkstemp(dir=tempdir, suffix=u'.isolated') | 1780 handle, isolated = tempfile.mkstemp(dir=tempdir, suffix=u'.isolated') |
1781 os.close(handle) | 1781 os.close(handle) |
1782 data = { | 1782 data = { |
1783 'algo': | 1783 'algo': |
1784 isolated_format.SUPPORTED_ALGOS_REVERSE[storage.hash_algo], | 1784 isolated_format.SUPPORTED_ALGOS_REVERSE[storage.hash_algo], |
1785 'files': metadata, | 1785 'files': metadata, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 return dispatcher.execute(OptionParserIsolateServer(), args) | 2046 return dispatcher.execute(OptionParserIsolateServer(), args) |
2047 | 2047 |
2048 | 2048 |
2049 if __name__ == '__main__': | 2049 if __name__ == '__main__': |
2050 subprocess42.inhibit_os_error_reporting() | 2050 subprocess42.inhibit_os_error_reporting() |
2051 fix_encoding.fix_encoding() | 2051 fix_encoding.fix_encoding() |
2052 tools.disable_buffering() | 2052 tools.disable_buffering() |
2053 colorama.init() | 2053 colorama.init() |
2054 file_path.enable_symlink() | 2054 file_path.enable_symlink() |
2055 sys.exit(main(sys.argv[1:])) | 2055 sys.exit(main(sys.argv[1:])) |
OLD | NEW |