[Python-checkins] python/dist/src/PCbuild rmpyc.py,1.3,1.4
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Fri, 25 Apr 2003 17:53:26 -0700
Update of /cvsroot/python/python/dist/src/PCbuild
In directory sc8-pr-cvs1:/tmp/cvs-serv23729/python/PCbuild
Modified Files:
rmpyc.py
Log Message:
Use os.walk() to find files to delete.
Index: rmpyc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/PCbuild/rmpyc.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rmpyc.py 12 Jul 2001 22:36:02 -0000 1.3
--- rmpyc.py 26 Apr 2003 00:53:24 -0000 1.4
***************
*** 1,22 ****
# Remove all the .pyc and .pyo files under ../Lib.
def deltree(root):
import os
! def rm(path):
! os.unlink(path)
npyc = npyo = 0
! dirs = [root]
! while dirs:
! dir = dirs.pop()
! for short in os.listdir(dir):
! full = os.path.join(dir, short)
! if os.path.isdir(full):
! dirs.append(full)
! elif short.endswith(".pyc"):
npyc += 1
! rm(full)
! elif short.endswith(".pyo"):
npyo += 1
! rm(full)
return npyc, npyo
--- 1,23 ----
# Remove all the .pyc and .pyo files under ../Lib.
+
def deltree(root):
import os
! from os.path import join
!
npyc = npyo = 0
! for root, dirs, files in os.walk(root):
! for name in files:
! delete = False
! if name.endswith('.pyc'):
! delete = True
npyc += 1
! elif name.endswith('.pyo'):
! delete = True
npyo += 1
!
! if delete:
! os.remove(join(root, name))
!
return npyc, npyo