OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The PDFium Authors. All rights reserved. | 2 # Copyright 2015 The PDFium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import glob | 6 import glob |
7 import os | 7 import os |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 | 10 |
11 def os_name(): | 11 def os_name(): |
12 if sys.platform.startswith('linux'): | 12 if sys.platform.startswith('linux'): |
13 return 'linux' | 13 return 'linux' |
14 if sys.platform.startswith('win'): | 14 if sys.platform.startswith('win'): |
15 return 'win' | 15 return 'win' |
16 if sys.platform.startswith('darwin'): | 16 if sys.platform.startswith('darwin'): |
17 return 'mac' | 17 return 'mac' |
18 raise Exception('Confused, can not determine OS, aborting.') | 18 raise Exception('Confused, can not determine OS, aborting.') |
19 | 19 |
20 | 20 |
21 def RunCommand(cmd): | 21 def RunCommand(cmd): |
22 try: | 22 try: |
23 subprocess.check_call(cmd) | 23 subprocess.check_call(cmd) |
24 return None | 24 return None |
25 except subprocess.CalledProcessError as e: | 25 except subprocess.CalledProcessError as e: |
26 return e | 26 return e |
27 | 27 |
28 # RunCommandExtractHashedFiles returns a tuple: (raised_exception, hashed_files) | |
borenet
2016/12/21 19:47:28
Isn't it more idiomatic just to let the exception
stephana
2016/12/21 21:47:57
I agree, but I wanted the changes to be minimal to
| |
29 # It runs the given command. If it fails it will return an exception and None. | |
30 # If it succeeds it will return None and the list of processed files extracted | |
31 # from the output of the command. It expects lines in this format: | |
32 # MD5:<path_to_image_file>:<md5_hash_in_hex> | |
33 # The returned hashed_files is a list of (file_path, MD5-hash) pairs. | |
34 def RunCommandExtractHashedFiles(cmd): | |
35 try: | |
36 output = subprocess.check_output(cmd, universal_newlines=True) | |
37 ret = [] | |
38 for line in output.split('\n'): | |
39 line = line.strip() | |
40 if line.startswith("MD5:"): | |
41 ret.append([x.strip() for x in line.lstrip("MD5:").rsplit(":", 1)]) | |
42 return None, ret | |
43 except subprocess.CalledProcessError as e: | |
44 return e, None | |
45 | |
28 # Adjust Dr. Memory wrapper to have separate log directory for each test | 46 # Adjust Dr. Memory wrapper to have separate log directory for each test |
29 # for better error reporting. | 47 # for better error reporting. |
30 def DrMemoryWrapper(wrapper, pdf_name): | 48 def DrMemoryWrapper(wrapper, pdf_name): |
31 if not wrapper: | 49 if not wrapper: |
32 return [] | 50 return [] |
33 # convert string to list | 51 # convert string to list |
34 cmd_to_run = wrapper.split() | 52 cmd_to_run = wrapper.split() |
35 | 53 |
36 # Do nothing if using default log directory. | 54 # Do nothing if using default log directory. |
37 if cmd_to_run.count("-logdir") == 0: | 55 if cmd_to_run.count("-logdir") == 0: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 if other_components: | 121 if other_components: |
104 result = os.path.join(result, other_components) | 122 result = os.path.join(result, other_components) |
105 return result | 123 return result |
106 | 124 |
107 def TestingDir(self, other_components=''): | 125 def TestingDir(self, other_components=''): |
108 '''Finds test files somewhere under the testing directory.''' | 126 '''Finds test files somewhere under the testing directory.''' |
109 result = self.testing_dir | 127 result = self.testing_dir |
110 if other_components: | 128 if other_components: |
111 result = os.path.join(result, other_components) | 129 result = os.path.join(result, other_components) |
112 return result | 130 return result |
OLD | NEW |