-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_backup.py
More file actions
103 lines (87 loc) · 3.45 KB
/
test_backup.py
File metadata and controls
103 lines (87 loc) · 3.45 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
102
103
#!/usr/bin/env python3
# Copyright (C) 2024-2026 OPEN CASCADE SAS
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
import subprocess
import sys, os
#import tempfile
#------------------------------------------------------------------------
def checkFileInSubprocess(logFile, title, args):
errCode = 0
try:
logFile.write(f"starting {title} process:\n")
logFile.write(" cmd_line = '{}'\n".format(" ".join(args)))
my_env = os.environ.copy()
my_env["QT_QPA_PLATFORM"] = "offscreen" # run SALOME in headless mode (=without GUI)
proc = subprocess.Popen(args, env=my_env)
try:
logFile.write(f" start communication with {title}\n")
proc.communicate(timeout = 500)
logFile.write(f"{title} terminated\n")
errCode = proc.returncode
logFile.write(f"{title} returned: {errCode}\n")
except subprocess.TimeoutExpired:
errCode = 96
logFile.write(f"{title} timed out\n")
except Exception as ex:
errCode = 97
logFile.write(f"Exception caught: {ex}\n")
except:
errCode = 98
logFile.write("Unknown Exception caught\n")
logFile.write(f"errCode = {errCode}\n")
except:
errCode = 99
return errCode
#------------------------------------------------------------------------
def checkBackups(backupFolder, baseName, checkScript):
errCode = 0
try:
# Create a log file in the backup folder starting with the same base name
with open(os.path.join(backupFolder, baseName+"_test.log"), "w") as logFile:
logFile.write("test_backup script started\n")
logFile.write(f" backupFolder = {backupFolder}\n")
logFile.write(f" baseName = {baseName}\n")
logFile.write(f" checkScript = {checkScript}\n")
hdfFile = os.path.join(backupFolder, baseName+".hdf")
logFile.write(f" hdfFile = {hdfFile}\n")
args = ["runSalome.py", "--modules", "GEOM,SHAPER,SHAPERSTUDY,SMESH", "--batch", "--splash", "0", checkScript, "args:" + hdfFile]
errCode = checkFileInSubprocess(logFile, "SALOME", args)
logFile.write(f"errCode = {errCode}\n")
if errCode == 0:
pyFile = os.path.join(backupFolder, baseName+".py")
logFile.write(f" pyfile = {pyFile}\n")
args = ["python", checkScript, pyFile]
errCode = checkFileInSubprocess(logFile, "PYTHON", args)
logFile.write(f"errCode = {errCode}\n")
except:
errCode = 100
return errCode
#------------------------------------------------------------------------
errCode = 0
try:
if (len(sys.argv) != 4):
errCode = 101
else:
backupFolder = sys.argv[1]
baseName = sys.argv[2]
checkScript = sys.argv[3]
errCode = checkBackups(backupFolder, baseName, checkScript)
except:
errCode = 102
exit(errCode)