blob: afac6716a2040d4f065c716ffa83b69fc05191c3 [file] [log] [blame]
Ray Milkeyad83ef92018-06-05 11:05:51 -07001#!/usr/bin/env python
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:
53 print 'USAGE'
54 sys.exit(1)
55
56 output = sys.argv[1]
57 args = sys.argv[2:]
58
59 if len(args) % 2 != 0:
60 print 'There must be an even number of args: file mvn_coords'
61 sys.exit(2)
62
63 files = zip(*[iter(args)]*2)
64 generateOar(output, files)