OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
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 |
(...skipping 23 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), |
| 63 'quiet': quiet, |
61 } | 64 } |
62 self.m.python( | 65 self.m.python( |
63 name=step_name, | 66 name=step_name, |
64 script=self.resource('unzip.py'), | 67 script=self.resource('unzip.py'), |
65 stdin=self.m.json.input(script_input)) | 68 stdin=self.m.json.input(script_input)) |
66 | 69 |
67 | 70 |
68 class ZipPackage(object): | 71 class ZipPackage(object): |
69 """Used to gather a list of files to zip.""" | 72 """Used to gather a list of files to zip.""" |
70 | 73 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 'entries': self._entries, | 118 'entries': self._entries, |
116 'output': str(self._output), | 119 'output': str(self._output), |
117 'root': str(self._root), | 120 'root': str(self._root), |
118 } | 121 } |
119 step_result = self._module.m.python( | 122 step_result = self._module.m.python( |
120 name=step_name, | 123 name=step_name, |
121 script=self._module.resource('zip.py'), | 124 script=self._module.resource('zip.py'), |
122 stdin=self._module.m.json.input(script_input)) | 125 stdin=self._module.m.json.input(script_input)) |
123 self._module.m.path.mock_add_paths(self._output) | 126 self._module.m.path.mock_add_paths(self._output) |
124 return step_result | 127 return step_result |
OLD | NEW |