Created
February 28, 2010 07:29
-
-
Save dekz/317469 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
#Check if rar files have been unrared, if so clean them up for space, if not unrared, do it and clean it | |
#requires unrar, use port or apt-get | |
import os | |
import sys | |
import subprocess | |
size = 0 | |
def morkon(path, list): | |
global size | |
directory=path | |
rarfound=False | |
checkfound=False | |
avicount=0 | |
rarfile="" | |
# for file in os.listdir(path): | |
if os.path.isdir(path): | |
#move in | |
for file in os.listdir(directory): | |
if os.path.isdir(os.path.join(directory, file)): | |
morkon(os.path.join(directory, file), checklist) | |
for listitem in list: | |
if file.find(listitem) >=0: | |
#print file | |
avicount += 1 | |
localsize = os.path.getsize(os.path.join(path,file)) | |
if localsize > 39321600: | |
checkfound = True | |
else: | |
print "SKIP" + file | |
if file.find(u".rar") >=0: | |
rarfound = True | |
rarfile = file | |
if (rarfound and checkfound): | |
removerar(directory, checklist) | |
if (rarfound and not checkfound): | |
# print "# " + directory | |
if rarfile: | |
filela = os.path.join(directory, rarfile) | |
# print "Unraring: " + filela | |
# subprocess.Popen(['unrar', 'e', filela]) | |
def removerar(path, list): | |
global size | |
if os.path.isdir(path): | |
for file in os.listdir(path): | |
if file.find(u".r") >=0: | |
for listitem in list: | |
if file.find(listitem): | |
break | |
try: | |
removeme = os.path.join(path, file) | |
size += os.path.getsize(removeme) | |
os.remove(removeme) | |
print "RMV: " + removeme | |
except: | |
print "FAIL: " + removeme | |
checklist = [u".avi", u".mkv", u".wmv"] | |
morkon(u'/Volumes/morbo/Downloads/complete/Movies/', checklist) | |
print size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment