Skip to content

Commit

Permalink
separate randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed May 30, 2018
1 parent 2f350ec commit 6f1e069
Show file tree
Hide file tree
Showing 4 changed files with 706 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ target/
FoundationPlist.py

# Go junk
bin/
vendor/
report_broken_client/build
50 changes: 50 additions & 0 deletions payload/usr/local/sal/bin/randomizer
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/python

import subprocess
import optparse
import time

def get_options():
"""Return commandline options."""
usage = "%prog [options]"
option_parser = optparse.OptionParser(usage=usage)
option_parser.add_option(
"--delay", default=0, type=int,
help="Delay running for between 0 and N seconds.")
option_parser.add_option(
"--path", default='/usr/local/sal/bin/sal-submit', type=str,
help="Path to script to run")
# We have no arguments, so don't store the results.
opts, _ = option_parser.parse_args()
return opts

def random_delay(delay):
if delay == 0:
print 'No delay set'
return
randomized_delay = random.randrange(0, delay)
print "Delaying run by %s seconds" % randomized_delay
time.sleep(randomized_delay)

def execute_path(path):
path_stat = os.stat(path)
if not path_stat.st_mode & stat.S_IWOTH:
try:
subprocess.call([path], stdin=None)
except (OSError, subprocess.CalledProcessError):
print "'{}' had errors during execution!".format(path)
else:
print "'{}' is not executable or has bad permissions".format(path)

def main():
opts = get_options()
path = opts.path
delay = opts.delay

if delay > 0:
random_delay(delay)

execute_path(path)

if __name__ == '__main__':
main()
Loading

0 comments on commit 6f1e069

Please sign in to comment.