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: |
Ray Milkey | 58915da | 2016-05-17 13:17:07 -0700 | [diff] [blame] | 14 | parts = mvnCoords.split(':') |
| 15 | if len(parts) > 3: |
| 16 | parts.insert(2, parts.pop()) # move version to the 3rd position |
| 17 | groupId, artifactId, version = parts[0:3] |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 18 | groupId = groupId.replace('.', '/') |
| 19 | extension = filename.split('.')[-1] |
| 20 | if extension == 'jar': |
| 21 | filename = '%s-%s.jar' % ( artifactId, version ) |
Brian O'Connor | e124f3d | 2016-04-06 23:54:26 -0700 | [diff] [blame] | 22 | elif 'features.xml' in filename: |
| 23 | filename = '%s-%s-features.xml' % ( artifactId, version ) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 24 | dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) |
Brian O'Connor | 1f16598 | 2016-04-06 21:36:09 -0700 | [diff] [blame] | 25 | zip.write(file, dest) |
| 26 | |
| 27 | if __name__ == '__main__': |
| 28 | import sys |
| 29 | |
| 30 | if len(sys.argv) < 2: |
| 31 | print 'USAGE' |
| 32 | sys.exit(1) |
| 33 | |
| 34 | output = sys.argv[1] |
| 35 | args = sys.argv[2:] |
| 36 | |
| 37 | if len(args) % 2 != 0: |
| 38 | print 'There must be an even number of args: file mvn_coords' |
| 39 | sys.exit(2) |
| 40 | |
| 41 | files = zip(*[iter(args)]*2) |
| 42 | generateOar(output, files) |