Created
June 3, 2014 23:26
-
-
Save luke10x/41b20f6aea042f4b2016 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 /usr/bin/python | |
import os, errno, shutil, sys | |
from pipes import quote | |
script_dir = os.path.realpath(os.path.dirname(__file__)) | |
output_dir = script_dir + "/outerr" | |
tmp_dir = script_dir + "/tmppppppp" | |
book_dir = os.path.realpath(sys.argv[1]) | |
book_name = os.path.basename(book_dir) | |
def mkdir_p(path): | |
try: | |
os.makedirs(path) | |
except OSError as exc: # Python >2.5 | |
if exc.errno == errno.EEXIST: | |
pass | |
else: raise | |
mkdir_p(output_dir) | |
mkdir_p(tmp_dir) | |
# delete everything from tmp directory | |
for the_file in os.listdir(tmp_dir): | |
file_path = os.path.join(tmp_dir, the_file) | |
try: | |
if os.path.isfile(file_path): | |
os.unlink(file_path) | |
else: | |
shutil.rmtree(file_path) | |
except Exception, e: | |
print e | |
print os.popen("cp %s/* %s" % (quote(book_dir), quote(tmp_dir))).read() | |
print os.popen("for z in %s/*.zip; do unzip -o $z -d %s; done " % | |
(quote(tmp_dir), quote(tmp_dir))).read() | |
print os.popen("cd %s " % ( quote(tmp_dir))).read() | |
wd = os.getcwd() | |
os.chdir(tmp_dir) | |
print os.popen("unrar -o+ x %s/*.rar " % ( quote(tmp_dir))).read() | |
print os.popen("cp %s/*.pdf %s/%s.pdf" % | |
(quote(tmp_dir), quote(output_dir), quote(book_name))).read() | |
print os.popen("notify-send -u low -t 1 'Extracted %s'" % ( quote(book_name))).read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment