2018-05-07 03:55:38 -06:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# code: utf-8
|
|
|
|
|
|
|
|
'''
|
|
|
|
A wrapper script to generate zip files for GitHub releases.
|
|
|
|
|
|
|
|
This script tends to be compatible with both Python 2 and Python 3.
|
|
|
|
'''
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
DEDRM_SRC_DIR = 'dedrm_src'
|
|
|
|
OBOK_SRC_DIR = 'obok_src'
|
|
|
|
SHELLS_BASE = 'contrib'
|
2018-05-07 03:55:38 -06:00
|
|
|
|
|
|
|
def make_calibre_plugin():
|
2018-12-02 04:51:51 -07:00
|
|
|
calibre_plugin_dir = os.path.join(SHELLS_BASE, 'DeDRM_calibre_plugin')
|
|
|
|
core_dir = os.path.join(calibre_plugin_dir, 'DeDRM_plugin')
|
2018-05-07 03:55:38 -06:00
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
shutil.copytree(DEDRM_SRC_DIR, core_dir)
|
|
|
|
shutil.make_archive(core_dir, 'zip', core_dir)
|
|
|
|
shutil.rmtree(core_dir)
|
2018-05-07 03:55:38 -06:00
|
|
|
|
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
def make_obok_plugin():
|
|
|
|
obok_plugin_dir = os.path.join(SHELLS_BASE, 'Obok_calibre_plugin')
|
|
|
|
core_dir = os.path.join(obok_plugin_dir, 'obok_plugin')
|
2018-05-07 03:55:38 -06:00
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
shutil.copytree(OBOK_SRC_DIR, core_dir)
|
|
|
|
shutil.make_archive(core_dir, 'zip', core_dir)
|
2018-05-07 03:55:38 -06:00
|
|
|
shutil.rmtree(core_dir)
|
|
|
|
|
|
|
|
|
|
|
|
def make_windows_app():
|
2018-12-02 04:51:51 -07:00
|
|
|
windows_app_dir = os.path.join(SHELLS_BASE, 'DeDRM_Windows_Application')
|
|
|
|
core_dir = os.path.join(windows_app_dir, 'DeDRM_App', 'DeDRM_lib', 'lib')
|
2018-05-07 03:55:38 -06:00
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
# delete any existing core_dir
|
|
|
|
try:
|
|
|
|
shutil.rmtree(core_dir)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2018-05-07 03:55:38 -06:00
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
shutil.copytree(DEDRM_SRC_DIR, core_dir)
|
2018-05-07 03:55:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
def make_macos_app():
|
2018-12-02 04:51:51 -07:00
|
|
|
macos_app_dir = os.path.join(SHELLS_BASE, 'DeDRM_Macintosh_Application')
|
|
|
|
core_dir = os.path.join(macos_app_dir, 'DeDRM.app', 'Contents', 'Resources')
|
2018-05-07 03:55:38 -06:00
|
|
|
|
2018-12-02 04:51:51 -07:00
|
|
|
# Resources already exists - copy contents to contents.
|
|
|
|
_, dirs, files = next(os.walk(DEDRM_SRC_DIR))
|
2018-05-07 03:55:38 -06:00
|
|
|
for name in dirs:
|
|
|
|
shutil.copyfile(
|
2018-12-02 04:51:51 -07:00
|
|
|
os.path.join(DEDRM_SRC_DIR, name),
|
2018-05-07 03:55:38 -06:00
|
|
|
os.path.join(core_dir, name)
|
|
|
|
)
|
|
|
|
for name in files:
|
|
|
|
shutil.copy2(
|
2018-12-02 04:51:51 -07:00
|
|
|
os.path.join(DEDRM_SRC_DIR, name),
|
2018-05-07 03:55:38 -06:00
|
|
|
os.path.join(core_dir, name)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-05-07 04:27:05 -06:00
|
|
|
def make_release(version):
|
|
|
|
make_calibre_plugin()
|
|
|
|
make_windows_app()
|
|
|
|
make_macos_app()
|
|
|
|
make_obok_plugin()
|
|
|
|
|
|
|
|
release_name = 'DeDRM_tools_{}'.format(version)
|
2018-12-02 04:51:51 -07:00
|
|
|
return shutil.make_archive(release_name, 'zip', SHELLS_BASE)
|
2018-05-07 03:55:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-05-07 04:27:05 -06:00
|
|
|
import sys
|
|
|
|
try:
|
|
|
|
version = sys.argv[1]
|
|
|
|
except IndexError:
|
|
|
|
raise SystemExit('Usage: {} version'.format(__file__))
|
|
|
|
|
|
|
|
print(make_release(version))
|