[r12]: / trunk / cforge / cforge / Package / CFORGE / Scripts / install.py  Maximize  Restore  History

Download this file

63 lines (39 with data), 1.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
# imports 
import sys
import os

from System.Diagnostics import Process
from System.Net import WebClient




# 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 = [ 
	    ["<url_to_package>", "download and install a codesys package"],
	    ["<local path of package>", "install a local codesys package"]
    ]

    return help



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

# download 

workingdir = os.path.dirname(sys.argv[0])

downloaddir = os.path.join(workingdir, "downloads")
if not os.path.exists(downloaddir):
    os.makedirs(downloaddir)

url = str(sys.argv[1])

print(url)

localname = os.path.join(downloaddir, url.split("/")[-1].split("?")[0])
print(localname)

if not localname.endswith(".package"):
    print("no proper local filename found: " + localname)
    sys.exit()

print("downloading file...")
web_client = WebClient()
web_client.DownloadFile(url, localname)
print("downloading done!")

# and install local package now:
Process.Start(localname)