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 90 91 | import sys, os import pysvn import json import build import commit hasWebClient = True try: from System.Net import WebClient except: import requests hasWebClient = False hasUI = True try: import ui except: hasUI = False 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 = [ ["json job string", "---"] ] return help def get_json(url): r = "" if hasWebClient: web_client = WebClient() r = web_client.DownloadData(url) else: r = requests.get(url).content 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() # Job is passed as first argument print("==========") print(sys.argv[1]) json_file = open(sys.argv[1], "r").read() job = json.loads(json_file) print(job) print("==========") job["folder"] = '\\temp\\CODESYS' # iterate over all tools of the project, and checkout all SVN repositories, # excluding the CODESYS folders if job != None: tools = get_json(base_url + '/' + job["project"]) 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_all(job['user'], job['pass'], url, os.path.join(job['folder'], repo)) for root, dirs, files in os.walk(job['folder']): for file in files: if file == "meta.profile": pysvn.svn_remove_local(root) print('\n') # store commit count details = get_json(base_url + tool['url']) f = open(os.path.join(job['folder'], repo + '.commit_count'), "w") if f: f.write(str(details['commit_count'])) f.close() # Exeucte all actions, passed to the job for action in job['actions']: if action['cmd'] == 'build': build.do(os.path.join(job['folder'], action['repo'])) if action['cmd'] == 'commit': commit.do(os.path.join(job['folder'], action['repo']), job["user"], job["pass"], action["msg"]) |