Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; '"""': 0.05; '%s"': 0.07; 'cleanup': 0.07; "'-'": 0.09; 'cmd': 0.09; 'err:': 0.09; 'fname': 0.09; 'output,': 0.09; 'subject:files': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'anyway': 0.11; '%s,': 0.16; '(output': 0.16; 'cc:name:python list': 0.16; 'downside': 0.16; 'err': 0.16; 'meanwhile': 0.16; 'out)': 0.16; 'proc': 0.16; 'bytes': 0.17; 'skip:{ 20': 0.17; 'received:209.85.214.174': 0.21; 'split': 0.23; 'cc:2**1': 0.24; 'command': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'implemented': 0.27; 'message-id:@mail.gmail.com': 0.27; 'faster,': 0.29; 'subject:size': 0.29; 'tar': 0.29; 'probably': 0.29; 'error': 0.30; 'file': 0.32; 'running': 0.32; 'received:google.com': 0.34; 'false': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'skip:{ 10': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:l 20': 0.38; 'received:209.85.214': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'containing': 0.61; 'first': 0.61; 'below.': 0.68; 'subject:limited': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0/EJB9fNI2n6SC8/puLEnuXytznBSA0+vNMk2CFvorY=; b=vMptLVTCGiCP5SYi1bnuyd9U302rgwOglxrvxe4Hj6KI9zbBwE+WpRbhu9P8F7ztkR u4I/2ZGlpfrNwZYeRqcOhrEMGvqHWQqLCwk5k6MZTI25dOiUoxx3x1s3vZ+1NaJGvXLk 1a6R3zxGOXWK6tMicyz/GByMqaygXd77QJ2vDEilgwTn+YEOobeoBlZiGATU+orFScS6 PFbIx5XcN75SRBJCP3Dy9GllZMhLXr4S/Em2/Bv+WfxoDQ2WqACoN4mZQ416fD9yXm85 JEydC4JWeqcVfGeiYGlxWPji7RoWiFeMx6wVYhpmVzNCPvOT69H1heZUmTBoOGyOmrGQ O2nA== MIME-Version: 1.0 In-Reply-To: References: <509ab0fa$0$6636$9b4e6d93@newsspool2.arcor-online.net> <509AD812.2060605@gmail.com> Date: Fri, 9 Nov 2012 10:39:21 +0000 Subject: Re: creating size-limited tar files From: andrea crotti To: Oscar Benjamin Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List , Roy Smith X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352457564 news.xs4all.nl 6928 [2001:888:2000:d::a6]:35052 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33009 Anyway in the meanwhile I implemented this tar and split in this way below. It works very well and it's probably much faster, but the downside is that I give away control to tar and split.. def tar_and_split(inputfile, output, bytes_size=None): """Take the file containing all the files to compress, the bytes desired for the split and the base name of the output file """ # cleanup first for fname in glob(output + "*"): logger.debug("Removing old file %s" % fname) remove(fname) out = '-' if bytes_size else (output + '.tar.gz') cmd = "tar czpf {} $(cat {})".format(out, inputfile) if bytes_size: cmd += "| split -b {} -d - {}".format(bytes_size, output) logger.info("Running command %s" % cmd) proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if err: logger.error("Got error messages %s" % err) logger.info("Output %s" % out) if proc.returncode != 0: logger.error("Something failed running %s, need to re-run" % cmd) return False