You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

199 lines
5.6 KiB

  1. # Copyright 2017 Virgil Dupras
  2. #
  3. # This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
  4. # which should be included with this package. The terms are also available at
  5. # http://www.gnu.org/licenses/gpl-3.0.html
  6. import os
  7. import os.path as op
  8. from optparse import OptionParser
  9. import shutil
  10. from setuptools import setup, Extension
  11. from hscommon import sphinxgen
  12. from hscommon.build import (
  13. add_to_pythonpath,
  14. print_and_do,
  15. move_all,
  16. fix_qt_resource_file,
  17. )
  18. from hscommon import loc
  19. def parse_args():
  20. usage = "usage: %prog [options]"
  21. parser = OptionParser(usage=usage)
  22. parser.add_option(
  23. "--clean",
  24. action="store_true",
  25. dest="clean",
  26. help="Clean build folder before building",
  27. )
  28. parser.add_option(
  29. "--doc", action="store_true", dest="doc", help="Build only the help file"
  30. )
  31. parser.add_option(
  32. "--loc", action="store_true", dest="loc", help="Build only localization"
  33. )
  34. parser.add_option(
  35. "--updatepot",
  36. action="store_true",
  37. dest="updatepot",
  38. help="Generate .pot files from source code.",
  39. )
  40. parser.add_option(
  41. "--mergepot",
  42. action="store_true",
  43. dest="mergepot",
  44. help="Update all .po files based on .pot files.",
  45. )
  46. parser.add_option(
  47. "--normpo",
  48. action="store_true",
  49. dest="normpo",
  50. help="Normalize all PO files (do this before commit).",
  51. )
  52. parser.add_option(
  53. "--modules",
  54. action="store_true",
  55. dest="modules",
  56. help="Build the python modules.",
  57. )
  58. (options, args) = parser.parse_args()
  59. return options
  60. def build_help():
  61. print("Generating Help")
  62. current_path = op.abspath(".")
  63. help_basepath = op.join(current_path, "help", "en")
  64. help_destpath = op.join(current_path, "build", "help")
  65. changelog_path = op.join(current_path, "help", "changelog")
  66. tixurl = "https://github.com/arsenetar/dupeguru/issues/{}"
  67. confrepl = {"language": "en"}
  68. changelogtmpl = op.join(current_path, "help", "changelog.tmpl")
  69. conftmpl = op.join(current_path, "help", "conf.tmpl")
  70. sphinxgen.gen(
  71. help_basepath,
  72. help_destpath,
  73. changelog_path,
  74. tixurl,
  75. confrepl,
  76. conftmpl,
  77. changelogtmpl,
  78. )
  79. def build_qt_localizations():
  80. loc.compile_all_po(op.join("qtlib", "locale"))
  81. loc.merge_locale_dir(op.join("qtlib", "locale"), "locale")
  82. def build_localizations():
  83. loc.compile_all_po("locale")
  84. build_qt_localizations()
  85. locale_dest = op.join("build", "locale")
  86. if op.exists(locale_dest):
  87. shutil.rmtree(locale_dest)
  88. shutil.copytree(
  89. "locale", locale_dest, ignore=shutil.ignore_patterns("*.po", "*.pot")
  90. )
  91. def build_updatepot():
  92. print("Building .pot files from source files")
  93. print("Building core.pot")
  94. loc.generate_pot(["core"], op.join("locale", "core.pot"), ["tr"])
  95. print("Building columns.pot")
  96. loc.generate_pot(["core"], op.join("locale", "columns.pot"), ["coltr"])
  97. print("Building ui.pot")
  98. # When we're not under OS X, we don't want to overwrite ui.pot because it contains Cocoa locs
  99. # We want to merge the generated pot with the old pot in the most preserving way possible.
  100. ui_packages = ["qt", op.join("cocoa", "inter")]
  101. loc.generate_pot(ui_packages, op.join("locale", "ui.pot"), ["tr"], merge=True)
  102. print("Building qtlib.pot")
  103. loc.generate_pot(["qtlib"], op.join("qtlib", "locale", "qtlib.pot"), ["tr"])
  104. def build_mergepot():
  105. print("Updating .po files using .pot files")
  106. loc.merge_pots_into_pos("locale")
  107. loc.merge_pots_into_pos(op.join("qtlib", "locale"))
  108. loc.merge_pots_into_pos(op.join("cocoalib", "locale"))
  109. def build_normpo():
  110. loc.normalize_all_pos("locale")
  111. loc.normalize_all_pos(op.join("qtlib", "locale"))
  112. loc.normalize_all_pos(op.join("cocoalib", "locale"))
  113. def build_pe_modules():
  114. print("Building PE Modules")
  115. exts = [
  116. Extension(
  117. "_block",
  118. [
  119. op.join("core", "pe", "modules", "block.c"),
  120. op.join("core", "pe", "modules", "common.c"),
  121. ],
  122. ),
  123. Extension(
  124. "_cache",
  125. [
  126. op.join("core", "pe", "modules", "cache.c"),
  127. op.join("core", "pe", "modules", "common.c"),
  128. ],
  129. ),
  130. ]
  131. exts.append(Extension("_block_qt", [op.join("qt", "pe", "modules", "block.c")]))
  132. setup(
  133. script_args=["build_ext", "--inplace"], ext_modules=exts,
  134. )
  135. move_all("_block_qt*", op.join("qt", "pe"))
  136. move_all("_block*", op.join("core", "pe"))
  137. move_all("_cache*", op.join("core", "pe"))
  138. def build_normal():
  139. print("Building dupeGuru with UI qt")
  140. add_to_pythonpath(".")
  141. print("Building dupeGuru")
  142. build_pe_modules()
  143. print("Building localizations")
  144. build_localizations()
  145. print("Building Qt stuff")
  146. print_and_do(
  147. "pyrcc5 {0} > {1}".format(op.join("qt", "dg.qrc"), op.join("qt", "dg_rc.py"))
  148. )
  149. fix_qt_resource_file(op.join("qt", "dg_rc.py"))
  150. build_help()
  151. def main():
  152. options = parse_args()
  153. if options.clean:
  154. if op.exists("build"):
  155. shutil.rmtree("build")
  156. if not op.exists("build"):
  157. os.mkdir("build")
  158. if options.doc:
  159. build_help()
  160. elif options.loc:
  161. build_localizations()
  162. elif options.updatepot:
  163. build_updatepot()
  164. elif options.mergepot:
  165. build_mergepot()
  166. elif options.normpo:
  167. build_normpo()
  168. elif options.modules:
  169. build_pe_modules()
  170. else:
  171. build_normal()
  172. if __name__ == "__main__":
  173. main()