Brian O'Connor | 0167bd4 | 2016-04-29 17:09:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | #FIXME Add license |
| 3 | |
| 4 | import re |
| 5 | from zipfile import ZipFile |
| 6 | |
| 7 | def stageOnos(output, files=[]): |
| 8 | # Note this is not a compressed zip |
| 9 | with ZipFile(output, 'a') as output: |
| 10 | written_files = set(output.namelist()) |
| 11 | for file in files: |
| 12 | if '.zip' in file: |
| 13 | with ZipFile(file, 'r') as zip_part: |
| 14 | for f in zip_part.namelist(): |
| 15 | dest = 'apache-karaf-3.0.5/system/' + f |
| 16 | if dest not in written_files: |
| 17 | output.writestr(dest, zip_part.open(f).read()) |
| 18 | written_files.add(dest) |
| 19 | elif '.oar' in file: |
| 20 | with ZipFile(file, 'r') as oar: |
| 21 | app_xml = oar.open('app.xml').read() |
| 22 | app_name = re.search('name="([^"]+)"', app_xml).group(1) |
| 23 | dest = 'apps/%(name)s/%(name)s.oar' % { 'name': app_name} |
| 24 | output.write(file, dest) |
| 25 | dest = 'apps/%s/app.xml' % app_name |
| 26 | output.writestr(dest, app_xml) |
| 27 | for f in oar.namelist(): |
| 28 | if 'm2' in f: |
| 29 | dest = 'apache-karaf-3.0.5/system/' + f[3:] |
| 30 | if dest not in written_files: |
| 31 | output.writestr(dest, oar.open(f).read()) |
| 32 | written_files.add(dest) |
| 33 | elif 'features.xml' in file: |
| 34 | dest = 'apache-karaf-3.0.5/system/org/onosproject/onos-features/1.6.0-SNAPSHOT/' |
| 35 | dest += 'onos-features-1.6.0-SNAPSHOT-features.xml' |
| 36 | with open(file) as f: |
| 37 | output.writestr(dest, f.read()) |
| 38 | # filename = file.split('/')[-1] |
| 39 | # if mvnCoords == 'APP': |
| 40 | # dest = filename |
| 41 | # else: |
| 42 | # groupId, artifactId, version = mvnCoords.split(':') |
| 43 | # groupId = groupId.replace('.', '/') |
| 44 | # extension = filename.split('.')[-1] |
| 45 | # if extension == 'jar': |
| 46 | # filename = '%s-%s.jar' % ( artifactId, version ) |
| 47 | # elif 'features.xml' in filename: |
| 48 | # filename = '%s-%s-features.xml' % ( artifactId, version ) |
| 49 | # dest = 'system/%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) |
| 50 | # zip.write(file, dest) |
| 51 | output.writestr('apps/org.onosproject.drivers/active', '') |
| 52 | output.writestr('apps/org.onosproject.openflow-base/active', '') |
| 53 | output.writestr('apps/org.onosproject.lldp/active', '') |
| 54 | output.writestr('apps/org.onosproject.host/active', '') |
| 55 | |
| 56 | if __name__ == '__main__': |
| 57 | import sys |
| 58 | |
| 59 | if len(sys.argv) < 2: |
| 60 | print 'USAGE' |
| 61 | sys.exit(1) |
| 62 | |
| 63 | output = sys.argv[1] |
| 64 | args = sys.argv[2:] |
| 65 | |
| 66 | # if len(args) % 2 != 0: |
| 67 | # print 'There must be an even number of args: file mvn_coords' |
| 68 | # sys.exit(2) |
| 69 | |
| 70 | #files = zip(*[iter(args)]*2) |
| 71 | stageOnos(output, args) |