Script Example 4: Import a Device in PLCOpenXML From Subversion
This example imports a device in PLCOpenXML from Subversion via command line svn client. It can be started from the EcoStruxure Machine Expert user interface or from the command line.
# Script Example DeviceImportFromSvn.py
# Imports a Device in PLCOpenXML from Subversion via command line svn client
import os
# Some variable definitions
svn_executable = r"C:\Program Files\TortoiseSVN\bin\svn.exe"
project_file = r"C:\Python\test.project"
# !!! Important: File must be under version control !!!
export_file = r"C:\Python\SVN\MyController.xml"
# Clean up any open project:
if projects.primary:
projects.primary.close()
# Fetch the PLCOpenXML data from subversion
# The with construct automatically closes the open pipe for us.
with os.popen('"' + svn_executable + '" cat ' + export_file, "r") as pipe:
xmldata = pipe.read()
# Create a new project
project_reference = projects.create(project_file)
# Create the import reporter
class Reporter(ImportReporter):
def error(self, message):
system.write_message(Severity.Error, message)
def warning(self, message):
system.write_message(Severity.Warning, message)
def resolve_conflict(self, obj):
return ConflictResolve.Copy
def added(self, obj):
print("added: ", obj)
def replaced(self, obj):
print("replaced: ", obj)
def skipped(self, obj):
print("skipped: ", obj)
@property
def aborting(self):
return False
# Create the importer instance
reporter = Reporter()
# Import the data into the project
project_reference.import_xml(reporter, xmldata)
# And finally save
project_reference.save()