[r46]: / trunk / cforge / cforge / Package / CFORGE / Scripts / import.py  Maximize  Restore  History

Download this file

89 lines (63 with data), 2.5 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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



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


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)


print("is versioned: " + str(p.svn.is_versioned))



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!")
	
p.close()