summaryrefslogtreecommitdiffstats
path: root/testing/mozharness/examples
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mozharness/examples
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozharness/examples')
-rwxr-xr-xtesting/mozharness/examples/action_config_script.py130
-rwxr-xr-xtesting/mozharness/examples/silent_script.py22
-rwxr-xr-xtesting/mozharness/examples/venv.py41
-rwxr-xr-xtesting/mozharness/examples/verbose_script.py63
4 files changed, 256 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 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()
diff --git a/testing/mozharness/examples/silent_script.py b/testing/mozharness/examples/silent_script.py
new file mode 100755
index 000000000..c73298ed7
--- /dev/null
+++ b/testing/mozharness/examples/silent_script.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+""" This script is an example of why I care so much about Mozharness' 2nd core
+concept, logging. http://escapewindow.dreamwidth.org/230853.html
+"""
+
+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 000000000..6b3c88f96
--- /dev/null
+++ b/testing/mozharness/examples/venv.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+"""venv.py
+
+Test virtualenv creation. This installs talos in the local venv; that's it.
+"""
+
+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 000000000..e8afd7567
--- /dev/null
+++ b/testing/mozharness/examples/verbose_script.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+"""verbose_script.py
+
+Contrast to silent_script.py.
+"""
+
+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()