Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15264

Re: leftover pyc files

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!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 <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.022
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; '"""': 0.07; 'python': 0.08; 'files:': 0.09; 'subject:files': 0.09; 'anyway': 0.09; 'def': 0.14; 'cc:addr:python-list': 0.15; 'os.walk': 0.16; 'suggestions?': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.23; 'cc:2**0': 0.25; 'code': 0.25; 'tree': 0.25; '(like': 0.25; 'skip:_ 20': 0.27; 'cc:addr:python.org': 0.29; 'print': 0.29; 'module': 0.30; 'recursively': 0.30; 'pm,': 0.31; 'skip:p 30': 0.31; 'cases': 0.32; 'does': 0.32; 'header:User-Agent:1': 0.33; 'done': 0.33; 'message-id:@gmail.com': 0.34; 'probably': 0.34; "we're": 0.34; 'stuck': 0.34; 'switch': 0.35; '(not': 0.37; 'received:google.com': 0.38; 'some': 0.38; 'move': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'files': 0.40; 'received:209': 0.40; 'more': 0.60; 'saw': 0.67; 'special': 0.67; 'from:addr:andrea.crotti.0': 0.84; 'from:name:andrea crotti': 0.84; 'otten': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=jZHkZzm56jXfW3nH0FdwD2mBvy8Vf1oHkrAibd0Z218=; b=n6gMwzazE1Idyf/11yIUiSWzRU63Wxc343MshFuQaIyq0A3+nSnqTNFWl28Tw8R4Es FxVyX81ecZW25ZYJB1rftSOBzjifAmaiaYI6NvMLrOCXwxylxGbk6doMsvjNwmOYG39m Xs2K2pLYuhfheLcLkHQAoncBMPSIyQmP/T4KI=
Date Wed, 02 Nov 2011 15:45:43 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1
MIME-Version 1.0
To Peter Otten <__peter__@web.de>
Subject Re: leftover pyc files
References <4EB14D9D.8080309@gmail.com> <j8rm4k$fvl$1@dough.gmane.org>
In-Reply-To <j8rm4k$fvl$1@dough.gmane.org>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2385.1320248748.27778.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1320248748 news.xs4all.nl 6904 [2001:888:2000:d::a6]:57985
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15264

Show key headers only | View raw


On 11/02/2011 03:03 PM, Peter Otten wrote:
> Switch to Python3.2 ;)

Yes I saw that and it would be great, unfortunately we're stuck with 
Python 2.5 :O
for some more time.

Anyway now the code that does it is a recursive thing ilke
def _clean_orphaned_pycs(self, directory, simulate=False):
     """Remove all the pyc files without a correspondent module
     """
     files = listdir(directory)
     # going down the tree recursively (like os.walk)
     for x in files:
         if x.endswith('.pyc'):
             py_file = x.split('.pyc')[0] + '.py'

             if (not simulate) and (py_file not in files):
                 deletable_pyc = path.join(directory, x)
                 print 'DELETING pyc %s as it has no py %s' % \
                     (deletable_pyc, py_file)
                 remove(deletable_pyc)

         #TODO: move out these special cases
         if path.isdir(path.join(directory, x)) \
             and x != '.svn' \
             and not x.endswith('.egg-info'):

             self._clean_orphaned_pycs(path.join(directory, x))


Can be done much better probably with os.walk or os.path.walk,
any suggestions?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: leftover pyc files Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-02 15:45 +0000
  Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-03 00:49 -0700
    Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-03 00:50 -0700
    Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-03 00:50 -0700
    Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-03 01:45 -0700
    Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-03 01:45 -0700
  Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-03 00:49 -0700
    Re: leftover pyc files Peter Otten <__peter__@web.de> - 2011-11-03 11:51 +0100
    Re: leftover pyc files Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-03 17:54 +0000
      Re: leftover pyc files Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-04 06:48 +0000
      Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-04 02:27 -0700
        Re: leftover pyc files Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-04 10:34 +0000
        Re: leftover pyc files Chris Angelico <rosuav@gmail.com> - 2011-11-04 21:39 +1100
          Re: leftover pyc files 88888 Dihedral <dihedral88888@googlemail.com> - 2011-11-04 06:31 -0700
          Re: leftover pyc files 88888 Dihedral <dihedral88888@googlemail.com> - 2011-11-04 06:31 -0700
        Re: leftover pyc files Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-04 11:00 +0000
        Re: leftover pyc files Terry Reedy <tjreedy@udel.edu> - 2011-11-04 16:01 -0400
          Re: leftover pyc files Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-04 23:15 +0000
      Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-04 02:27 -0700
        Re: leftover pyc files Jonathan Hartley <tartley@tartley.com> - 2011-11-04 02:29 -0700
    Re: leftover pyc files Chris Angelico <rosuav@gmail.com> - 2011-11-04 08:36 +1100
    Re: leftover pyc files David Robinow <drobinow@gmail.com> - 2011-11-03 20:14 -0400

csiph-web