forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdump_tour.py
executable file
·53 lines (39 loc) · 1.5 KB
/
dump_tour.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import argparse
import datetime
import os
import sys
import time
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'test')))
from galaxy_selenium import cli
DESCRIPTION = "Walk a Galaxy tour and dump screenshots."
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
args = _arg_parser().parse_args(argv)
driver_wrapper = cli.DriverWrapper(args)
output = args.output
assert output is not None
output = output.replace("TIMESTAMP", datetime.datetime.now().strftime("%Y%m%d%H%M%s"))
if os.path.exists(output):
raise Exception("Output directory %s exists, skipping")
else:
os.makedirs(output)
callback = DumpTourCallback(driver_wrapper, output)
driver_wrapper.run_tour(args.tour, tour_callback=callback)
class DumpTourCallback(object):
def __init__(self, driver_wrapper, output):
self.driver_wrapper = driver_wrapper
self.output = output
def handle_step(self, step, step_index):
time.sleep(.5)
self.driver_wrapper.driver.save_screenshot("%s/%i.png" % (self.output, step_index))
time.sleep(.5)
def _arg_parser():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('tour', metavar='TOUR', help='tour to walk')
parser.add_argument('-o', '--output', default="tour_dump_TIMESTAMP", help='directory to dump tour to')
parser = cli.add_selenium_arguments(parser)
return parser
if __name__ == "__main__":
main()