a/trunk/cforge/cforge/Package/CFORGE/Scripts/import.py | b/trunk/cforge/cforge/Package/CFORGE/Scripts/import.py | ||
---|---|---|---|
1 | import sys, os |
1 | # Example Batch: |
2 | 2 | #set WD=%~d0%~p0 |
|
3 | 3 | #set USER=<username> |
|
4 | # this script helps to import a given project or library into codesys forge |
4 | #set PASS=<password> |
5 | # it can be called via cforge, but also directly from inside codesys (for now this is experimental!) |
5 | #set PROJECT=C:\Users\<bla>\Projekte\CODESYS\IoDrvSysfsGPIO.library |
6 | 6 | #set URL=https://forge.codesys.com/svn/,,,,/IoDrvSysfsGPIO/ |
|
7 | 7 | #set MESSAGE='initial commit' |
|
8 | def cforge_usage(): |
8 | #"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 |
9 | help = [ |
9 | |
10 | ["<path to CODESYS project>", "---"] |
10 | # if not all parameters are passed, there will be message prompts |
11 | ] |
11 | # this makes it possible to use it from inside codesys |
12 | 12 | ||
13 | return help |
13 | import sys, os |
14 | 14 | ||
15 | bRunningFromCDS = False |
15 | |
16 | 16 | ||
17 | 17 | class ER(ExportReporter): |
|
18 | try: |
18 | def error(self, object, message): |
19 | p = projects.primary |
19 | system.write_message(Severity.Error, "Error exporting %s: %s" % (object, message)) |
20 | bRunningFromCDS = True |
20 | def warning(self, object, message): |
21 | print("running from cds") |
21 | system.write_message(Severity.Warning, "Warning exporting %s: %s" % (object, message)) |
22 | except: |
22 | def nonexportable(self, object): |
23 | print("not running from cds") |
23 | system.write_message(Severity.Information, "Object not exportable: %s" % object) |
24 | pass |
24 | @property |
25 | 25 | def aborting(self): |
|
26 | # do the xml export |
26 | return False; |
27 | workingdir = os.path.dirname(sys.argv[0]) |
27 | |
28 | print(workingdir) |
28 | |
29 | sys.path.append(workingdir) |
29 | if len(sys.argv) > 1: |
30 | import cds_script |
30 | username=sys.argv[1] |
31 | 31 | else: |
|
32 | if bRunningFromCDS: |
32 | username = system.ui.query_string("Enter the svn username") |
33 | 33 | ||
34 | from plcopenxml_export import export |
34 | |
35 | export(scriptargs) |
35 | if len(sys.argv) > 2: |
36 | 36 | password=sys.argv[2] |
|
37 | else: # running from cforge |
37 | else: |
38 | scriptname = os.path.join(workingdir, "plcopenxml_export.py") |
38 | password = system.ui.query_password("Enter the svn password") |
39 | scriptargs = sys.argv[1] |
39 | |
40 | 40 | ||
41 | cds_script.RunCodesysWithScript(scriptname, scriptargs) |
41 | if len(sys.argv) > 3: |
42 | 42 | project=sys.argv[3] |
|
43 | 43 | else: |
|
44 | # do the commit |
44 | res = system.ui.open_file_dialog("Choose file:", filter="Project files (*.project)|*.project|Library files (*.library)|*.library", filter_index = 0, multiselect=False) |
45 | print("commit") |
45 | project = res |
46 | tsvn_workdir="C:\\Program Files\\TortoiseSVN\\bin\\" |
46 | |
47 | bCDSSvn = False |
47 | |
48 | try: |
48 | if len(sys.argv) > 4: |
49 | dir(svn) |
49 | url=sys.argv[4] |
50 | bCDSSvn = True |
50 | else: |
51 | except: |
51 | url = system.ui.query_string("Enter the svn url:") |
52 | print("CODESYS SVN not installed!") |
52 | |
53 | exit() |
53 | if len(sys.argv) > 5: |
54 | 54 | message=sys.argv[5] |
|
55 | elif os.path.exists(tsvn_workdir): |
55 | else: |
56 | print("using Tortoise svn") |
56 | message = system.ui.query_string("Enter the commit message:") |
57 | filename = scriptargs |
57 | |
58 | 58 | def set_username(req): |
|
59 | e = cds_script.RunProcess(tsvn_workdir,"SubWCRev.exe", filename) |
59 | print_all(req) |
60 | if e == 10: # is not a working copy: |
60 | req.username = username |
61 | cds_script.RunProcess(tsvn_workdir,"TortoiseProc.exe", '/command:import "/path:' + filename + '"') |
61 | req.password = password |
62 | else: |
62 | req.save = True # Optional |
63 | cds_script.RunProcess(tsvn_workdir,"TortoiseProc.exe", '/command:commit "/path:' + filename + '"') |
63 | |
64 | 64 | svn.auth_username_password += set_username |
|
65 | 65 | ||
66 | 66 | ||
67 | else: |
67 | print("open project: " + project) |
68 | print("SVN not installed at all") |
68 | p = projects.open(project) |
69 | reporter = ER() |
||
70 | print("export plcopen xml") |
||
71 | p.export_xml(reporter, p.get_children(False), p.path + ".plcopen.xml", True, True, True) |
||
72 | |||
73 | |||
74 | print("is versioned: " + str(p.svn.is_versioned)) |
||
75 | |||
76 | |||
77 | |||
78 | if not p.svn.is_versioned: |
||
79 | print("importing project to svn...") |
||
80 | p.svn.import_project(url,message) |
||
81 | print("import done!") |
||
82 | else: |
||
83 | print("committing project to svn...") |
||
84 | p.svn.commit() |
||
85 | print("commit done!") |
||
86 | |||
87 | p.close() |
||
88 | |||
89 |