[r86]: / trunk / cforge / cforge / Package / CFORGE / Scripts / action.svn.checkout.py  Maximize  Restore  History

Download this file

72 lines (59 with data), 1.9 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
# Example Batch:
# set WD=%~d0%~p0
# set USER=<username>
# set PASS=<password>
# set URL=https://forge.codesys.com/svn/drv,gpio-mod,code/trunk/GPIOMods
# "C:\Program Files (x86)\3S CODESYS-V3.5.12.0\CODESYS\Common\CODESYS.exe" --profile="CODESYS V3.5 SP12" --runscript="%WD%\action.svn.checkout.py" --scriptargs="%URL% %USER% %PASS% %WD%" --noUI

import sys
import os.path
import pysvn

system.prompt_handling = PromptHandling.None

if len(sys.argv) <= 1:
	print("usage: <url> [<user> <pass> <working dir>]")
	sys.exit()

url = sys.argv[1].replace("`````", "'")

if len(sys.argv) > 3:
	username = sys.argv[2].replace("`````", "'")
	password = sys.argv[3].replace("`````", "'")
else:
	credentials = system.ui.query_credentials("Enter SVN credentials")
	username = credentials[0]
	password = credentials[1]

if len(sys.argv) > 4:
	path = sys.argv[4].replace("`````", "'")
else:
	path = system.ui.browse_directory_dialog("Choose a checkout folder")

def set_username(req):
	req.username = username
	req.password = password
	req.save = True # Optional

# checkout plain SVN files
pysvn.svn_checkout_non_codesys(username, password, url, path)

# get all CODESYS projects
svn.auth_username_password += set_username
cdsprojects = pysvn.svn_get_directories_with_codesys_projects(username, password, url)
# checkout all CODESYS projects
for p in cdsprojects:
	dirbase = path + "\\" + p.rstrip('/').replace("/", "\\")
	filebase = os.path.basename(dirbase)
	dir = os.path.dirname(dirbase)
	print("checkout via SVN...")
	try:
		svn.checkout(url + "/" + p, dir, filebase + ".library")
	except:
		pass
	print("... checkout done.")
	
	print("save project...")
	proj = projects.primary
	if proj.find("Project Information"):
		proj.save_as(dirbase + ".library")
	else:
		proj.save_as(dirbase + ".project")
	print("... project saved.")
	print("closing...")
	try:
		proj.close()
	except:
		pass
	print("... project closed.")
	

system.exit()