verbose_script.py (2380B)
1 #!/usr/bin/env python 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/. 5 6 """verbose_script.py 7 8 Contrast to silent_script.py. 9 """ 10 11 import os 12 import sys 13 14 sys.path.insert(1, os.path.dirname(sys.path[0])) 15 16 # from mozharness.base.errors import TarErrorList, SSHErrorList 17 from mozharness.base.script import BaseScript 18 19 20 # VerboseExample {{{1 21 class VerboseExample(BaseScript): 22 def __init__(self, require_config_file=False): 23 super(VerboseExample, self).__init__( 24 all_actions=[ 25 "verbosity", 26 ], 27 require_config_file=require_config_file, 28 config={"tarball_name": "bar.tar.xz"}, 29 ) 30 31 def verbosity(self): 32 tarball_name = self.config["tarball_name"] 33 self.download_file( 34 "http://people.mozilla.org/~asasaki/foo.tar.xz", file_name=tarball_name 35 ) 36 # the error_list adds more error checking. 37 # the halt_on_failure will kill the script at this point if 38 # unsuccessful. Be aware if you need to do any cleanup before you 39 # actually fatal(), though. If so, you may want to either use an 40 # |if self.run_command(...):| construct, or define a self._post_fatal() 41 # for a generic end-of-fatal-run method. 42 self.run_command( 43 ["tar", "xJvf", tarball_name], 44 # error_list=TarErrorList, 45 # halt_on_failure=True, 46 # fatal_exit_code=3, 47 ) 48 self.rmtree("x/ship2") 49 self.rmtree(tarball_name) 50 self.run_command( 51 ["tar", "cJvf", tarball_name, "x"], 52 # error_list=TarErrorList, 53 # halt_on_failure=True, 54 # fatal_exit_code=3, 55 ) 56 self.rmtree("x") 57 if self.run_command( 58 ["scp", tarball_name, "people.mozilla.org:public_html/foo2.tar.xz"], 59 # error_list=SSHErrorList, 60 ): 61 self.error( 62 "There's been a problem with the scp. We're going to proceed anyway." 63 ) 64 self.rmtree(tarball_name) 65 66 67 # __main__ {{{1 68 if __name__ == "__main__": 69 verbose_example = VerboseExample() 70 verbose_example.run_and_exit()