Source

sage-geom / spkg-delauto

#!/usr/bin/env python

import os, sys

if len(sys.argv) != 2:
    print "%s <directory name>"%sys.argv[0]
    print "Delete Cython autogenerated files in the given directory and"
    print "all subdirectories of the given directory."
    sys.exit(1)

os.system('rm c_lib/*.so')
os.system('rm c_lib/*.os')

def del_all(dir):
    for f in os.listdir(dir):
        filename = '%s/%s'%(dir,f)
        if filename.endswith('.png'):
            print "Deleting temporary image %s"%filename
            os.unlink(filename)
            continue
        if os.path.isdir(filename):
            del_all(filename)
        if filename.endswith('.c') or filename.endswith('.cpp'):
            r = open(filename).readline()
            if '/* Generated by ' in r:
                print "Deleting autogenerated file %s"%filename
                os.unlink(filename)



del_all(sys.argv[1])