Added a --with-library option to the calibre GUI so that it can be easily used with multiple libraries

This commit is contained in:
Kovid Goyal 2008-10-16 18:46:22 -07:00
parent 4f4bf0ec02
commit 0114f4cf20
2 changed files with 9 additions and 4 deletions

View File

@ -24,9 +24,9 @@ _('''%prog [options] mybook.txt
dest='debug_html_generation', help=_('Print generated HTML to stdout and quit.'))
return parser
def fix_image_includes(tdir, match):
def fix_image_includes(sdir, tdir, match):
path = match.group(1).split('/')
src = os.path.join(os.getcwd(), *path)
src = os.path.join(sdir, *path)
dest = os.path.join(tdir, *path)
p = os.path.dirname(dest)
if not os.path.exists(p):
@ -64,7 +64,7 @@ def generate_html(txtfile, encoding, tdir):
)
html = '<html><body>'+md.convert(txt)+'</body></html>'
for match in re.finditer(r'<img\s+[^>]*src="([^"]+)"', html):
fix_image_includes(tdir, match)
fix_image_includes(os.path.dirname(txtfile), tdir, match)
p = os.path.join(tdir, 'index.html')
open(p, 'wb').write(html.encode('utf-8'))
mi = MetaInformation(os.path.splitext(os.path.basename(txtfile))[0], [_('Unknown')])
@ -109,4 +109,4 @@ def main(args=sys.argv, logger=None):
return 0
if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

View File

@ -1252,7 +1252,12 @@ def main(args=sys.argv):
Launch the main calibre Graphical User Interface and optionally add the ebook at
path_to_ebook to the database.
''')
parser.add_option('--with-library', default=None, action='store',
help=_('Use the library located at the specified path.'))
opts, args = parser.parse_args(args)
if opts.with_library is not None and os.path.isdir(opts.with_library):
prefs.set('library_path', opts.with_library)
print 'Using library at', prefs['library_path']
app = Application(args)
app.setWindowIcon(QIcon(':/library'))
QCoreApplication.setOrganizationName(ORG_NAME)