tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

action_config_script.py (3827B)


      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/.
      5 
      6 """action_config_script.py
      7 
      8 Demonstrate actions and config.
      9 """
     10 
     11 import os
     12 import sys
     13 import time
     14 
     15 sys.path.insert(1, os.path.dirname(sys.path[0]))
     16 
     17 from mozharness.base.script import BaseScript
     18 
     19 
     20 # ActionsConfigExample {{{1
     21 class ActionsConfigExample(BaseScript):
     22    config_options = [
     23        [
     24            [
     25                "--beverage",
     26            ],
     27            {
     28                "action": "store",
     29                "dest": "beverage",
     30                "type": "string",
     31                "help": "Specify your beverage of choice",
     32            },
     33        ],
     34        [
     35            [
     36                "--ship-style",
     37            ],
     38            {
     39                "action": "store",
     40                "dest": "ship_style",
     41                "type": "choice",
     42                "choices": ["1", "2", "3"],
     43                "help": "Specify the type of ship",
     44            },
     45        ],
     46        [
     47            [
     48                "--long-sleep-time",
     49            ],
     50            {
     51                "action": "store",
     52                "dest": "long_sleep_time",
     53                "type": "int",
     54                "help": "Specify how long to sleep",
     55            },
     56        ],
     57    ]
     58 
     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",
     66            ],
     67            default_actions=[
     68                "clobber",
     69                "nap",
     70                "ship-it",
     71            ],
     72            require_config_file=require_config_file,
     73            config={
     74                "beverage": "kool-aid",
     75                "long_sleep_time": 3600,
     76                "ship_style": "1",
     77            },
     78        )
     79 
     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.")
     94 
     95    def _ship1(self):
     96        self.info(
     97            r"""
     98     _~
     99  _~ )_)_~
    100  )_))_))_)
    101  _!__!__!_
    102  \______t/
    103 ~~~~~~~~~~~~~
    104 """
    105        )
    106 
    107    def _ship2(self):
    108        self.info(
    109            r"""
    110    _4 _4
    111   _)_))_)
    112  _)_)_)_)
    113 _)_))_))_)_
    114 \_=__=__=_/
    115 ~~~~~~~~~~~~~
    116 """
    117        )
    118 
    119    def _ship3(self):
    120        self.info(
    121            """
    122 ,;;:;,
    123   ;;;;;
    124  ,:;;:;    ,'=.
    125  ;:;:;' .=" ,'_\\
    126  ':;:;,/  ,__:=@
    127   ';;:;  =./)_
    128     `"=\\_  )_"`
    129          ``'"`
    130 """
    131        )
    132 
    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"]
    142            )
    143        else:
    144            self.info(
    145                "This will be quick, but grab a %s anyway." % self.config["beverage"]
    146            )
    147        self._sleep(self.config["long_sleep_time"])
    148 
    149    def ship_it(self):
    150        name = "_ship%s" % self.config["ship_style"]
    151        if hasattr(self, name):
    152            getattr(self, name)()
    153 
    154 
    155 # __main__ {{{1
    156 if __name__ == "__main__":
    157    actions_config_example = ActionsConfigExample()
    158    actions_config_example.run_and_exit()