Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | #FIXME Add license |
| 3 | |
| 4 | from zipfile import ZipFile |
| 5 | |
| 6 | def 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 ) |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 19 | elif 'features.xml' in filename: |
| 20 | filename = '%s-%s-features.xml' % ( artifactId, version ) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 21 | dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 22 | zip.write(file, dest) |
| 23 | |
| 24 | if __name__ == '__main__': |
| 25 | import sys |
| 26 | |
| 27 | if len(sys.argv) < 2: |
| 28 | print 'USAGE' |
| 29 | sys.exit(1) |
| 30 | |
| 31 | output = sys.argv[1] |
| 32 | args = sys.argv[2:] |
| 33 | |
| 34 | if len(args) % 2 != 0: |
| 35 | print 'There must be an even number of args: file mvn_coords' |
| 36 | sys.exit(2) |
| 37 | |
| 38 | files = zip(*[iter(args)]*2) |
| 39 | generateOar(output, files) |