a | b/trunk/cforge/cforge/Package/CFORGE/Scripts/cds_script.py | ||
---|---|---|---|
1 | # imports |
||
2 | import sys |
||
3 | import os |
||
4 | |||
5 | from System.Diagnostics import Process |
||
6 | from System.Net import WebClient |
||
7 | |||
8 | def RunCodesysWithScript(scriptfilename, scriptargs=None): |
||
9 | print(scriptfilename) |
||
10 | # common paths |
||
11 | workingdir = os.path.dirname(sys.argv[0]) |
||
12 | cdsdir = os.path.abspath(os.path.join(workingdir, os.path.pardir, os.path.pardir)) |
||
13 | #print(cdsdir) |
||
14 | |||
15 | # profile stuff |
||
16 | profiledir=os.path.join(cdsdir,"Profiles") |
||
17 | #print(profiledir) |
||
18 | lastprofile="" |
||
19 | for file in os.listdir(profiledir): |
||
20 | if file.endswith(".profile"): |
||
21 | lastprofile = file.replace(".profile","") |
||
22 | #print(lastprofile) |
||
23 | |||
24 | # exe |
||
25 | codesys_exe = os.path.join(cdsdir, "Common", "CODESYS.exe") |
||
26 | packageman_exe = os.path.join(cdsdir, "Common", "PackageManager.exe") |
||
27 | workdir = os.path.join(cdsdir, "Common") |
||
28 | |||
29 | if not os.path.exists(scriptfilename): |
||
30 | print("File does not exist: " + scriptfilename) |
||
31 | |||
32 | else: |
||
33 | p = Process() |
||
34 | p.StartInfo.WorkingDirectory=workdir |
||
35 | p.StartInfo.FileName = codesys_exe |
||
36 | |||
37 | processargs = "--profile='" + lastprofile + "' --noUI --runscript='" + scriptfilename + "'" |
||
38 | if scriptargs != None: |
||
39 | processargs += " --scriptargs:'" + scriptargs + "'" |
||
40 | |||
41 | p.StartInfo.Arguments = processargs |
||
42 | p.Start() |
||
43 | p.WaitForExit() |
||
44 | |||
45 | |||
46 |