SimpleCode
very useful if one intends to share code
http://www.simplebits.com/cgi-bin/simplecode.pl?mode=process
very useful if one intends to share code
Quite frequently i found myself struggling with extracting files that i download from iptorrents.com . The download data is organized in multiple rar files which i hate to extract manually. Here is how it is typically arrange for TV series.
import getopt, sys, os, fnmatch, subprocess
def usage():
usage = """
-h --help Prints this
-p --path (PATH to the fir which needs to be unrar'ed)
-v verbose
"""
print usage
def unrar():
if os.path.exists(__path) == False:
print "Path doesn't exist: %s" % __path
sys.exit(1)
for dirs in os.listdir(__path):
if os.path.isdir(os.path.join(__path, dirs)) == True:
for files in os.listdir(os.path.join(__path, dirs)):
if fnmatch.fnmatch(files, '*.r00'):
myarg = os.path.join(__path, dirs)+ "/" +files
print myarg
try:
retcode = subprocess.Popen(["unrar", "x", myarg, __path])
if retcode <>>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hp:v", ["help", "path="])
except getopt.GetoptError:
print str(err)
usage()
sys.exit(2)
global __path
verbose = False
for options, arg in opts:
if options == "-v":
verbose = True
elif options == "-h":
usage()
sys.exit()
elif options in ("-p", "--path"):
__path = arg
else:
assert False, "unhandled option"
__path = ""
if __name__ == "__main__":
main()
unrar()
This spawns multiple processes each unraring each one of the r00 [disclaimer it could slow down you system but then given the fact that your are reading this time is not of much importance to you]. Invoke it giving the season's dir path