1#! /usr/bin/env python 2#************************************************************************* 3# 4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5# 6# Copyright 2000, 2010 Oracle and/or its affiliates. 7# 8# OpenOffice.org - a multi-platform office productivity suite 9# 10# This file is part of OpenOffice.org. 11# 12# OpenOffice.org is free software: you can redistribute it and/or modify 13# it under the terms of the GNU Lesser General Public License version 3 14# only, as published by the Free Software Foundation. 15# 16# OpenOffice.org is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU Lesser General Public License version 3 for more details 20# (a copy is included in the LICENSE file that accompanied this code). 21# 22# You should have received a copy of the GNU Lesser General Public License 23# version 3 along with OpenOffice.org. If not, see 24# <http://www.openoffice.org/license.html> 25# for a copy of the LGPLv3 License. 26# 27#************************************************************************* 28import os, os.path, sys, zipfile 29 30def paths_to_pack(loglines): 31 """Returns a generator iterating the outdir fields (with platform) of gb_deliver.log lines.""" 32 lines=[] 33 for line in loglines: 34 fields = line.split() 35 if len(fields) >= 3: 36 lines.append(fields[2]) 37 return lines 38 39def stripped_paths_to_pack(loglines): 40 """returns a generator iterating the outdir fields (stripped of the platform) of gb_deliver.log lines.""" 41 return (path.partition('/')[2] for path in paths_to_pack(loglines)) 42 43def main(args): 44 """creates/overwrites a file at OUTDIR/zip/MODULE.zip containing the contents of the gb_deliver.log.""" 45 if len(args) != 3: 46 print('usage: packmodule OUTDIR MODULE') 47 sys.exit(2) 48 (executable, outdir, module) = args 49 os.chdir(outdir) 50 zipdir = 'zip' 51 try: 52 os.makedirs(zipdir) 53 except OSError: 54 pass 55 deliverlog = open(os.path.join('inc', module, 'gb_deliver.log')) 56 packedmodule = zipfile.ZipFile(os.path.join(zipdir,module+'.zip'), 'w') 57 [packedmodule.write(path) for path in stripped_paths_to_pack(deliverlog)] 58 packedmodule.write(os.path.join('inc', module, 'gb_deliver.log')) 59 packedmodule.close() 60 61if __name__ == "__main__": 62 main(sys.argv) 63 64# vim:set et sw=4 ts=4 filetype=python: 65