[r14]: / trunk / cforge / cforge / Package / CFORGE / Scripts / cds_script.py  Maximize  Restore  History

Download this file

47 lines (35 with data), 1.3 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
# 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()