xref: /aoo41x/main/solenv/bin/packmodule (revision e76eebc6)
1cdf0e10cSrcweir#! /usr/bin/env python
2*e76eebc6SAndrew Rist#**************************************************************
3*e76eebc6SAndrew Rist#
4*e76eebc6SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5*e76eebc6SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6*e76eebc6SAndrew Rist#  distributed with this work for additional information
7*e76eebc6SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8*e76eebc6SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9*e76eebc6SAndrew Rist#  "License"); you may not use this file except in compliance
10*e76eebc6SAndrew Rist#  with the License.  You may obtain a copy of the License at
11*e76eebc6SAndrew Rist#
12*e76eebc6SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13*e76eebc6SAndrew Rist#
14*e76eebc6SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15*e76eebc6SAndrew Rist#  software distributed under the License is distributed on an
16*e76eebc6SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*e76eebc6SAndrew Rist#  KIND, either express or implied.  See the License for the
18*e76eebc6SAndrew Rist#  specific language governing permissions and limitations
19*e76eebc6SAndrew Rist#  under the License.
20*e76eebc6SAndrew Rist#
21*e76eebc6SAndrew Rist#**************************************************************
22cdf0e10cSrcweirimport os, os.path, sys, zipfile
23cdf0e10cSrcweir
24cdf0e10cSrcweirdef paths_to_pack(loglines):
25cdf0e10cSrcweir    """Returns a generator iterating the outdir fields (with platform) of gb_deliver.log lines."""
26cdf0e10cSrcweir    lines=[]
27cdf0e10cSrcweir    for line in loglines:
28cdf0e10cSrcweir        fields = line.split()
29cdf0e10cSrcweir        if len(fields) >= 3:
30cdf0e10cSrcweir            lines.append(fields[2])
31cdf0e10cSrcweir    return lines
32cdf0e10cSrcweir
33cdf0e10cSrcweirdef stripped_paths_to_pack(loglines):
34cdf0e10cSrcweir    """returns a generator iterating the outdir fields (stripped of the platform) of gb_deliver.log lines."""
35cdf0e10cSrcweir    return (path.partition('/')[2] for path in paths_to_pack(loglines))
36cdf0e10cSrcweir
37cdf0e10cSrcweirdef main(args):
38cdf0e10cSrcweir    """creates/overwrites a file at OUTDIR/zip/MODULE.zip containing the contents of the gb_deliver.log."""
39cdf0e10cSrcweir    if len(args) != 3:
40cdf0e10cSrcweir        print('usage: packmodule OUTDIR MODULE')
41cdf0e10cSrcweir        sys.exit(2)
42cdf0e10cSrcweir    (executable, outdir, module) = args
43cdf0e10cSrcweir    os.chdir(outdir)
44cdf0e10cSrcweir    zipdir = 'zip'
45cdf0e10cSrcweir    try:
46cdf0e10cSrcweir        os.makedirs(zipdir)
47cdf0e10cSrcweir    except OSError:
48cdf0e10cSrcweir        pass
49cdf0e10cSrcweir    deliverlog = open(os.path.join('inc', module, 'gb_deliver.log'))
50cdf0e10cSrcweir    packedmodule = zipfile.ZipFile(os.path.join(zipdir,module+'.zip'), 'w')
51cdf0e10cSrcweir    [packedmodule.write(path) for path in stripped_paths_to_pack(deliverlog)]
52cdf0e10cSrcweir    packedmodule.write(os.path.join('inc', module, 'gb_deliver.log'))
53cdf0e10cSrcweir    packedmodule.close()
54cdf0e10cSrcweir
55cdf0e10cSrcweirif __name__ == "__main__":
56cdf0e10cSrcweir    main(sys.argv)
57cdf0e10cSrcweir
58cdf0e10cSrcweir# vim:set et sw=4 ts=4 filetype=python:
59