Backed out changeset 5c7de47bcacb (bug 1927094) for causing Bug 1928689. a=backout
[gecko.git] / testing / mozharness / examples / action_config_script.py
blob99022ce082d1923dfae8c1a29894667282f3c73b
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.
9 """
11 import os
12 import sys
13 import time
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):
22 config_options = [
25 "--beverage",
28 "action": "store",
29 "dest": "beverage",
30 "type": "string",
31 "help": "Specify your beverage of choice",
36 "--ship-style",
39 "action": "store",
40 "dest": "ship_style",
41 "type": "choice",
42 "choices": ["1", "2", "3"],
43 "help": "Specify the type of ship",
48 "--long-sleep-time",
51 "action": "store",
52 "dest": "long_sleep_time",
53 "type": "int",
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,
62 all_actions=[
63 "clobber",
64 "nap",
65 "ship-it",
67 default_actions=[
68 "clobber",
69 "nap",
70 "ship-it",
72 require_config_file=require_config_file,
73 config={
74 "beverage": "kool-aid",
75 "long_sleep_time": 3600,
76 "ship_style": "1",
80 def _sleep(self, sleep_length, interval=5):
81 self.info("Sleeping %d seconds..." % sleep_length)
82 counter = 0
83 while counter + interval <= sleep_length:
84 sys.stdout.write(".")
85 try:
86 time.sleep(interval)
87 except:
88 print
89 self.error("Impatient, are we?")
90 sys.exit(1)
91 counter += interval
92 print()
93 self.info("Ok, done.")
95 def _ship1(self):
96 self.info(
97 r"""
99 _~ )_)_~
100 )_))_))_)
101 _!__!__!_
102 \______t/
103 ~~~~~~~~~~~~~
107 def _ship2(self):
108 self.info(
109 r"""
110 _4 _4
111 _)_))_)
112 _)_)_)_)
113 _)_))_))_)_
114 \_=__=__=_/
115 ~~~~~~~~~~~~~
119 def _ship3(self):
120 self.info(
122 ,;;:;,
123 ;;;;;
124 ,:;;:; ,'=.
125 ;:;:;' .=" ,'_\\
126 ':;:;,/ ,__:=@
127 ';;:; =./)_
128 `"=\\_ )_"`
129 ``'"`
133 def nap(self):
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"]
138 if sleep_time > 60:
139 self.info(
140 "Ok, grab a %s. This is going to take a while."
141 % self.config["beverage"]
143 else:
144 self.info(
145 "This will be quick, but grab a %s anyway." % self.config["beverage"]
147 self._sleep(self.config["long_sleep_time"])
149 def ship_it(self):
150 name = "_ship%s" % self.config["ship_style"]
151 if hasattr(self, name):
152 getattr(self, name)()
155 # __main__ {{{1
156 if __name__ == "__main__":
157 actions_config_example = ActionsConfigExample()
158 actions_config_example.run_and_exit()