diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /testing/mozharness/examples | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozharness/examples')
-rwxr-xr-x | testing/mozharness/examples/action_config_script.py | 159 | ||||
-rwxr-xr-x | testing/mozharness/examples/silent_script.py | 27 | ||||
-rwxr-xr-x | testing/mozharness/examples/venv.py | 52 | ||||
-rwxr-xr-x | testing/mozharness/examples/verbose_script.py | 71 |
4 files changed, 309 insertions, 0 deletions
diff --git a/testing/mozharness/examples/action_config_script.py b/testing/mozharness/examples/action_config_script.py new file mode 100755 index 0000000000..93d4d52819 --- /dev/null +++ b/testing/mozharness/examples/action_config_script.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python -u +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +"""action_config_script.py + +Demonstrate actions and config. +""" + +from __future__ import absolute_import, print_function +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() diff --git a/testing/mozharness/examples/silent_script.py b/testing/mozharness/examples/silent_script.py new file mode 100755 index 0000000000..65148870b3 --- /dev/null +++ b/testing/mozharness/examples/silent_script.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +""" This script is an example of why I care so much about Mozharness' 2nd core +concept, logging. http://escapewindow.dreamwidth.org/230853.html +""" + +from __future__ import absolute_import +import os +import shutil + +# print "downloading foo.tar.bz2..." +os.system("curl -s -o foo.tar.bz2 http://people.mozilla.org/~asasaki/foo.tar.bz2") +# os.system("curl -v -o foo.tar.bz2 http://people.mozilla.org/~asasaki/foo.tar.bz2") + +# os.rename("foo.tar.bz2", "foo3.tar.bz2") +os.system("tar xjf foo.tar.bz2") + +# os.chdir("x") +os.remove("x/ship2") +os.remove("foo.tar.bz2") +os.system("tar cjf foo.tar.bz2 x") +shutil.rmtree("x") +# os.system("scp -q foo.tar.bz2 people.mozilla.org:public_html/foo2.tar.bz2") +os.remove("foo.tar.bz2") diff --git a/testing/mozharness/examples/venv.py b/testing/mozharness/examples/venv.py new file mode 100755 index 0000000000..4fb109d046 --- /dev/null +++ b/testing/mozharness/examples/venv.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +"""venv.py + +Test virtualenv creation. This installs talos in the local venv; that's it. +""" + +from __future__ import absolute_import +import os +import sys + +sys.path.insert(1, os.path.dirname(sys.path[0])) + +from mozharness.base.errors import PythonErrorList +from mozharness.base.python import virtualenv_config_options, VirtualenvMixin +from mozharness.base.script import BaseScript + +# VirtualenvExample {{{1 +class VirtualenvExample(VirtualenvMixin, BaseScript): + config_options = [ + [ + ["--talos-url"], + { + "action": "store", + "dest": "talos_url", + "default": "https://hg.mozilla.org/build/talos/archive/tip.tar.gz", + "help": "Specify the talos pip url", + }, + ] + ] + virtualenv_config_options + + def __init__(self, require_config_file=False): + super(VirtualenvExample, self).__init__( + config_options=self.config_options, + all_actions=[ + "create-virtualenv", + ], + default_actions=[ + "create-virtualenv", + ], + require_config_file=require_config_file, + config={"virtualenv_modules": ["talos"]}, + ) + + +# __main__ {{{1 +if __name__ == "__main__": + venv_example = VirtualenvExample() + venv_example.run_and_exit() diff --git a/testing/mozharness/examples/verbose_script.py b/testing/mozharness/examples/verbose_script.py new file mode 100755 index 0000000000..0478d05297 --- /dev/null +++ b/testing/mozharness/examples/verbose_script.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +"""verbose_script.py + +Contrast to silent_script.py. +""" + +from __future__ import absolute_import +import os +import sys + +sys.path.insert(1, os.path.dirname(sys.path[0])) + +# from mozharness.base.errors import TarErrorList, SSHErrorList +from mozharness.base.script import BaseScript + + +# VerboseExample {{{1 +class VerboseExample(BaseScript): + def __init__(self, require_config_file=False): + super(VerboseExample, self).__init__( + all_actions=[ + "verbosity", + ], + require_config_file=require_config_file, + config={"tarball_name": "bar.tar.bz2"}, + ) + + def verbosity(self): + tarball_name = self.config["tarball_name"] + self.download_file( + "http://people.mozilla.org/~asasaki/foo.tar.bz2", file_name=tarball_name + ) + # the error_list adds more error checking. + # the halt_on_failure will kill the script at this point if + # unsuccessful. Be aware if you need to do any cleanup before you + # actually fatal(), though. If so, you may want to either use an + # |if self.run_command(...):| construct, or define a self._post_fatal() + # for a generic end-of-fatal-run method. + self.run_command( + ["tar", "xjvf", tarball_name], + # error_list=TarErrorList, + # halt_on_failure=True, + # fatal_exit_code=3, + ) + self.rmtree("x/ship2") + self.rmtree(tarball_name) + self.run_command( + ["tar", "cjvf", tarball_name, "x"], + # error_list=TarErrorList, + # halt_on_failure=True, + # fatal_exit_code=3, + ) + self.rmtree("x") + if self.run_command( + ["scp", tarball_name, "people.mozilla.org:public_html/foo2.tar.bz2"], + # error_list=SSHErrorList, + ): + self.error( + "There's been a problem with the scp. We're going to proceed anyway." + ) + self.rmtree(tarball_name) + + +# __main__ {{{1 +if __name__ == "__main__": + verbose_example = VerboseExample() + verbose_example.run_and_exit() |