2 # -*- coding: utf-8 -*-
5 A wrapper script to generate zip files for GitHub releases.
7 This script tends to be compatible with both Python 2 and Python 3.
10 from __future__
import print_function
16 DEDRM_SRC_DIR
= 'DeDRM_plugin'
17 DEDRM_SRC_TMP_DIR
= 'DeDRM_plugin_temp'
18 DEDRM_README
= 'DeDRM_plugin_ReadMe.txt'
19 OBOK_SRC_DIR
= 'Obok_plugin'
20 OBOK_README
= 'obok_plugin_ReadMe.txt'
21 RELEASE_DIR
= 'release'
23 def patch_file(filepath
):
24 f
= open(filepath
, "rb")
25 fn
= open(filepath
+ ".tmp", "wb")
26 patch
= open(os
.path
.join(DEDRM_SRC_DIR
, "__calibre_compat_code.py"), "rb")
27 patchdata
= patch
.read()
35 if line
.strip().startswith(b
"#@@CALIBRE_COMPAT_CODE@@"):
42 shutil
.move(filepath
+ ".tmp", filepath
)
46 def make_release(version
):
48 shutil
.rmtree(RELEASE_DIR
)
52 shutil
.rmtree(DEDRM_SRC_TMP_DIR
)
59 shutil
.copytree(DEDRM_SRC_DIR
, DEDRM_SRC_TMP_DIR
)
63 shutil
.rmtree(os
.path
.join(os
.path
.abspath(DEDRM_SRC_TMP_DIR
), "__pycache__"))
67 # Patch file to add compat code.
68 for root
, dirs
, files
in os
.walk(DEDRM_SRC_TMP_DIR
):
70 if name
.endswith(".py"):
71 patch_file(os
.path
.join(root
, name
))
75 shutil
.make_archive(DEDRM_SRC_DIR
, 'zip', DEDRM_SRC_TMP_DIR
)
76 shutil
.make_archive(OBOK_SRC_DIR
, 'zip', OBOK_SRC_DIR
)
77 shutil
.move(DEDRM_SRC_DIR
+'.zip', RELEASE_DIR
)
78 shutil
.move(OBOK_SRC_DIR
+'.zip', RELEASE_DIR
)
79 shutil
.copy(DEDRM_README
, RELEASE_DIR
)
80 shutil
.copy(OBOK_README
, RELEASE_DIR
)
81 shutil
.copy("ReadMe_Overview.txt", RELEASE_DIR
)
84 shutil
.rmtree(DEDRM_SRC_TMP_DIR
)
86 if version
is not None:
87 release_name
= 'DeDRM_tools_{}'.format(version
)
89 release_name
= 'DeDRM_tools'
90 result
= shutil
.make_archive(release_name
, 'zip', RELEASE_DIR
)
92 shutil
.rmtree(RELEASE_DIR
)
98 if __name__
== '__main__':
101 version
= sys
.argv
[1]
105 print(make_release(version
))