From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../mozharness/examples/action_config_script.py | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100755 testing/mozharness/examples/action_config_script.py (limited to 'testing/mozharness/examples/action_config_script.py') diff --git a/testing/mozharness/examples/action_config_script.py b/testing/mozharness/examples/action_config_script.py new file mode 100755 index 000000000..e1135771e --- /dev/null +++ b/testing/mozharness/examples/action_config_script.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python -u +"""action_config_script.py + +Demonstrate actions and config. +""" + +import os +import sys +import time + +sys.path.insert(1, os.path.dirname(sys.path[0])) + +from mozharness.base.script import BaseScript + + +# ActionsConfigExample {{{1 +class ActionsConfigExample(BaseScript): + config_options = [[ + ['--beverage', ], + {"action": "store", + "dest": "beverage", + "type": "string", + "help": "Specify your beverage of choice", + } + ], [ + ['--ship-style', ], + {"action": "store", + "dest": "ship_style", + "type": "choice", + "choices": ["1", "2", "3"], + "help": "Specify the type of ship", + } + ], [ + ['--long-sleep-time', ], + {"action": "store", + "dest": "long_sleep_time", + "type": "int", + "help": "Specify how long to sleep", + } + ]] + + def __init__(self, require_config_file=False): + super(ActionsConfigExample, self).__init__( + config_options=self.config_options, + all_actions=[ + 'clobber', + 'nap', + 'ship-it', + ], + default_actions=[ + 'clobber', + 'nap', + 'ship-it', + ], + require_config_file=require_config_file, + config={ + 'beverage': "kool-aid", + 'long_sleep_time': 3600, + 'ship_style': "1", + } + ) + + def _sleep(self, sleep_length, interval=5): + self.info("Sleeping %d seconds..." % sleep_length) + counter = 0 + while counter + interval <= sleep_length: + sys.stdout.write(".") + try: + time.sleep(interval) + except: + print + self.error("Impatient, are we?") + sys.exit(1) + counter += interval + print + self.info("Ok, done.") + + def _ship1(self): + self.info(""" + _~ + _~ )_)_~ + )_))_))_) + _!__!__!_ + \______t/ +~~~~~~~~~~~~~ +""") + + def _ship2(self): + self.info(""" + _4 _4 + _)_))_) + _)_)_)_) + _)_))_))_)_ + \_=__=__=_/ +~~~~~~~~~~~~~ +""") + + def _ship3(self): + self.info(""" + ,;;:;, + ;;;;; + ,:;;:; ,'=. + ;:;:;' .=" ,'_\\ + ':;:;,/ ,__:=@ + ';;:; =./)_ + `"=\\_ )_"` + ``'"` +""") + + def nap(self): + for var_name in self.config.keys(): + if var_name.startswith("random_config_key"): + self.info("This is going to be %s!" % self.config[var_name]) + sleep_time = self.config['long_sleep_time'] + if sleep_time > 60: + self.info("Ok, grab a %s. This is going to take a while." % self.config['beverage']) + else: + self.info("This will be quick, but grab a %s anyway." % self.config['beverage']) + self._sleep(self.config['long_sleep_time']) + + def ship_it(self): + name = "_ship%s" % self.config['ship_style'] + if hasattr(self, name): + getattr(self, name)() + + +# __main__ {{{1 +if __name__ == '__main__': + actions_config_example = ActionsConfigExample() + actions_config_example.run_and_exit() -- cgit v1.2.3