| 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 import gzip | 5 import gzip |
| 6 import os | 6 import os |
| 7 import time | 7 import time |
| 8 import zipfile | 8 import zipfile |
| 9 | 9 |
| 10 | 10 |
| 11 def ArchiveFiles(host_files, output): | 11 def ArchiveFiles(host_files, output): |
| 12 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as z: | 12 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as z: |
| 13 for host_file in host_files: | 13 for host_file in host_files: |
| 14 z.write(host_file) | 14 z.write(host_file) |
| 15 os.unlink(host_file) | 15 os.unlink(host_file) |
| 16 | 16 |
| 17 |
| 17 def CompressFile(host_file, output): | 18 def CompressFile(host_file, output): |
| 18 with gzip.open(output, 'wb') as out, open(host_file, 'rb') as input_file: | 19 with gzip.open(output, 'wb') as out, open(host_file, 'rb') as input_file: |
| 19 out.write(input_file.read()) | 20 out.write(input_file.read()) |
| 20 os.unlink(host_file) | 21 os.unlink(host_file) |
| 21 | 22 |
| 22 def ArchiveData(trace_results, output): | |
| 23 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as z: | |
| 24 for result in trace_results: | |
| 25 trace_file = result.source_name + GetTraceTimestamp() | |
| 26 WriteDataToCompressedFile(result.raw_data, trace_file) | |
| 27 z.write(trace_file) | |
| 28 os.unlink(trace_file) | |
| 29 | 23 |
| 30 def WriteDataToCompressedFile(data, output): | 24 def WriteDataToCompressedFile(data, output): |
| 31 with gzip.open(output, 'wb') as out: | 25 with gzip.open(output, 'wb') as out: |
| 32 out.write(data) | 26 out.write(data) |
| 33 | 27 |
| 28 |
| 34 def GetTraceTimestamp(): | 29 def GetTraceTimestamp(): |
| 35 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) | 30 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) |
| OLD | NEW |