Created
August 15, 2012 23:17
-
-
Save masnun/3364613 to your computer and use it in GitHub Desktop.
Remove .pyc files recursively (shell command + django manage.py plugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: <appname>/management/commands/rmpyc.py | |
# management and commands directories must be python packages (each must have a __init__.py file) | |
from django.core.management.base import BaseCommand, CommandError | |
from subprocess import Popen, STDOUT, PIPE | |
import shlex, os | |
class Command(BaseCommand): | |
def handle(self, *args, **options): | |
#Cleanup the *.pyc files using *nix shell | |
# Doesn't and shouldn't work on non-*nix systems | |
os.system("rm `find . -type f -name '*.pyc'`") | |
#Find pyc files to test outcomes of the command | |
cmd = "find . -type f -name '*.pyc'" | |
args = shlex.split(cmd) | |
files = Popen(args, stderr=STDOUT, stdout=PIPE).communicate()[0].split("\n") | |
if len(files) < 2: | |
self.stdout.write('All *pyc files were succesfully cleaned up! \n') | |
else: | |
self.stdout.write('Whoops! Something went wrong! \n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm `find . -type f -name "*.pyc"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment