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


Groups > comp.lang.python > #15264 > unrolled thread

Re: leftover pyc files

Started byAndrea Crotti <andrea.crotti.0@gmail.com>
First post2011-11-02 15:45 +0000
Last post2011-11-03 20:14 -0400
Articles 2 on this page of 22 — 8 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#15306

FromChris Angelico <rosuav@gmail.com>
Date2011-11-04 08:36 +1100
Message-ID<mailman.2413.1320356178.27778.python-list@python.org>
In reply to#15282
On Fri, Nov 4, 2011 at 4:54 AM, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
> All these ideas (shell and git hooks) are nice, but unfortunately
> - it's svn not git
> - it's windows not *nix
> - we have to remove only the ones without the corresponding *py...

Windows? Well, Windows shell scripting isn't quite as rich as
bash/csh/etc, but it's possible. I'll leave recursion as an exercise
for the reader, but this (untested) should do it for one directory:

for %d in (*.pyc) do (
set fn=%d
if not exist !fn:~0,-1! del %d
)

This needs to be run with 'cmd /v' to enable delayed variable
evaluation. Of course, it'd be really easy to do if Windows Batch had
anything like decent string manipulation.

ChrisA

[toc] | [prev] | [next] | [standalone]


#15315

FromDavid Robinow <drobinow@gmail.com>
Date2011-11-03 20:14 -0400
Message-ID<mailman.2421.1320365673.27778.python-list@python.org>
In reply to#15282
On Thu, Nov 3, 2011 at 1:54 PM, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
> All these ideas (shell and git hooks) are nice, but unfortunately
> - it's svn not git
> - it's windows not *nix
> - we have to remove only the ones without the corresponding *py...
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Barely tested. Change the print functions to removes. Pass the top
directory as the argument.

import os, sys
for dirpath, dirnames, filenames in os.walk(sys.argv[1]):
    if dirpath.endswith("__pycache__"):
        thispath = dirpath[:-11]
        for f in filenames:
            if f.endswith(".pyc"):
                if not os.path.exists(os.path.join(thispath,f[:-1])):
                    print("delete " + os.path.join(thispath,f))

    else:
        for f in filenames:
            if f.endswith(".pyc"):
                if not os.path.exists(os.path.join(dirpath,f[:-1])):
                    print("delete " + os.path.join(dirpath,f))
                    #os.remove(os.path.join(dirpath,f))

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web