# Imports a Device in PLCOpenXML from Subversion via command line svn client import os, codecs, StringIO # Some variable definitions project_file = r"FULL PATH TO \Test.library" PLCopen_file = r"FULL PATH TO \PLCopenXML.xml" # Clean up any open project: if projects.primary: projects.primary.close() # The with construct automatically closes the open pipe for us. with open(PLCopen_file) 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() # Remove BOM from xml data BOMLEN = len(codecs.BOM_UTF8) if xmldata.startswith(codecs.BOM_UTF8): xmlSio = StringIO.StringIO(xmldata) xmlSio.read(BOMLEN) # ignore BOMLEN number of bytes xmldata = xmlSio.read() # read whats left # Import the data into the project project_reference.import_xml(reporter, xmldata) # And finally save project_reference.save()