From 8048b91fa86428d71329b15275d3134230a06019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Fri, 17 Mar 2017 10:55:56 +0100 Subject: [PATCH] Overhauled startup functions for PyPI packaging --- MANIFEST.in | 1 + kcc-c2e.py | 9 ++---- kcc-c2p.py | 9 ++---- kcc.py | 20 ++---------- kindlecomicconverter/startup.py | 53 ++++++++++++++++++++++++++++++++ setup.py | 54 ++++++++------------------------- 6 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 MANIFEST.in create mode 100644 kindlecomicconverter/startup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..e938f6e9 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +exclude kindlecomicconverter/sentry.py \ No newline at end of file diff --git a/kcc-c2e.py b/kcc-c2e.py index cb831888..c17deeca 100755 --- a/kcc-c2e.py +++ b/kcc-c2e.py @@ -23,14 +23,9 @@ print('ERROR: This is Python 3 script!') exit(1) -from kindlecomicconverter.shared import dependencyCheck -dependencyCheck(2) - from multiprocessing import freeze_support -from kindlecomicconverter import __version__ -from kindlecomicconverter.comic2ebook import main +from kindlecomicconverter.startup import startC2E if __name__ == "__main__": freeze_support() - print('comic2ebook v' + __version__ + ' - Written by Ciro Mattia Gonano and Pawel Jastrzebski.') - sys.exit(main(sys.argv[1:])) + startC2E() diff --git a/kcc-c2p.py b/kcc-c2p.py index bc6aa6b3..f1fb9150 100755 --- a/kcc-c2p.py +++ b/kcc-c2p.py @@ -23,14 +23,9 @@ print('ERROR: This is Python 3 script!') exit(1) -from kindlecomicconverter.shared import dependencyCheck -dependencyCheck(1) - from multiprocessing import freeze_support -from kindlecomicconverter import __version__ -from kindlecomicconverter.comic2panel import main +from kindlecomicconverter.startup import startC2P if __name__ == "__main__": freeze_support() - print('comic2panel v' + __version__ + ' - Written by Ciro Mattia Gonano and Pawel Jastrzebski.') - sys.exit(main(sys.argv[1:])) + startC2P() \ No newline at end of file diff --git a/kcc.py b/kcc.py index a93e48f5..445b0a36 100755 --- a/kcc.py +++ b/kcc.py @@ -63,24 +63,10 @@ def __init__(self, *args, **kw): except: pass -from kindlecomicconverter.shared import dependencyCheck -dependencyCheck(3) - from multiprocessing import freeze_support -from kindlecomicconverter import KCC_gui +from kindlecomicconverter.startup import start if __name__ == "__main__": freeze_support() - os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = "1" - KCCAplication = KCC_gui.QApplicationMessaging(sys.argv) - if KCCAplication.isRunning(): - if len(sys.argv) > 1: - KCCAplication.sendMessage(sys.argv[1]) - else: - KCCAplication.sendMessage('ARISE') - else: - KCCWindow = KCC_gui.QMainWindowKCC() - KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow) - if len(sys.argv) > 1: - KCCUI.handleMessage(sys.argv[1]) - sys.exit(KCCAplication.exec_()) + start() + diff --git a/kindlecomicconverter/startup.py b/kindlecomicconverter/startup.py new file mode 100644 index 00000000..4c47a17a --- /dev/null +++ b/kindlecomicconverter/startup.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2012-2014 Ciro Mattia Gonano +# Copyright (c) 2013-2017 Pawel Jastrzebski +# +# Permission to use, copy, modify, and/or distribute this software for +# any purpose with or without fee is hereby granted, provided that the +# above copyright notice and this permission notice appear in all +# copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# + +import os +import sys +from . import __version__ +from .shared import dependencyCheck + +def start(): + dependencyCheck(3) + from . import KCC_gui + os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = "1" + KCCAplication = KCC_gui.QApplicationMessaging(sys.argv) + if KCCAplication.isRunning(): + if len(sys.argv) > 1: + KCCAplication.sendMessage(sys.argv[1]) + else: + KCCAplication.sendMessage('ARISE') + else: + KCCWindow = KCC_gui.QMainWindowKCC() + KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow) + if len(sys.argv) > 1: + KCCUI.handleMessage(sys.argv[1]) + sys.exit(KCCAplication.exec_()) + +def startC2E(): + dependencyCheck(2) + from .comic2ebook import main + print('comic2ebook v' + __version__ + ' - Written by Ciro Mattia Gonano and Pawel Jastrzebski.') + sys.exit(main(sys.argv[1:])) + +def startC2P(): + dependencyCheck(1) + from .comic2panel import main + print('comic2panel v' + __version__ + ' - Written by Ciro Mattia Gonano and Pawel Jastrzebski.') + sys.exit(main(sys.argv[1:])) \ No newline at end of file diff --git a/setup.py b/setup.py index cdd19eb1..7e330fe7 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ py -3 setup.py build_binary Usage (Linux/OS X): - python3 setup.py build_binary or python3 setup.py build_binary --pyz + python3 setup.py build_binary """ import os @@ -60,42 +60,8 @@ def run(self): os.system('setup.bat') exit(0) else: - if self.pyz: - script = ''' - cp kcc.py __main__.py - zip kcc.zip __main__.py kindlecomicconverter/*.py - echo "#!/usr/bin/env python3" > kcc-bin - cat kcc.zip >> kcc-bin - chmod +x kcc-bin - - cp kcc-c2e.py __main__.py - zip kcc-c2e.zip __main__.py kindlecomicconverter/*.py - echo "#!/usr/bin/env python3" > kcc-c2e-bin - cat kcc-c2e.zip >> kcc-c2e-bin - chmod +x kcc-c2e-bin - - cp kcc-c2p.py __main__.py - zip kcc-c2p.zip __main__.py kindlecomicconverter/*.py - echo "#!/usr/bin/env python3" > kcc-c2p-bin - cat kcc-c2p.zip >> kcc-c2p-bin - chmod +x kcc-c2p-bin - - mkdir dist - tar --xform s:^.*/:: \ - --xform s/LICENSE.txt/LICENSE/ \ - --xform s/kcc-bin/kcc/ \ - --xform s/kcc-c2p-bin/kcc-c2p/ \ - --xform s/kcc-c2e-bin/kcc-c2e/ \ - --xform s/comic2ebook/kcc/ \ - -czf dist/KindleComicConverter_linux_''' + VERSION + '''.tar.gz \ - kcc-bin kcc-c2e-bin kcc-c2p-bin LICENSE.txt README.md icons/comic2ebook.png - rm __main__.py kcc.zip kcc-c2e.zip kcc-c2p.zip kcc-bin kcc-c2e-bin kcc-c2p-bin - ''' - os.system("bash -c '%s'" % script) - exit(0) - else: - os.system('docker run --rm -v ' + os.getcwd() + ':/app -e KCCVER=' + VERSION + ' acidweb/kcc') - exit(0) + os.system('docker run --rm -v ' + os.getcwd() + ':/app -e KCCVER=' + VERSION + ' acidweb/kcc') + exit(0) setuptools.setup( cmdclass={ @@ -109,12 +75,18 @@ def run(self): license='ISC License (ISCL)', keywords=['kindle', 'kobo', 'comic', 'manga', 'mobi', 'epub', 'cbz'], url='http://github.com/ciromattia/kcc', - scripts=['kcc.py', - 'kcc-c2e.py', - 'kcc-c2p.py'], + entry_points={ + 'console_scripts': [ + 'kcc-c2e = kindlecomicconverter.startup:startC2E', + 'kcc-c2p = kindlecomicconverter.startup:startC2P', + ], + 'gui_scripts': [ + 'kcc = kindlecomicconverter.startup:start', + ], + }, packages=['kindlecomicconverter'], install_requires=[ - 'PyQt5>=5.6.0' + 'PyQt5>=5.6.0', 'Pillow>=4.0.0', 'psutil>=5.0.0', 'python-slugify>=1.2.1',