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