| 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 hashlib | 5 import hashlib |
| 6 import os | 6 import os |
| 7 import struct | 7 import struct |
| 8 import sys | 8 import sys |
| 9 from recipe_engine import recipe_test_api | 9 from recipe_engine import recipe_test_api |
| 10 | 10 |
| 11 # TODO(phajdan.jr): Clean up this somewhat ugly import. | |
| 12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources')) | |
| 13 import bot_update | |
| 14 | |
| 15 | 11 |
| 16 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): | 12 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): |
| 17 def output_json(self, master, builder, slave, root, first_sln, | 13 def output_json(self, master, builder, slave, root, first_sln, |
| 18 revision_mapping, force=False, fail_patch=False, | 14 revision_mapping, force=False, fail_patch=False, |
| 19 output_manifest=False, fixed_revisions=None): | 15 output_manifest=False, fixed_revisions=None): |
| 20 """Deterministically synthesize json.output test data for gclient's | 16 """Deterministically synthesize json.output test data for gclient's |
| 21 --output-json option. | 17 --output-json option. |
| 22 """ | 18 """ |
| 23 active = bot_update.check_valid_host(master, builder, slave) or force | 19 active = True |
| 24 | 20 |
| 25 output = { | 21 output = { |
| 26 'did_run': active, | 22 'did_run': active, |
| 27 'patch_failure': False | 23 'patch_failure': False |
| 28 } | 24 } |
| 29 | 25 |
| 30 # Add in extra json output if active. | 26 # Add in extra json output if active. |
| 31 if active: | 27 if active: |
| 32 properties = { | 28 properties = { |
| 33 property_name: self.gen_revision(project_name) | 29 property_name: self.gen_revision(project_name) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 def gen_revision(project): | 68 def gen_revision(project): |
| 73 """Hash project to bogus deterministic git hash values.""" | 69 """Hash project to bogus deterministic git hash values.""" |
| 74 h = hashlib.sha1(project) | 70 h = hashlib.sha1(project) |
| 75 return h.hexdigest() | 71 return h.hexdigest() |
| 76 | 72 |
| 77 @staticmethod | 73 @staticmethod |
| 78 def gen_commit_position(project): | 74 def gen_commit_position(project): |
| 79 """Hash project to bogus deterministic Cr-Commit-Position values.""" | 75 """Hash project to bogus deterministic Cr-Commit-Position values.""" |
| 80 h = hashlib.sha1(project) | 76 h = hashlib.sha1(project) |
| 81 return struct.unpack('!I', h.digest()[:4])[0] % 300000 | 77 return struct.unpack('!I', h.digest()[:4])[0] % 300000 |
| OLD | NEW |