blob: 5aa77a066ab256c4a619a2135b6ff2e8bfc8010e [file] [log] [blame]
pierventre69db90c2022-05-06 23:06:20 +02001#!/usr/bin/env python3
Thomas Vachuska8e022a92018-07-10 14:47:38 -07002"""
3 Copyright 2018-present Open Networking Foundation
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16"""
Ray Milkeyad83ef92018-06-05 11:05:51 -070017
Ray Milkey1ccab712018-06-12 16:30:02 -070018from zipfile import ZipFile, ZipInfo
Thomas Vachuska8e022a92018-07-10 14:47:38 -070019
20# Utility to write out the ONOS OAR file bundle containing the artifacts
21# required to install and activate an ONOS application.
Ray Milkeyad83ef92018-06-05 11:05:51 -070022
23def generateOar(output, files=[]):
Ray Milkeyad83ef92018-06-05 11:05:51 -070024 with ZipFile(output, 'w') as zip:
25 for file, mvnCoords in files:
Ray Milkey1ccab712018-06-12 16:30:02 -070026 mvnCoords = mvnCoords.replace("mvn:", "")
Ray Milkeyad83ef92018-06-05 11:05:51 -070027 filename = file.split('/')[-1]
28 if mvnCoords == 'NONE':
Ray Milkey1d52ddd2018-06-07 10:37:24 -070029 if 'app-xml.xml' in filename:
30 dest = 'app.xml'
31 else:
32 dest = filename
Ray Milkeyad83ef92018-06-05 11:05:51 -070033 else:
34 parts = mvnCoords.split(':')
35 if len(parts) > 3:
36 parts.insert(2, parts.pop()) # move version to the 3rd position
37 groupId, artifactId, version = parts[0:3]
38 groupId = groupId.replace('.', '/')
39 extension = filename.split('.')[-1]
40 if extension == 'jar':
41 filename = '%s-%s.jar' % ( artifactId, version )
Ray Milkey1d52ddd2018-06-07 10:37:24 -070042 elif 'feature-xml' in filename:
Ray Milkeyad83ef92018-06-05 11:05:51 -070043 filename = '%s-%s-features.xml' % ( artifactId, version )
44 dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
Ray Milkey1ccab712018-06-12 16:30:02 -070045 f = open(file, 'rb')
46 zip.writestr(ZipInfo(dest, date_time=(1980, 1, 1, 0, 0, 0)), f.read())
47 f.close()
Ray Milkeyad83ef92018-06-05 11:05:51 -070048
49if __name__ == '__main__':
50 import sys
51
52 if len(sys.argv) < 2:
Laszlo Papp066fe4a2018-09-05 13:21:27 +010053 print('USAGE')
Ray Milkeyad83ef92018-06-05 11:05:51 -070054 sys.exit(1)
55
56 output = sys.argv[1]
57 args = sys.argv[2:]
58
59 if len(args) % 2 != 0:
Laszlo Papp066fe4a2018-09-05 13:21:27 +010060 print('There must be an even number of args: file mvn_coords')
Ray Milkeyad83ef92018-06-05 11:05:51 -070061 sys.exit(2)
62
pierventre69db90c2022-05-06 23:06:20 +020063 files = list(zip(*[iter(args)]*2))
Ray Milkeyad83ef92018-06-05 11:05:51 -070064 generateOar(output, files)