--- a +++ b/trunk/cforge/cforge/Package/CFORGE/Scripts/cds_script.py @@ -0,0 +1,46 @@ +# imports +import sys +import os + +from System.Diagnostics import Process +from System.Net import WebClient + +def RunCodesysWithScript(scriptfilename, scriptargs=None): + print(scriptfilename) + # common paths + workingdir = os.path.dirname(sys.argv[0]) + cdsdir = os.path.abspath(os.path.join(workingdir, os.path.pardir, os.path.pardir)) + #print(cdsdir) + + # profile stuff + profiledir=os.path.join(cdsdir,"Profiles") + #print(profiledir) + lastprofile="" + for file in os.listdir(profiledir): + if file.endswith(".profile"): + lastprofile = file.replace(".profile","") + #print(lastprofile) + + # exe + codesys_exe = os.path.join(cdsdir, "Common", "CODESYS.exe") + packageman_exe = os.path.join(cdsdir, "Common", "PackageManager.exe") + workdir = os.path.join(cdsdir, "Common") + + if not os.path.exists(scriptfilename): + print("File does not exist: " + scriptfilename) + + else: + p = Process() + p.StartInfo.WorkingDirectory=workdir + p.StartInfo.FileName = codesys_exe + + processargs = "--profile='" + lastprofile + "' --noUI --runscript='" + scriptfilename + "'" + if scriptargs != None: + processargs += " --scriptargs:'" + scriptargs + "'" + + p.StartInfo.Arguments = processargs + p.Start() + p.WaitForExit() + + +