OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
iannucci
2016/09/30 21:05:21
this zip change should have been a separate CL
dnj
2016/09/30 22:54:54
Acknowledged.
| |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from recipe_engine import recipe_api | 5 from recipe_engine import recipe_api |
6 | 6 |
7 | 7 |
8 class ZipApi(recipe_api.RecipeApi): | 8 class ZipApi(recipe_api.RecipeApi): |
9 """Provides steps to zip and unzip files.""" | 9 """Provides steps to zip and unzip files.""" |
10 | 10 |
11 def make_package(self, root, output): | 11 def make_package(self, root, output): |
(...skipping 22 matching lines...) Expand all Loading... | |
34 step_name: display name of the step. | 34 step_name: display name of the step. |
35 directory: path to a directory to compress, it would become the root of | 35 directory: path to a directory to compress, it would become the root of |
36 an archive, i.e. |directory|/file.txt would be named 'file.txt' in | 36 an archive, i.e. |directory|/file.txt would be named 'file.txt' in |
37 the archive. | 37 the archive. |
38 output: path to a zip file to create. | 38 output: path to a zip file to create. |
39 """ | 39 """ |
40 pkg = self.make_package(directory, output) | 40 pkg = self.make_package(directory, output) |
41 pkg.add_directory(directory) | 41 pkg.add_directory(directory) |
42 pkg.zip(step_name) | 42 pkg.zip(step_name) |
43 | 43 |
44 def unzip(self, step_name, zip_file, output): | 44 def unzip(self, step_name, zip_file, output, quiet=False): |
45 """Step to uncompress |zip_file| into |output| directory. | 45 """Step to uncompress |zip_file| into |output| directory. |
46 | 46 |
47 Zip package will be unpacked to |output| so that root of an archive is in | 47 Zip package will be unpacked to |output| so that root of an archive is in |
48 |output|, i.e. archive.zip/file.txt will become |output|/file.txt. | 48 |output|, i.e. archive.zip/file.txt will become |output|/file.txt. |
49 | 49 |
50 Step will FAIL if |output| already exists. | 50 Step will FAIL if |output| already exists. |
51 | 51 |
52 Args: | 52 Args: |
53 step_name: display name of a step. | 53 step_name: display name of a step. |
54 zip_file: path to a zip file to uncompress, should exist. | 54 zip_file: path to a zip file to uncompress, should exist. |
55 output: path to a directory to unpack to, it should NOT exist. | 55 output: path to a directory to unpack to, it should NOT exist. |
56 quiet (bool): If True, print terse output instead of the name | |
57 of each unzipped file. | |
56 """ | 58 """ |
57 # TODO(vadimsh): Use 7zip on Windows if available? | 59 # TODO(vadimsh): Use 7zip on Windows if available? |
58 script_input = { | 60 script_input = { |
59 'output': str(output), | 61 'output': str(output), |
60 'zip_file': str(zip_file), | 62 'zip_file': str(zip_file), |
61 } | 63 } |
64 if quiet: | |
65 script_input['quiet'] = True | |
62 self.m.python( | 66 self.m.python( |
63 name=step_name, | 67 name=step_name, |
64 script=self.resource('unzip.py'), | 68 script=self.resource('unzip.py'), |
65 stdin=self.m.json.input(script_input)) | 69 stdin=self.m.json.input(script_input)) |
66 | 70 |
67 | 71 |
68 class ZipPackage(object): | 72 class ZipPackage(object): |
69 """Used to gather a list of files to zip.""" | 73 """Used to gather a list of files to zip.""" |
70 | 74 |
71 def __init__(self, module, root, output): | 75 def __init__(self, module, root, output): |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 'entries': self._entries, | 119 'entries': self._entries, |
116 'output': str(self._output), | 120 'output': str(self._output), |
117 'root': str(self._root), | 121 'root': str(self._root), |
118 } | 122 } |
119 step_result = self._module.m.python( | 123 step_result = self._module.m.python( |
120 name=step_name, | 124 name=step_name, |
121 script=self._module.resource('zip.py'), | 125 script=self._module.resource('zip.py'), |
122 stdin=self._module.m.json.input(script_input)) | 126 stdin=self._module.m.json.input(script_input)) |
123 self._module.m.path.mock_add_paths(self._output) | 127 self._module.m.path.mock_add_paths(self._output) |
124 return step_result | 128 return step_result |
OLD | NEW |