Diff of /trunk/cforge/cforge/Package/CFORGE/Scripts/import.py [r18] .. [r19]  Maximize  Restore

Switch to side-by-side view

--- a/trunk/cforge/cforge/Package/CFORGE/Scripts/import.py
+++ b/trunk/cforge/cforge/Package/CFORGE/Scripts/import.py
@@ -1,68 +1,89 @@
+# Example Batch:
+#set WD=%~d0%~p0
+#set USER=<username>
+#set PASS=<password>
+#set PROJECT=C:\Users\<bla>\Projekte\CODESYS\IoDrvSysfsGPIO.library
+#set URL=https://forge.codesys.com/svn/,,,,/IoDrvSysfsGPIO/
+#set MESSAGE='initial commit'
+#"C:\Program Files (x86)\3S CODESYS\CODESYS\Common\CODESYS.exe" --Profile="CODESYS V3.5 SP12" --runscript="C:\Program Files (x86)\3S CODESYS\CODESYS\CFORGE\Scripts\import.py" --scriptargs="%USER% %PASS% %PROJECT% %URL% %WD% %MESSAGE%" --noUI
+
+# if not all parameters are passed, there will be message prompts
+# this makes it possible to use it from inside codesys
+
 import sys, os
 
 
-# this script helps to import a given project or library into codesys forge
-# it can be called via cforge, but also directly from inside codesys (for now this is experimental!)
+
+class ER(ExportReporter):
+    def error(self, object, message):   
+        system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message))
+    def warning(self, object, message):   
+        system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message))
+    def nonexportable(self, object):   
+        system.write_message(Severity.Information, "Object not exportable: %s" % object)
+    @property
+    def aborting(self):
+        return False;
+
+		
+if len(sys.argv) > 1:
+	username=sys.argv[1]
+else:
+	username = system.ui.query_string("Enter the svn username")
+	
+		
+if len(sys.argv) > 2:
+	password=sys.argv[2]
+else:
+	password = system.ui.query_password("Enter the svn password")
+	
+	
+if len(sys.argv) > 3:
+	project=sys.argv[3]
+else:
+	res = system.ui.open_file_dialog("Choose file:", filter="Project files (*.project)|*.project|Library files (*.library)|*.library", filter_index = 0, multiselect=False)
+	project = res
+	
+
+if len(sys.argv) > 4:
+	url=sys.argv[4]
+else:
+	url = system.ui.query_string("Enter the svn url:")
+
+if len(sys.argv) > 5:
+	message=sys.argv[5]
+else:
+	message = system.ui.query_string("Enter the commit message:")
+	
+def set_username(req):
+    print_all(req)
+    req.username = username
+    req.password = password
+    req.save = True # Optional
+
+svn.auth_username_password += set_username
 
 
-def cforge_usage():
-    help = [ 
-	    ["<path to CODESYS project>", "---"]
-    ]
-
-    return help
-
-bRunningFromCDS = False
+print("open project: " + project)
+p = projects.open(project)
+reporter = ER()
+print("export plcopen xml")
+p.export_xml(reporter, p.get_children(False), p.path + ".plcopen.xml", True, True, True)
 
 
-try:
-	p = projects.primary
-	bRunningFromCDS = True
-	print("running from cds")
-except:
-	print("not running from cds")
-	pass
-
-# do the xml export
-workingdir = os.path.dirname(sys.argv[0])
-print(workingdir)
-sys.path.append(workingdir)
-import cds_script
-
-if bRunningFromCDS:
-	
-	from  plcopenxml_export import export
-	export(scriptargs)
-	
-else: 	# running from cforge
-	scriptname = os.path.join(workingdir, "plcopenxml_export.py")
-	scriptargs = sys.argv[1]
-	
-	cds_script.RunCodesysWithScript(scriptname, scriptargs)
+print("is versioned: " + str(p.svn.is_versioned))
 
 
-# do the commit
-print("commit")
-tsvn_workdir="C:\\Program Files\\TortoiseSVN\\bin\\"
-bCDSSvn = False
-try:
-	dir(svn)
-	bCDSSvn = True
-except:
-	print("CODESYS SVN not installed!")
-	exit()
 
-elif os.path.exists(tsvn_workdir):
-	print("using Tortoise svn")
-	filename = scriptargs
+if not p.svn.is_versioned:
+	print("importing project to svn...")
+	p.svn.import_project(url,message)
+	print("import done!")
+else:
+	print("committing project to svn...")
+	p.svn.commit()
+	print("commit done!")
 	
-	e = cds_script.RunProcess(tsvn_workdir,"SubWCRev.exe", filename)	
-	if e == 10: # is not a working copy:
-		cds_script.RunProcess(tsvn_workdir,"TortoiseProc.exe", '/command:import "/path:' + filename + '"')
-	else:
-		cds_script.RunProcess(tsvn_workdir,"TortoiseProc.exe", '/command:commit "/path:' + filename + '"')
-	
-	
-	
-else:
-	print("SVN not installed at all")
\ No newline at end of file
+p.close()
+		
+	
\ No newline at end of file