-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-script
More file actions
executable file
·101 lines (80 loc) · 4.18 KB
/
run-script
File metadata and controls
executable file
·101 lines (80 loc) · 4.18 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
'''
Author: Oliver Bartley (obartley@ebay.com)
Date: 28 NOV 2011
Version: 1.0
Configure the Java environment and Sikuli interpereter to run .sikuli scripts that make use of SeeMonkey objects.
For usage, run with the -h option
'''
import sys, os
import argparse
import subprocess
def main():
# parse command line arguments
parser = argparse.ArgumentParser(description = "Configure the Java environment and Sikuli interpereter to run .sikuli scripts that make use of SeeMonkey objects.")
parser.add_argument("--android-sdk", dest="androidSdk", default=None,
help="Sets path to local Android SDK. Default is to use the value of the environment variable $ANDROID_SDK", metavar = "DIR")
parser.add_argument("--seemonkey-root", dest="seemonkeyRoot", default=os.getcwd(),
help="Sets path to the root of the SeeMonkey package. Due to the way the Sikuli interpereter locates native libraries, they must always be available in 'DIR/libs'.\
Use this option if you need to run a script from within a directory outside of the package root.\
Default is the current working directory.", metavar="DIR")
parser.add_argument("--set-property", action='append', dest='props',
help="Sets a Java system property 'seemonkey.NAME'='VALUE', e.g. '--set-property xmlrunner.output=foo/bar' will set the Java system property 'seemonkey.xmlrunner.output' equal to 'foo/bar'. This is useful to pass additional data to the sikuli environment from the command line.", metavar="NAME=VALUE")
parser.add_argument("path_to_script", help="path to sikuli script", nargs='+')
args = parser.parse_args()
os.chdir(args.seemonkeyRoot)
if args.androidSdk is None:
try:
androidSdk = stripSlash(os.environ['ANDROID_SDK'])
except:
# throws a KeyError if the variable is not set
sys.stderr.write("Cannot locate Android SDK\n")
sys.stderr.write("Set $ANDROID_SDK or use the --android-sdk option to specify a path.\n")
exit(1)
else:
androidSdk = stripSlash(args.androidSdk)
try:
javaClasspath = os.environ['CLASSPATH']
except:
# throws a KeyError if the variable is not set
javaClasspath = ''
# add custom seeMonkey stuff to the classpath
for j in ["libs/sikuli-script.jar",
"libs/seeMonkey.jar",
"libs/python"]: # additional python packages/modules to be imported within sikuli scripts
javaClasspath = "%s:%s" %(javaClasspath, j)
# add android sdk libs to the classpath
for j in ['guavalib.jar',
'monkeyrunner.jar',
'sdklib.jar',
'chimpchat.jar',
'ddmlib.jar']:
javaClasspath = "%s:%s/tools/lib/%s" % (javaClasspath, androidSdk, j)
# construct the process call in a list object
procCall = ["java", "-cp", javaClasspath]
# add set-property arguments, if available
# note the addition of the seemonkey namespace, which makes this command less able
# to unintentionaly attempt to set a Java system property.
# p should be in the form of "key=value" so that the arg ends up looking like "-Dseemonkey.key=value"
if args.props is not None:
for p in args.props:
procCall.append("-Dseemonkey.%s" % p)
# set the android sdk path so that SeeMonkey can see it
procCall.append("-Dandroid.sdk.dir=%s" % androidSdk)
procCall.append("org.sikuli.script.SikuliScript")
# now we just push a script path, issue the process call for each script path given
for s in args.path_to_script:
print("Running script '%s'..." % s)
procCall.append(s)
subprocess.call(procCall)
procCall.pop() # remove the name of the script we just ran,
# so that we're ready for the next item in args.scripts
def stripSlash(path):
'''
Strip the trailing slash, if present, in a given path
'''
if path[-1:] == "/":
path = path[0:-1]
return path
if (__name__ == "__main__"):
main()