OSDN Git Service

97b78778a3b193945759993f77a8a70dd6cca8f9
[qt-creator-jp/qt-creator-jp.git] / tests / system / shared / qtcreator.py
1 import platform;
2 import shutil;
3 import os;
4 import glob;
5 import atexit;
6 import codecs;
7 import subprocess;
8 import errno;
9 from datetime import datetime,timedelta;
10
11 srcPath = ''
12 SettingsPath = ''
13 tmpSettingsDir = ''
14 testSettings.logScreenshotOnFail = True
15
16 source("../../shared/utils.py")
17 source("../../shared/build_utils.py")
18 source("../../shared/project.py")
19 source("../../shared/qtquick.py")
20 source("../../shared/editor_utils.py")
21
22 def waitForCleanShutdown(timeOut=10):
23     appCtxt = currentApplicationContext()
24     shutdownDone = False
25     if platform.system() in ('Windows','Microsoft'):
26         endtime = datetime.utcnow() + timedelta(seconds=timeOut)
27         while not shutdownDone:
28             # following work-around because os.kill() works for win not until python 2.7
29             tasks = subprocess.Popen("tasklist /FI \"PID eq %d\"" % appCtxt.pid, shell=True,stdout=subprocess.PIPE)
30             output = tasks.communicate()[0]
31             tasks.stdout.close()
32             if (output=="INFO: No tasks are running which match the specified criteria."
33                 or output=="" or output.find("ERROR")==0):
34                 shutdownDone=True
35             if not shutdownDone and datetime.utcnow() > endtime:
36                 break
37     else:
38         endtime = datetime.utcnow() + timedelta(seconds=timeOut)
39         while not shutdownDone:
40             try:
41                 os.kill(appCtxt.pid,0)
42             except OSError, err:
43                 if err.errno == errno.EPERM or err.errno == errno.ESRCH:
44                     shutdownDone=True
45             if not shutdownDone and datetime.utcnow() > endtime:
46                 break
47
48 def __removeTmpSettingsDir__():
49     waitForCleanShutdown()
50     deleteDirIfExists(os.path.dirname(tmpSettingsDir))
51
52 if platform.system() in ('Windows', 'Microsoft'):
53     sdkPath = "C:\\QtSDK"
54     cwd = os.getcwd()       # current dir is directory holding qtcreator.py
55     cwd+="\\..\\..\\settings\\windows"
56     defaultQtVersion = "Qt 4.7.4 for Desktop - MinGW 4.4 (Qt SDK)"
57 else:
58     sdkPath = os.path.expanduser("~/QtSDK")
59     cwd = os.getcwd()       # current dir is directory holding qtcreator.py
60     cwd+="/../../settings/unix"
61     defaultQtVersion = "Desktop Qt 4.7.4 for GCC (Qt SDK)"
62 srcPath = sdkPath + "/src"
63
64 cwd = os.path.abspath(cwd)
65 tmpSettingsDir = tempDir()
66 tmpSettingsDir = os.path.abspath(tmpSettingsDir+"/settings")
67 shutil.copytree(cwd, tmpSettingsDir)
68 # the following only doesn't work if the test ends in an exception
69 atexit.register(__removeTmpSettingsDir__)
70 SettingsPath = " -settingspath %s" % tmpSettingsDir
71