diff options
author | Hidehiko Abe <hidehiko@google.com> | 2018-04-23 19:57:41 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-04-23 19:57:41 -0700 |
commit | 0ab20ac2283987e63b0e7c1318db2a5cf7c668d2 (patch) | |
tree | bd2d04362f66c36d4279f7a9735ba21ea3a2a021 /third_party/catapult/devil/devil/utils/zip_utils.py | |
parent | e389a13ad8648d89ac670ca06f68c9b32976351c (diff) | |
parent | b268b43ac6fdbc4f3a2ed1429b99ace424906090 (diff) | |
download | libchrome-0ab20ac2283987e63b0e7c1318db2a5cf7c668d2.tar.gz |
Migrate libmojo repository into libchrome, part 2.
am: b268b43ac6
Change-Id: I7b2c3d7cfed03673c33eb497be20e238bd0aac33
Diffstat (limited to 'third_party/catapult/devil/devil/utils/zip_utils.py')
-rw-r--r-- | third_party/catapult/devil/devil/utils/zip_utils.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/third_party/catapult/devil/devil/utils/zip_utils.py b/third_party/catapult/devil/devil/utils/zip_utils.py new file mode 100644 index 0000000000..eaa6a2df01 --- /dev/null +++ b/third_party/catapult/devil/devil/utils/zip_utils.py @@ -0,0 +1,33 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import logging +import os +import zipfile + +logger = logging.getLogger(__name__) + + +def WriteToZipFile(zip_file, path, arc_path): + """Recursively write |path| to |zip_file| as |arc_path|. + + zip_file: An open instance of zipfile.ZipFile. + path: An absolute path to the file or directory to be zipped. + arc_path: A relative path within the zip file to which the file or directory + located at |path| should be written. + """ + if os.path.isdir(path): + for dir_path, _, file_names in os.walk(path): + dir_arc_path = os.path.join(arc_path, os.path.relpath(dir_path, path)) + logger.debug('dir: %s -> %s', dir_path, dir_arc_path) + zip_file.write(dir_path, dir_arc_path, zipfile.ZIP_STORED) + for f in file_names: + file_path = os.path.join(dir_path, f) + file_arc_path = os.path.join(dir_arc_path, f) + logger.debug('file: %s -> %s', file_path, file_arc_path) + zip_file.write(file_path, file_arc_path, zipfile.ZIP_DEFLATED) + else: + logger.debug('file: %s -> %s', path, arc_path) + zip_file.write(path, arc_path, zipfile.ZIP_DEFLATED) + |