Adding onos_stage.py and onos_feature.py for feature generation and onos-package
Change-Id: I67cb1ec9c09a194c41707ff55121dcdc54e3e4ea
Showing
3 changed files
with
126 additions
and
0 deletions
... | @@ -19,6 +19,19 @@ python_binary( | ... | @@ -19,6 +19,19 @@ python_binary( |
19 | visibility = ['PUBLIC'], | 19 | visibility = ['PUBLIC'], |
20 | ) | 20 | ) |
21 | 21 | ||
22 | +python_binary( | ||
23 | + name = 'onos-stage', | ||
24 | + main = 'onos_stage.py', | ||
25 | + deps = [], | ||
26 | + visibility = ['PUBLIC'], | ||
27 | +) | ||
28 | + | ||
29 | +python_binary( | ||
30 | + name = 'onos-feature', | ||
31 | + main = 'onos_feature.py', | ||
32 | + deps = [], | ||
33 | + visibility = ['PUBLIC'], | ||
34 | +) | ||
22 | 35 | ||
23 | python_binary( | 36 | python_binary( |
24 | name = 'pack_war', | 37 | name = 'pack_war', | ... | ... |
buck-tools/onos_feature.py
0 → 100755
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 | + 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] | ||
18 | + groupId = groupId.replace('.', '/') | ||
19 | + extension = filename.split('.')[-1] | ||
20 | + if extension == 'jar': | ||
21 | + filename = '%s-%s.jar' % ( artifactId, version ) | ||
22 | + elif 'features.xml' in filename: | ||
23 | + filename = '%s-%s-features.xml' % ( artifactId, version ) | ||
24 | + dest = '%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) | ||
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) |
buck-tools/onos_stage.py
0 → 100755
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) |
-
Please register or login to post a comment