diff options
author | Paweł Jastrzębski <pawelj@iosphe.re> | 2015-10-02 20:01:21 +0200 |
---|---|---|
committer | Paweł Jastrzębski <pawelj@iosphe.re> | 2015-10-02 20:01:21 +0200 |
commit | f93ced8939ba88d91e0974d1f30374fc88c4973a (patch) | |
tree | af66f6509381383e209bf94275908de52705a246 /setup.py | |
parent | Binary blob cleanup (diff) | |
download | kcc-f93ced8939ba88d91e0974d1f30374fc88c4973a.tar.gz kcc-f93ced8939ba88d91e0974d1f30374fc88c4973a.tar.bz2 kcc-f93ced8939ba88d91e0974d1f30374fc88c4973a.zip |
Migrated to PyInstaller
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 252 |
1 files changed, 110 insertions, 142 deletions
diff --git a/setup.py b/setup.py index 1490815..21a2ac2 100755 --- a/setup.py +++ b/setup.py @@ -1,168 +1,136 @@ #!/usr/bin/env python3 """ -pip/py2exe/py2app build script for KCC. +pip/pyinstaller build script for KCC. Usage (Windows): - py -3.4 setup.py py2exe + py -3 setup.py build_binary -Usage (Linux): - python3 setup.py make_pyz or python3 setup.py install - -Usage (Mac OS X): - python3 setup.py py2app +Usage (Linux/OS X): + python3 setup.py build_binary or python3 setup.py build_binary --pyz """ -from sys import platform, version_info, argv +import os +import sys +import shutil +import setuptools +import distutils.cmd +from distutils.command.build import build from kcc import __version__ - NAME = 'KindleComicConverter' -VERSION = __version__ MAIN = 'kcc.py' -extra_options = {} - - -if platform == 'darwin': - from setuptools import setup - from os import chmod, makedirs, system - from shutil import copyfile - extra_options = dict( - setup_requires=['py2app'], - app=[MAIN], - options=dict( - py2app=dict( - argv_emulation=True, - iconfile='icons/comic2ebook.icns', - includes=['sip', 'PyQt5.QtPrintSupport'], - resources=['LICENSE.txt', - 'other/osx/qt.conf', - 'other/osx/Additional-LICENSE.txt', - 'other/osx/unrar', - 'other/osx/7za'], - plist=dict( - CFBundleName='Kindle Comic Converter', - CFBundleShortVersionString=VERSION, - CFBundleGetInfoString=NAME + ' ' + VERSION + - ', written 2012-2015 by Ciro Mattia Gonano and Pawel Jastrzebski', - CFBundleExecutable=NAME, - CFBundleDocumentTypes=[ - dict( - CFBundleTypeExtensions=['cbz', 'cbr', 'cb7', 'zip', 'rar', '7z', 'pdf'], - CFBundleTypeName='Comics', - CFBundleTypeIconFile='comic2ebook.icns', - CFBundleTypeRole='Editor', - ) - ], - CFBundleIdentifier='com.kindlecomicconverter.KindleComicConverter', - LSMinimumSystemVersion='10.8.0', - LSEnvironment=dict( - PATH='./../Resources:/usr/local/bin:/usr/bin:/bin' - ), - NSHumanReadableCopyright='ISC License (ISCL)' - ) - ) - ) - ) -elif platform == 'win32': - import py2exe - from platform import architecture - from distutils.core import setup - if architecture()[0] == '64bit': - suffix = '_64' - else: - suffix = '' - additional_files = [('platforms', ['C:\Python34' + suffix + - '\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll']), - ('', ['LICENSE.txt', - 'other\\windows\\7za.exe', - 'other\\windows\\UnRAR.exe', - 'other\\windows\\Additional-LICENSE.txt', - 'C:\Python34' + suffix + '\Lib\site-packages\PyQt5\libGLESv2.dll', - 'C:\Python34' + suffix + '\Lib\site-packages\PyQt5\libEGL.dll'])] - extra_options = dict( - options={'py2exe': {'bundle_files': 1, - 'dist_dir': 'dist' + suffix, - 'compressed': True, - 'includes': ['sip'], - 'excludes': ['tkinter'], - 'optimize': 2}}, - windows=[{'script': MAIN, - 'dest_base': 'KCC', - 'version': VERSION, - 'copyright': 'Ciro Mattia Gonano, Pawel Jastrzebski © 2012-2015', - 'legal_copyright': 'ISC License (ISCL)', - 'product_version': VERSION, - 'product_name': 'Kindle Comic Converter', - 'file_description': 'Kindle Comic Converter', - 'icon_resources': [(1, 'icons\comic2ebook.ico')]}], - zipfile=None, - data_files=additional_files) -else: - if len(argv) > 1 and argv[1] == 'make_pyz': - from os import system - script = ''' - cp kcc.py __main__.py - zip kcc.zip __main__.py kcc/*.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 kcc/*.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 kcc/*.py - echo "#!/usr/bin/env python3" > kcc-c2p-bin - cat kcc-c2p.zip >> kcc-c2p-bin - chmod +x kcc-c2p-bin - - 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 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 - ''' - system("bash -c '%s'" % script) - exit(0) - else: - from setuptools import setup - from os import makedirs - from shutil import copyfile - makedirs('build/_scripts/', exist_ok=True) - copyfile('kcc.py', 'build/_scripts/kcc') - copyfile('kcc-c2e.py', 'build/_scripts/kcc-c2e') - copyfile('kcc-c2p.py', 'build/_scripts/kcc-c2p') - extra_options = dict( - scripts=['build/_scripts/kcc', 'build/_scripts/kcc-c2e', 'build/_scripts/kcc-c2p'], +VERSION = __version__ +OPTIONS = {} + + +class BuildBinaryCommand(distutils.cmd.Command): + description = 'build binary release' + user_options = [ + ('pyz', None, 'build PYZ package'), + ] + + def initialize_options(self): + # noinspection PyAttributeOutsideInit + self.pyz = False + + def finalize_options(self): + pass + + def run(self): + if sys.platform == 'darwin': + os.system('pyinstaller -y -F -i icons/comic2ebook.icns -n "Kindle Comic Converter" -w -s kcc.py') + shutil.copy('other/osx/7za', 'dist/Kindle Comic Converter.app/Contents/Resources') + shutil.copy('other/osx/unrar', 'dist/Kindle Comic Converter.app/Contents/Resources') + shutil.copy('other/osx/Info.plist', 'dist/Kindle Comic Converter.app/Contents') + shutil.copy('LICENSE.txt', 'dist/Kindle Comic Converter.app/Contents/Resources') + shutil.copy('other/windows/Additional-LICENSE.txt', 'dist/Kindle Comic Converter.app/Contents/Resources') + os.chmod('dist/Kindle Comic Converter.app/Contents/Resources/unrar', 0o777) + os.chmod('dist/Kindle Comic Converter.app/Contents/Resources/7za', 0o777) + if os.path.isfile('setup.sh'): + os.system('setup.sh') + os.system('appdmg kcc.json dist/KindleComicConverter_osx_' + VERSION + '.dmg') + exit(0) + elif sys.platform == 'win32': + os.system('pyinstaller -y -F -i icons\comic2ebook.ico -n KCC -w kcc.py') + if os.path.isfile('setup.bat'): + os.system('setup.bat ' + VERSION) + exit(0) + else: + if self.pyz: + script = ''' + cp kcc.py __main__.py + zip kcc.zip __main__.py kcc/*.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 kcc/*.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 kcc/*.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 build --no-cache -t kcc . && docker run --rm -v ' + os.getcwd() + + ':/out kcc && docker rmi kcc') + exit(0) + + +class BuildCommand(build): + def run(self): + os.makedirs('build/_scripts/', exist_ok=True) + shutil.copyfile('kcc.py', 'build/_scripts/kcc') + shutil.copyfile('kcc-c2e.py', 'build/_scripts/kcc-c2e') + shutil.copyfile('kcc-c2p.py', 'build/_scripts/kcc-c2p') + # noinspection PyShadowingNames + OPTIONS = dict( + scripts=['build/_scripts/kcc', + 'build/_scripts/kcc-c2e', + 'build/_scripts/kcc-c2p'], packages=['kcc'], install_requires=[ - 'Pillow>=2.8.2', - 'psutil>=3.0.0', - 'python-slugify>=1.1.3', + 'Pillow>=3.0.0', + 'psutil>=3.2.1', + 'python-slugify>=1.1.4', ], zip_safe=False, ) - if version_info[1] < 5: - extra_options['install_requires'].append('scandir>=1.1.0') + if sys.version_info[1] < 5: + OPTIONS['install_requires'].append('scandir>=1.1.0') + build.run(self) -setup( +setuptools.setup( + cmdclass={ + 'build_binary': BuildBinaryCommand, + 'build': BuildCommand, + }, name=NAME, version=VERSION, author='Ciro Mattia Gonano, Pawel Jastrzebski', author_email='ciromattia@gmail.com, pawelj@iosphe.re', - description='Comic and manga converter for E-Book readers.', + description='Comic and Manga converter for e-book readers.', license='ISC License (ISCL)', keywords='kindle comic mobipocket mobi cbz cbr manga', url='http://github.com/ciromattia/kcc', - **extra_options + **OPTIONS ) - -if platform == 'darwin': - makedirs('dist/Kindle Comic Converter.app/Contents/PlugIns/platforms', exist_ok=True) - copyfile('other/osx/libqcocoa.dylib', 'dist/Kindle Comic Converter.app/Contents/PlugIns/platforms/libqcocoa.dylib') - chmod('dist/Kindle Comic Converter.app/Contents/Resources/unrar', 0o777) - chmod('dist/Kindle Comic Converter.app/Contents/Resources/7za', 0o777) - system('appdmg setup.json dist/KindleComicConverter_osx_' + VERSION + '.dmg') |