nsis-configurator.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import shutil
  2. import sys
  3. from datetime import datetime
  4. from pathlib import Path
  5. from jinja2 import Template
  6. if __name__ == "__main__":
  7. """
  8. - dist_loc: Location of distribution folder, as output by pyinstaller
  9. - nsi_jinja_loc: Jinja2 template to use
  10. - app_name: Should be "Ultimaker Cura".
  11. - main_app: Name of executable, e.g. Ultimaker-Cura.exe?
  12. - version_major: Major version number of Semver (e.g. 5).
  13. - version_minor: Minor version number of Semver (e.g. 0).
  14. - version_patch: Patch version number of Semver (e.g. 0).
  15. - version_build: A version number that gets manually incremented at each build.
  16. - company: Publisher of the application. Should be "Ultimaker B.V."
  17. - web_site: Website to find more information. Should be "https://ultimaker.com".
  18. - cura_license_file: Path to a license file in Cura. Should point to packaging/cura_license.txt in this repository.
  19. - compression_method: Compression algorithm to use to compress the data inside the executable. Should be ZLIB, ZBIP2 or LZMA.
  20. - cura_banner_img: Path to an image shown on the left in the installer. Should point to packaging/cura_banner_nsis.bmp in this repository.
  21. - icon_path: Path to the icon to use on the installer
  22. - destination: Where to put the installer after it's generated.
  23. ` """
  24. for i, v in enumerate(sys.argv):
  25. print(f"{i} = {v}")
  26. dist_loc = Path(sys.argv[1])
  27. instdir = Path("$INSTDIR")
  28. dist_paths = [p.relative_to(dist_loc) for p in sorted(dist_loc.rglob("*")) if p.is_file()]
  29. mapped_out_paths = {}
  30. for dist_path in dist_paths:
  31. if "__pycache__" not in dist_path.parts:
  32. out_path = instdir.joinpath(dist_path).parent
  33. if out_path not in mapped_out_paths:
  34. mapped_out_paths[out_path] = [(dist_loc.joinpath(dist_path), instdir.joinpath(dist_path))]
  35. else:
  36. mapped_out_paths[out_path].append((dist_loc.joinpath(dist_path), instdir.joinpath(dist_path)))
  37. rmdir_paths = set()
  38. for rmdir_f in mapped_out_paths.values():
  39. for _, rmdir_p in rmdir_f:
  40. for rmdir in rmdir_p.parents:
  41. rmdir_paths.add(rmdir)
  42. rmdir_paths = sorted(list(rmdir_paths), reverse = True)[:-2]
  43. jinja_template_path = Path(sys.argv[2])
  44. with open(jinja_template_path, "r") as f:
  45. template = Template(f.read())
  46. nsis_content = template.render(
  47. app_name = sys.argv[3],
  48. main_app = sys.argv[4],
  49. version_major = sys.argv[5],
  50. version_minor = sys.argv[6],
  51. version_patch = sys.argv[7],
  52. version_build = sys.argv[8],
  53. company = sys.argv[9],
  54. web_site = sys.argv[10],
  55. year = datetime.now().year,
  56. cura_license_file = Path(sys.argv[11]),
  57. compression_method = sys.argv[12], # ZLIB, BZIP2 or LZMA
  58. cura_banner_img = Path(sys.argv[13]),
  59. cura_icon = Path(sys.argv[14]),
  60. mapped_out_paths = mapped_out_paths,
  61. rmdir_paths = rmdir_paths,
  62. destination = Path(sys.argv[15])
  63. )
  64. with open(dist_loc.parent.joinpath(jinja_template_path.stem), "w") as f:
  65. f.write(nsis_content)
  66. shutil.copy(Path(__file__).absolute().parent.joinpath("fileassoc.nsh"), dist_loc.parent.joinpath("fileassoc.nsh"))
  67. icon_path = Path(sys.argv[14])
  68. shutil.copy(icon_path, dist_loc.joinpath(icon_path.name))