15 def install_dumpling():
17 if (not os.path.isfile(dumplingPath)):
18 url = "https://dumpling.int-dot.net/api/client/dumpling.py"
19 scriptPath = os.path.dirname(os.path.realpath(__file__))
20 downloadLocation = scriptPath + "/dumpling.py"
21 response = urllib2.urlopen(url)
22 if response.getcode() == 200:
23 with open(downloadLocation, 'w') as f:
24 f.write(response.read())
25 subprocess.call([sys.executable, downloadLocation, "install", "--update"])
27 raise urllib2.URLError("HTTP Status Code" + str(result.getcode()))
29 subprocess.call([sys.executable, dumplingPath, "install"])
30 except urllib2.HTTPError, e:
31 print("Dumpling cannot be installed from " + url + " due to: " + str(e).replace(':', '')) # Remove : to avoid looking like error format
32 except urllib2.URLError, e:
33 print("Dumpling cannot be installed from " + url + " due to: " + str(e.reason))
35 print("An unexpected error was encountered while installing dumpling.py: " + traceback.format_exc())
37 def ensure_installed():
38 if (not os.path.isfile(dumplingPath)):
39 print("Dumpling has not been installed yet. Please run \"DumplingHelper.py install_dumpling\" before collect_dumps.")
44 def find_latest_dump(folder, startTimeStr):
45 startTime = float(startTimeStr)
48 # Outside of Windows, core files are generally dumped into the executable's directory,
49 # so it may have many other files in it. Filter those out.
50 if sys.platform != "win32":
51 globPattern = "/*core*"
53 allFiles = glob.glob(folder + globPattern);
55 latestFile = max(allFiles, key=os.path.getmtime)
56 latestTime = os.path.getmtime(latestFile)
57 if (latestTime > startTime):
61 def collect_dump(exitcodeStr, folder, startTimeStr, projectName, incpaths):
62 exitcode = int(exitcodeStr)
67 if not ensure_installed():
70 if (not incpaths is None):
71 # Normalize incpaths so it can be passed to dumpling.py.
72 incpaths = incpaths.split(",")
73 incpaths = string.join(incpaths, " ")
75 # Find candidate crash dumps in the given folder.
76 print("Trying to find crash dumps for project: " + projectName)
77 file = find_latest_dump(folder, startTimeStr)
79 print("No new dump file was found in " + folder)
81 # File was found; upload it.
82 print("Uploading dump file: " + file)
83 procArgs = string.join([
84 sys.executable, dumplingPath, "upload",
88 "--displayname", projectName,
89 "--properties", "STRESS_TESTID="+projectName
91 if (not incpaths is None):
92 procArgs = procArgs + " --incpaths " + incpaths
94 subprocess.call(procArgs, shell=True)
99 print("DumplingHelper.py <command>")
101 print(" install_dumpling:")
102 print(" - Installs dumpling globally on the machine.")
103 print(" get_timestamp:")
104 print(" - Prints out the current timestamp of the machine.")
105 print(" collect_dump <exitcode> <folder> <starttime> <projectname> <incpaths>:")
106 print(" - Collects and uploads the latest dump (after start time) from the folder to the dumpling service.")
113 if (argv[1] == "install_dumpling"):
115 elif (argv[1] == "get_timestamp"):
117 elif (argv[1] == "collect_dump"):
119 collect_dump(argv[2], argv[3], argv[4], argv[5], None)
120 elif (len(argv) == 7):
121 collect_dump(argv[2], argv[3], argv[4], argv[5], argv[6])
123 print("Invalid number of arguments passed to collect_dump.")
126 print(argv[1] + " is not a valid command.")
130 dumplingPath = os.path.expanduser("~/.dumpling/dumpling.py")
131 if __name__ == '__main__':