Skip to content

Commit

Permalink
Implement a CLI interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-schwartz committed Sep 13, 2019
1 parent 0559cc5 commit 6cda7ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ def is_customizable(self):
''' This method must return True to enable customization via
Preferences->Plugins '''
return False

def cli_main(self, argv):
from calibre_plugins.scrambleebook_plugin.scrambleebook import main
main('this came from a .zip', argv[1:])
32 changes: 20 additions & 12 deletions scrambleebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,10 @@ def initialise_new_file(self, pathtoebook):
# not calibre library book, ie standalone or book on attached device
sourcepath = self.ebook.path_to_ebook

if self.from_calibre:
# calibre plugin
try:
self.dummyimg = get_resources('images/' + format + '.png')
self.dummysvg = get_resources('images/' + format + '.svg')
self.dirout = ''
else:
# standalone version
except:
dummyimgdir = os.path.join(self.progdir, 'images')
dummy_imgpath = os.path.join(dummyimgdir, format + '.png')
with open(dummy_imgpath, 'rb') as f:
Expand All @@ -243,6 +240,12 @@ def initialise_new_file(self, pathtoebook):
with open(dummy_svgpath, 'rb') as f:
ans = f.read()
self.dummysvg = self.ebook.decode(ans)

if self.from_calibre:
# calibre plugin
self.dirout = ''
else:
# standalone version
self.dirout = dirn
self.log.append('\n--- New ebook: %s' % sourcepath)

Expand Down Expand Up @@ -1152,15 +1155,16 @@ def get_fileparts(path):
is_kepub_epub = fn.rpartition('.')[-1].lower() == 'kepub'
return (dirname, fn, ext, is_kepub_epub)

if __name__ == "__main__":
import sys
def main(prog, args):

prog = sys.argv[0]
progdir, x, x, x = get_fileparts(prog)
if prog.endswith('.py'):
progdir, x, x, x = get_fileparts(prog)
else:
progdir = None

if len(sys.argv) > 1:
if args:
# Windows Send-to or drag-drop onto .bat
ebook_path = sys.argv[1]
ebook_path = args[0]
else:
ebook_path = ''

Expand All @@ -1180,8 +1184,12 @@ def get_fileparts(path):
#MY_SETTINGS['x_meta_extra'] = False # True = Try to remove other metadata which identifies book
#MY_SETTINGS['x_fnames'] = False # True = Rename files (HTML, images, CSS) to generic filenames

app = QApplication(sys.argv)
app = QApplication(args)
win = EbookScramble(None, ebook_path, book_id=None, dsettings=MY_SETTINGS, progdir=progdir)

win.show()
app.exec_()

if __name__ == "__main__":
import sys
main(sys.argv[0], sys.argv[1:])

0 comments on commit 6cda7ab

Please sign in to comment.