a/trunk/cforge/cforge/Package/CFORGE/Scripts/cds_script.py | b/trunk/cforge/cforge/Package/CFORGE/Scripts/cds_script.py | ||
---|---|---|---|
1 | # imports |
1 | # imports |
2 | import sys |
2 | import sys |
3 | import os |
3 | import os |
4 | 4 | ||
5 | from System.Diagnostics import Process |
5 | # |
6 | from System.Net import WebClient |
6 | # this is a general helper module providing some basic functions to |
7 | # e.g. run CODESYS or another process with certain arguments |
||
8 | # |
||
9 | # |
||
10 | |||
11 | from System.Diagnostics import Process |
||
12 | from System.Net import WebClient |
||
13 | |||
14 | def RunProcess(workdir, process, args): |
||
15 | exitcode = -1 |
||
16 | print("run process: " + process + " " + args) |
||
17 | if not os.path.exists(workdir): |
||
18 | print("Path does not exist: " + workdir) |
||
19 | if not os.path.exists(os.path.join(workdir, process)): |
||
20 | print("File does not exist: " + process) |
||
21 | else: |
||
22 | p = Process() |
||
23 | p.StartInfo.WorkingDirectory=workdir |
||
24 | p.StartInfo.FileName = process |
||
25 | p.StartInfo.Arguments = args |
||
26 | p.Start() |
||
27 | p.WaitForExit() |
||
28 | exitcode = p.ExitCode |
||
29 | print("done: " + str(exitcode)) |
||
30 | return exitcode |
||
31 | |||
7 | 32 | ||
8 | def RunCodesysWithScript(scriptfilename, scriptargs=None): |
33 | def RunCodesysWithScript(scriptfilename, scriptargs=None): |
9 | print(scriptfilename) |
34 | print(scriptfilename) |
10 | # common paths |
35 | # common paths |
11 | workingdir = os.path.dirname(sys.argv[0]) |
36 | workingdir = os.path.dirname(sys.argv[0]) |
... |
... |
||
23 | 48 | ||
24 | # exe |
49 | # exe |
25 | codesys_exe = os.path.join(cdsdir, "Common", "CODESYS.exe") |
50 | codesys_exe = os.path.join(cdsdir, "Common", "CODESYS.exe") |
26 | packageman_exe = os.path.join(cdsdir, "Common", "PackageManager.exe") |
51 | packageman_exe = os.path.join(cdsdir, "Common", "PackageManager.exe") |
27 | workdir = os.path.join(cdsdir, "Common") |
52 | workdir = os.path.join(cdsdir, "Common") |
28 | 53 | exitcode = -1 |
|
29 | if not os.path.exists(scriptfilename): |
54 | if not os.path.exists(os.path.join(workingdir,scriptfilename)): |
30 | print("File does not exist: " + scriptfilename) |
55 | print("File does not exist: " + scriptfilename) |
31 | 56 | ||
32 | else: |
57 | else: |
33 | p = Process() |
58 | p = Process() |
34 | p.StartInfo.WorkingDirectory=workdir |
59 | p.StartInfo.WorkingDirectory=workdir |
35 | p.StartInfo.FileName = codesys_exe |
60 | p.StartInfo.FileName = codesys_exe |
36 | 61 | ||
37 | processargs = "--profile='" + lastprofile + "' --noUI --runscript='" + scriptfilename + "'" |
62 | processargs = "--profile='" + lastprofile + "' --runscript='" + os.path.join(workingdir,scriptfilename) + "'" |
63 | processargs += " --noUI" |
||
38 | if scriptargs != None: |
64 | if scriptargs != None: |
39 | processargs += " --scriptargs:'" + scriptargs + "'" |
65 | processargs += " --scriptargs:'" + scriptargs + "'" |
40 | 66 | print("running codesys with script " + scriptfilename) |
|
41 | p.StartInfo.Arguments = processargs |
67 | p.StartInfo.Arguments = processargs |
42 | p.Start() |
68 | p.Start() |
43 | p.WaitForExit() |
69 | p.WaitForExit() |
44 | 70 | ||
71 | exitcode = p.ExitCode |
||
72 | |||
73 | print("done: " + str(exitcode)) |
||
74 | return exitcode |
||
45 | 75 | ||
46 | 76 |