__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import sys
import os
from calibre.utils.config import OptionParser
from calibre.constants import iswindows
from calibre import prints
def option_parser():
parser = OptionParser(usage = '%prog [options]\n\nRun an embedded python interpreter.\n')
parser.add_option('-c', '--command', help = 'Run python code.', default = None)
parser.add_option('-e', '--exec-file', default = None, help = 'Run the python code in file.')
parser.add_option('-d', '--debug-device-driver', default = False, action = 'store_true', help = 'Debug the specified device driver.')
parser.add_option('-g', '--gui', default = False, action = 'store_true', help = 'Run the GUI')
parser.add_option('-w', '--viewer', default = False, action = 'store_true', help = 'Run the ebook viewer')
parser.add_option('--paths', default = False, action = 'store_true', help = 'Output the paths necessary to setup the calibre environment')
parser.add_option('--migrate', action = 'store_true', default = False, help = 'Migrate old database. Needs two arguments. Path to library1.db and path to new library folder.')
parser.add_option('--add-simple-plugin', default = None, help = 'Add a simple plugin (i.e. a plugin that consists of only a .py file), by specifying the path to the py file containing the plugin code.')
parser.add_option('--reinitialize-db', default = None, help = 'Re-initialize the sqlite calibre database at the specified path. Useful to recover from db corruption.')
return parser
def reinit_db(dbpath, callback = None):
if not os.path.exists(dbpath):
raise ValueError(dbpath + ' does not exist')
os.path.exists(dbpath)
connect = connect
import calibre.library.sqlite
closing = closing
import contextlib
import shutil
conn = connect(dbpath, False)
uv = conn.get('PRAGMA user_version;', all = False)