Chore: Add gerrit maven verify GHA workflow
[sdnc/oam.git] / installation / sdnc-web / src / main / scripts / opm.py
1 #!/usr/bin/python3
2 ###
3 # ============LICENSE_START=======================================================
4 # ONAP : ccsdk distribution web
5 # ================================================================================
6 # Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 # All rights reserved.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END=========================================================
21 ###
22
23 # opm = ODLUX package manager
24 # install odlux application inside of the container
25 # $1 install|uninstall
26 # $2 appName
27 # $3 zip file to add(extract)
28
29 import sys
30 from core import *
31
32
33
34
35 # install application
36 # $1 appName
37 # $2
38 # $2 zip file (optional)
39 def run_install(name, index=0, file=None):
40     if name is None:
41         error("no name given")
42     add_application(name, index, file)
43     update_index_html()
44
45
46 # install application from url
47 # $1 url
48 # $2 name (optional)
49 # $3 index (optional)
50 def run_install_from_url(url, name=None, index=0):
51     if url is None:
52         error("no url given")
53     print("installing from url...")
54     localFile = getRandomTempFile()
55     download(url,localFile)
56     if (name is None) or (index==0):
57         infos = autoDetectInfosFromJar(localFile)
58         if infos is not None:
59             if name is None:
60                 name = infos['name']
61             if index == 0:
62                 index = infos['index']
63     add_application(name,index,localFile)
64
65 # uninstall application
66 # $1 appName
67 def run_uninstall(name):
68     if name is None:
69         error("no name given")
70     apps = load_applications()
71     apps = [app for app in apps if app['name']!=name]
72     write_applications(apps)
73     update_index_html()
74     
75 def run_list(args):
76     apps = load_applications()
77     print('installed apps') 
78     for app in apps:
79         print('{} {}'.format(app['index'],app['name']))
80     
81 def print_help():
82     print("ODLUX package manager")
83     print("=====================")
84     print("usage:")
85     print(" opm.py install --name myApplication --index 23 --file app.zip")
86     print(" opm.py install --url https://link-to-my-odlux-application.jar")
87     print(" opm.py list")
88     print(" opm.py uninstall --name myApplication")
89
90 def error(msg):
91     print('ERROR: {}'.format(msg))
92     exit(1)
93
94 args = sys.argv
95 args.pop(0)
96 cmd = args.pop(0)
97 name=None
98 index=0
99 file=None
100 url=None
101 while(len(args)>0):
102     x=args.pop(0)
103     if x=='--name':
104         name=args.pop(0) if len(args)>0 else error("no name given")
105     elif x=='--index':
106         index=int(args.pop(0)) if len(args)>0 else error("no index given")
107     elif x=='--file':
108         file=args.pop(0) if len(args)>0 else error("no file given")
109     elif x=='--url':
110         url=args.pop(0) if len(args)>0 else error("no file given")
111     
112 print("command={} name={} index={} file={} url={}".format(cmd,name,index, file, url))
113        
114 if cmd=='install':
115     if url is not None:
116         run_install_from_url(url, name, index)
117     else:
118         run_install(name,index,file)
119 elif cmd=='uninstall':
120     run_uninstall(name)
121 elif cmd=='list':
122     run_list(args)
123 else:
124     print_help
125     exit(1)
126 exit(0)