blob: 99fd498ce196cc73c84d019a24e51dda384f06ef [file] [log] [blame]
Brian O'Connor1f165982016-04-06 21:36:09 -07001#!/usr/bin/env python
2#FIXME Add license
3
4from zipfile import ZipFile
5
6def generateOar(output, files=[]):
7 # Note this is not a compressed zip
8 with ZipFile(output, 'w') as zip:
9 for file, mvnCoords in files:
10 filename = file.split('/')[-1]
11 if mvnCoords == 'NONE':
12 dest = filename
13 else:
14 groupId, artifactId, version = mvnCoords.split(':')
15 groupId = groupId.replace('.', '/')
16 extension = filename.split('.')[-1]
17 if extension == 'jar':
18 filename = '%s-%s.jar' % ( artifactId, version )
19 dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
20 print file, '->', dest
21 zip.write(file, dest)
22
23if __name__ == '__main__':
24 import sys
25
26 if len(sys.argv) < 2:
27 print 'USAGE'
28 sys.exit(1)
29
30 output = sys.argv[1]
31 args = sys.argv[2:]
32
33 if len(args) % 2 != 0:
34 print 'There must be an even number of args: file mvn_coords'
35 sys.exit(2)
36
37 files = zip(*[iter(args)]*2)
38 generateOar(output, files)