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