This commit is contained in:
Kovid Goyal 2012-05-03 19:26:04 +05:30
parent 364d1dca55
commit ecd4d6ddea
2 changed files with 23 additions and 14 deletions

View File

@ -59,9 +59,7 @@ Run an embedded python interpreter.
'files and metadata, which you can edit using standard HTML ' 'files and metadata, which you can edit using standard HTML '
'editing tools, and then rebuilds the file from the edited HTML. ' 'editing tools, and then rebuilds the file from the edited HTML. '
'Makes no additional changes to the HTML, unlike a full calibre ' 'Makes no additional changes to the HTML, unlike a full calibre '
'conversion). Note that this tool will try to open the ' 'conversion).')
'folder containing the HTML files in the editor pointed to by the'
' EDITOR environment variable.')
parser.add_option('--test-build', help='Test binary modules in build', parser.add_option('--test-build', help='Test binary modules in build',
action='store_true', default=False) action='store_true', default=False)

View File

@ -7,11 +7,11 @@ __license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import sys, os, shlex, subprocess import sys, os, shlex, subprocess, shutil
from calibre import prints, as_unicode, walk from calibre import prints, as_unicode, walk
from calibre.constants import iswindows, __appname__ from calibre.constants import iswindows, __appname__
from calibre.ptempfile import TemporaryDirectory from calibre.ptempfile import TemporaryDirectory, TemporaryFile
from calibre.libunzip import extract as zipextract from calibre.libunzip import extract as zipextract
from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZIP_STORED from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZIP_STORED
from calibre.utils.ipc.simple_worker import WorkerError from calibre.utils.ipc.simple_worker import WorkerError
@ -108,21 +108,32 @@ def tweak(ebook_file):
# The question was answered with No # The question was answered with No
return return
ed = os.environ.get('EDITOR', None) ed = os.environ.get('EDITOR', 'dummy')
cmd = shlex.split(ed)
isvim = bool([x for x in cmd[0].split('/') if x.endswith('vim')])
proceed = False proceed = False
if ed is None:
prints('Book extracted to', tdir) prints('Book extracted to', tdir)
if not isvim:
prints('Make your tweaks and once you are done,', __appname__, prints('Make your tweaks and once you are done,', __appname__,
'will rebuild', ebook_file, 'from', tdir) 'will rebuild', ebook_file, 'from', tdir)
print() print()
proceed = ask_cli_question('Rebuild ' + ebook_file + '?') proceed = ask_cli_question('Rebuild ' + ebook_file + '?')
else: else:
cmd = shlex.split(ed) base = os.path.basename(ebook_file)
with TemporaryFile(base+'.zip') as zipf:
with ZipFile(zipf, 'w') as zf:
zf.add_dir(tdir)
try: try:
subprocess.check_call(cmd + [tdir]) subprocess.check_call(cmd + [zipf])
except: except:
prints(ed, 'failed, aborting...') prints(ed, 'failed, aborting...')
raise SystemExit(1) raise SystemExit(1)
with ZipFile(zipf, 'r') as zf:
shutil.rmtree(tdir)
os.mkdir(tdir)
zf.extractall(path=tdir)
proceed = True proceed = True
if proceed: if proceed: