mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
rtf2lrf
This commit is contained in:
parent
3e9119e0e5
commit
2a779db7bd
@ -194,6 +194,9 @@ _check_symlinks_prescript()
|
||||
print 'Adding clit'
|
||||
os.link(os.path.expanduser('~/clit'), os.path.join(frameworks_dir, 'clit'))
|
||||
print
|
||||
print 'Adding unrtf'
|
||||
os.link(os.path.expanduser('~/unrtf'), os.path.join(frameworks_dir, 'unrtf'))
|
||||
print
|
||||
print 'Installing prescipt'
|
||||
sf = [os.path.basename(s) for s in all_names]
|
||||
cs = BuildAPP.CHECK_SYMLINKS_PRESCRIPT % dict(dest_path=repr('/usr/bin'),
|
||||
|
1
setup.py
1
setup.py
@ -27,6 +27,7 @@ entry_points = {
|
||||
'html2lrf = libprs500.ebooks.lrf.html.convert_from:main',\
|
||||
'markdown = libprs500.ebooks.markdown.markdown:main',\
|
||||
'lit2lrf = libprs500.ebooks.lrf.lit.convert_from:main',\
|
||||
'rtf2lrf = libprs500.ebooks.lrf.rtf.convert_from:main',\
|
||||
],
|
||||
'gui_scripts' : [ APPNAME+' = libprs500.gui.main:main']
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
''' E-book management software'''
|
||||
__version__ = "0.3.63"
|
||||
__version__ = "0.3.64"
|
||||
__docformat__ = "epytext"
|
||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||
__appname__ = 'libprs500'
|
||||
|
@ -17,3 +17,6 @@
|
||||
Code for the conversion of ebook formats and the reading of metadata
|
||||
from various formats.
|
||||
'''
|
||||
|
||||
class ConversionError(Exception):
|
||||
pass
|
||||
|
@ -25,6 +25,7 @@ from libprs500.ebooks.lrf.pylrs.pylrs import Book as _Book
|
||||
from libprs500.ebooks.lrf.pylrs.pylrs import TextBlock, Header, PutObj, \
|
||||
Paragraph, TextStyle, BlockStyle
|
||||
from libprs500.ebooks.lrf.fonts import FONT_FILE_MAP
|
||||
from libprs500.ebooks import ConversionError
|
||||
from libprs500 import __version__ as VERSION
|
||||
from libprs500 import iswindows
|
||||
|
||||
@ -67,9 +68,6 @@ def font_family(option, opt_str, value, parser):
|
||||
setattr(parser.values, option.dest, tuple())
|
||||
|
||||
|
||||
class ConversionError(Exception):
|
||||
pass
|
||||
|
||||
def option_parser(usage):
|
||||
parser = OptionParser(usage=usage, version='libprs500 '+VERSION,
|
||||
epilog='Created by Kovid Goyal')
|
||||
|
@ -38,7 +38,8 @@ from libprs500.ebooks.lrf.pylrs.pylrs import Paragraph, CR, Italic, ImageStream,
|
||||
TextBlock, ImageBlock, JumpButton, CharButton, Bold, Space, \
|
||||
Plot, Image, BlockSpace, RuledLine, BookSetting, Canvas
|
||||
from libprs500.ebooks.lrf.pylrs.pylrs import Span as _Span
|
||||
from libprs500.ebooks.lrf import ConversionError, option_parser, Book, PRS500_PROFILE
|
||||
from libprs500.ebooks.lrf import option_parser, Book, PRS500_PROFILE
|
||||
from libprs500.ebooks import ConversionError
|
||||
from libprs500.ebooks.lrf.html.table import Table
|
||||
from libprs500 import extract, filename_to_utf8
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
|
@ -15,7 +15,8 @@
|
||||
import os, sys, shutil, glob
|
||||
from tempfile import mkdtemp
|
||||
from subprocess import Popen, PIPE
|
||||
from libprs500.ebooks.lrf import option_parser, ConversionError
|
||||
from libprs500.ebooks.lrf import option_parser
|
||||
from libprs500.ebooks import ConversionError
|
||||
from libprs500.ebooks.lrf.html.convert_from import parse_options as html_parse_options
|
||||
from libprs500.ebooks.lrf.html.convert_from import process_file
|
||||
from libprs500 import isosx
|
||||
|
14
src/libprs500/ebooks/lrf/rtf/__init__.py
Normal file
14
src/libprs500/ebooks/lrf/rtf/__init__.py
Normal file
@ -0,0 +1,14 @@
|
||||
## Copyright (C) 2007 Kovid Goyal kovid@kovidgoyal.net
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
115
src/libprs500/ebooks/lrf/rtf/convert_from.py
Normal file
115
src/libprs500/ebooks/lrf/rtf/convert_from.py
Normal file
@ -0,0 +1,115 @@
|
||||
## Copyright (C) 2007 Kovid Goyal kovid@kovidgoyal.net
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
import os, sys, tempfile, subprocess, shutil
|
||||
|
||||
from libprs500.ebooks.lrf import option_parser
|
||||
from libprs500.ebooks.metadata.meta import get_metadata
|
||||
from libprs500.ebooks.lrf.html.convert_from import parse_options as html_parse_options
|
||||
from libprs500.ebooks.lrf.html.convert_from import process_file
|
||||
from libprs500.ebooks import ConversionError
|
||||
from libprs500 import isosx
|
||||
|
||||
UNRTF = 'unrtf'
|
||||
if isosx and hasattr(sys, 'frameworks_dir'):
|
||||
UNRTF = os.path.join(sys.frameworks_dir, UNRTF)
|
||||
|
||||
def parse_options(cli=True):
|
||||
""" CLI for rtf -> lrf conversions """
|
||||
parser = option_parser(
|
||||
"""usage: %prog [options] mybook.rtf
|
||||
|
||||
%prog converts mybook.rtf to mybook.lrf
|
||||
"""
|
||||
)
|
||||
options, args = parser.parse_args()
|
||||
if len(args) != 1:
|
||||
if cli:
|
||||
parser.print_help()
|
||||
raise ConversionError, 'no filename specified'
|
||||
return options, args, parser
|
||||
|
||||
def generate_html(rtfpath):
|
||||
tdir = tempfile.mkdtemp(prefix='rtf2lrf_')
|
||||
cwd = os.path.abspath(os.getcwd())
|
||||
os.chdir(tdir)
|
||||
try:
|
||||
print 'Converting to HTML...',
|
||||
sys.stdout.flush()
|
||||
handle, path = tempfile.mkstemp(dir=tdir, suffix='.html')
|
||||
file = os.fdopen(handle, 'wb')
|
||||
cmd = ' '.join([UNRTF, '"'+rtfpath+'"'])
|
||||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
||||
file.write(p.stdout.read())
|
||||
file.close()
|
||||
ret = p.wait()
|
||||
if ret != 0:
|
||||
raise ConversionError, 'unrtf failed with error code: %d'%(ret,)
|
||||
print 'done'
|
||||
return path
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
def main():
|
||||
try:
|
||||
options, args, parser = parse_options()
|
||||
rtf = os.path.abspath(os.path.expanduser(args[0]))
|
||||
f = open(rtf, 'rb')
|
||||
mi = get_metadata(f, 'rtf')
|
||||
f.close()
|
||||
html = generate_html(rtf)
|
||||
tdir = os.path.dirname(html)
|
||||
try:
|
||||
for i in range(len(sys.argv)):
|
||||
if sys.argv[i] == args[0]:
|
||||
sys.argv[i] = html
|
||||
o_spec = False
|
||||
for arg in sys.argv[1:]:
|
||||
arg = arg.lstrip()
|
||||
if arg.startswith('-o') or arg.startswith('--output'):
|
||||
o_spec = True
|
||||
break
|
||||
ext = '.lrf'
|
||||
for arg in sys.argv[1:]:
|
||||
if arg.strip() == '--lrs':
|
||||
ext = '.lrs'
|
||||
break
|
||||
if not o_spec:
|
||||
sys.argv.append('-o')
|
||||
sys.argv.append(os.path.splitext(os.path.basename(rtf))[0]+ext)
|
||||
|
||||
if not options.title or options.title == 'Unknown':
|
||||
sys.argv.append('-t')
|
||||
sys.argv.append('"'+mi.title+'"')
|
||||
if not options.author or options.author == 'Unknown':
|
||||
sys.argv.append('-a')
|
||||
sys.argv.append('"'+mi.author+'"')
|
||||
if not options.category or options.category == 'Unknown' and mi.category:
|
||||
sys.argv.append('--category')
|
||||
sys.argv.append('"'+mi.category+'"')
|
||||
if not options.freetext or options.freetext == 'Unknown' and mi.comments:
|
||||
sys.argv.append('--comment')
|
||||
sys.argv.append('"'+mi.comments+'"')
|
||||
options, args, parser = html_parse_options(parser=parser)
|
||||
process_file(html, options)
|
||||
finally:
|
||||
shutil.rmtree(tdir)
|
||||
except ConversionError, err:
|
||||
print >>sys.stderr, err
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
@ -19,7 +19,8 @@ import os, sys, codecs
|
||||
|
||||
from libprs500 import iswindows
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
from libprs500.ebooks.lrf import ConversionError, option_parser
|
||||
from libprs500.ebooks.lrf import option_parser
|
||||
from libprs500.ebooks import ConversionError
|
||||
from libprs500.ebooks.lrf.html.convert_from import parse_options as html_parse_options
|
||||
from libprs500.ebooks.lrf.html.convert_from import process_file
|
||||
from libprs500.ebooks.markdown import markdown
|
||||
|
@ -51,6 +51,7 @@ Var MUI_TEMP
|
||||
!define LIBUSB_DIR "C:\libusb-prs500"
|
||||
!define LIBUNRAR_DIR "C:\Program Files\UnrarDLL"
|
||||
!define CLIT "C:\clit\clit.exe"
|
||||
!define UNRTF "C:\unrtf\unrtf.exe"
|
||||
|
||||
;------------------------------------------------------------------------------------------------------
|
||||
;General
|
||||
@ -119,6 +120,7 @@ Section "libprs500" Seclibprs500
|
||||
;ADD YOUR OWN FILES HERE...
|
||||
File /r "${PY2EXE_DIR}\*"
|
||||
File "${CLIT}"
|
||||
File "${UNRTF}"
|
||||
|
||||
SetOutPath "$INSTDIR\driver"
|
||||
File "${LIBUSB_DIR}\*.dll"
|
||||
|
Loading…
x
Reference in New Issue
Block a user