[r58]: / trunk / cforge / cforge / Package / CFORGE / Scripts / checkout-prj.py  Maximize  Restore  History

Download this file

68 lines (57 with data), 2.2 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
import sys, os
import ui
import pysvn
import json
from System.Net import WebClient

base_url = "https://forge.codesys.com/rest"
base_svn = "https://forge.codesys.com/svn/"

# This is a cforge command (script file)
# this will be run as ironpython script.
# the filename of this script is automatically the corresponding cforge command 
# with some magic functions you can easily integrate it nicely into cforge tool

# cforge_usage: 
# here you can return an array of all possible arguments and options that can 
# be passed to this command script
def cforge_usage():
    help = [ 
        ["<path to CODESYS project>", "---"]
    ]

    return help

def get_json(url):
    web_client = WebClient()
    r = web_client.DownloadData(url)
    j = json.loads(bytes(r).decode('utf-8'))
    return j

    
if len(sys.argv) <= 1:
    print("Oh, there are no arguments. Perhaps you forgot something?")
    sys.exit()

args = sys.argv[1].split(" ")
folder = ""
if len(args) == 1:
    folder = args[0].strip("/").split("/")[-1]

# username, password and path are specified at the command line
config = dict()
if len(sys.argv)>= 3:
    config['user'] = sys.argv[2]
    config['pass'] = sys.argv[3]
    config['folder'] = sys.argv[4]
else:
    config = ui.Dialog("Checkout Project", Folder=True, Credentials=True, DefaultFolder=folder)

# iterate over all tools of the project, and checkout all SVN repositories,
# excluding the CODESYS folders
if config != None:
    tools = get_json(base_url + '/' + sys.argv[1])
    for tool in tools['tools']:
        if tool['name'] == 'svn':
            repo = tool['url'][1:-1].replace('/', ',')
            url = base_svn + repo
            print(url)
            # checkout
            pysvn.svn_checkout_non_codesys(config['user'], config['pass'], url, os.path.join(config['folder'], repo))
            print('\n')
            # store commit count
            details = get_json(base_url + tool['url'])
            f = open(os.path.join(config['folder'], repo + '.commit_count'), "w")
            if f:
                f.write(str(details['commit_count']))
                f.close()