OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 """Utility class to generate and manage a factory to be passed to a | 5 """Utility class to generate and manage a factory to be passed to a |
6 builder dictionary as the 'factory' member, for each builder in c['builders']. | 6 builder dictionary as the 'factory' member, for each builder in c['builders']. |
7 | 7 |
8 Specifically creates a basic factory that will execute an arbirary annotator | 8 Specifically creates a basic factory that will execute an arbirary annotator |
9 script. | 9 script. |
10 """ | 10 """ |
11 | 11 |
12 from master.factory import annotator_commands | 12 from master.factory import annotator_commands |
13 from master.factory import commands | 13 from master.factory import commands |
14 from master.factory.build_factory import BuildFactory | 14 from master.factory.build_factory import BuildFactory |
15 | 15 |
16 | 16 |
17 class AnnotatorFactory(object): | 17 class AnnotatorFactory(object): |
18 """Encapsulates data and methods common to all annotators.""" | 18 """Encapsulates data and methods common to all annotators.""" |
19 | 19 |
20 def __init__(self): | 20 def __init__(self): |
21 self._factory_properties = None | 21 self._factory_properties = None |
22 | 22 |
23 def BaseFactory(self, recipe, factory_properties=None, triggers=None, | 23 def BaseFactory(self, recipe=None, factory_properties=None, triggers=None, |
24 timeout=1200, max_time=None): | 24 timeout=1200, max_time=None): |
25 """The primary input for the factory is the |recipe|, which specifies the | 25 """The primary input for the factory is the |recipe|, which specifies the |
26 name of a recipe file to search for. The recipe file will fill in the rest | 26 name of a recipe file to search for. The recipe file will fill in the rest |
27 of the |factory_properties|. This setup allows for major changes to factory | 27 of the |factory_properties|. This setup allows for major changes to factory |
28 properties to occur on slave-side without master restarts. | 28 properties to occur on slave-side without master restarts. |
29 | 29 |
30 NOTE: Please be very discerning with what |factory_properties| you pass to | 30 NOTE: Please be very discerning with what |factory_properties| you pass to |
31 this method. Ideally, you will pass none, and that will be sufficient in the | 31 this method. Ideally, you will pass none, and that will be sufficient in the |
32 vast majority of cases. Think very carefully before adding any | 32 vast majority of cases. Think very carefully before adding any |
33 |factory_properties| here, as changing them will require a master restart. | 33 |factory_properties| here, as changing them will require a master restart. |
34 | 34 |
| 35 |recipe| is the name of the recipe to pass to annotated_run. If omitted, |
| 36 annotated_run will attempt to look up the recipe from builders.pyl in the |
| 37 master. |
| 38 |
35 |timeout| refers to the maximum number of seconds a step should be allowed | 39 |timeout| refers to the maximum number of seconds a step should be allowed |
36 to run without output. After no output for |timeout| seconds, the step is | 40 to run without output. After no output for |timeout| seconds, the step is |
37 forcibly killed. | 41 forcibly killed. |
38 | 42 |
39 |max_time| refers to the maximum number of seconds a step should be allowed | 43 |max_time| refers to the maximum number of seconds a step should be allowed |
40 to run, regardless of output. After |max_time| seconds, the step is forcibly | 44 to run, regardless of output. After |max_time| seconds, the step is forcibly |
41 killed. | 45 killed. |
42 """ | 46 """ |
43 factory_properties = factory_properties or {} | 47 factory_properties = factory_properties or {} |
44 factory_properties.update({'recipe': recipe}) | 48 if recipe: |
| 49 factory_properties.update({'recipe': recipe}) |
45 self._factory_properties = factory_properties | 50 self._factory_properties = factory_properties |
46 factory = BuildFactory() | 51 factory = BuildFactory() |
47 factory.properties.update(self._factory_properties, 'AnnotatorFactory') | 52 factory.properties.update(self._factory_properties, 'AnnotatorFactory') |
48 cmd_obj = annotator_commands.AnnotatorCommands(factory) | 53 cmd_obj = annotator_commands.AnnotatorCommands(factory) |
49 cmd_obj.AddAnnotatedScript( | 54 cmd_obj.AddAnnotatedScript( |
50 factory_properties, timeout=timeout, max_time=max_time) | 55 factory_properties, timeout=timeout, max_time=max_time) |
51 | 56 |
52 for t in triggers or []: | 57 for t in triggers or []: |
53 factory.addStep(commands.CreateTriggerStep( | 58 factory.addStep(commands.CreateTriggerStep( |
54 t, trigger_copy_properties=['swarm_hashes'])) | 59 t, trigger_copy_properties=['swarm_hashes'])) |
55 | 60 |
56 return factory | 61 return factory |
OLD | NEW |