1 #!/usr/bin/env python -u
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 """action_config_script.py
8 Demonstrate actions and config.
15 sys
.path
.insert(1, os
.path
.dirname(sys
.path
[0]))
17 from mozharness
.base
.script
import BaseScript
20 # ActionsConfigExample {{{1
21 class ActionsConfigExample(BaseScript
):
31 "help": "Specify your beverage of choice",
42 "choices": ["1", "2", "3"],
43 "help": "Specify the type of ship",
52 "dest": "long_sleep_time",
54 "help": "Specify how long to sleep",
59 def __init__(self
, require_config_file
=False):
60 super(ActionsConfigExample
, self
).__init
__(
61 config_options
=self
.config_options
,
72 require_config_file
=require_config_file
,
74 "beverage": "kool-aid",
75 "long_sleep_time": 3600,
80 def _sleep(self
, sleep_length
, interval
=5):
81 self
.info("Sleeping %d seconds..." % sleep_length
)
83 while counter
+ interval
<= sleep_length
:
89 self
.error("Impatient, are we?")
93 self
.info("Ok, done.")
134 for var_name
in self
.config
.keys():
135 if var_name
.startswith("random_config_key"):
136 self
.info("This is going to be %s!" % self
.config
[var_name
])
137 sleep_time
= self
.config
["long_sleep_time"]
140 "Ok, grab a %s. This is going to take a while."
141 % self
.config
["beverage"]
145 "This will be quick, but grab a %s anyway." % self
.config
["beverage"]
147 self
._sleep
(self
.config
["long_sleep_time"])
150 name
= "_ship%s" % self
.config
["ship_style"]
151 if hasattr(self
, name
):
152 getattr(self
, name
)()
156 if __name__
== "__main__":
157 actions_config_example
= ActionsConfigExample()
158 actions_config_example
.run_and_exit()