build.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. '''
  2. @author: olivier.massot, 2019
  3. '''
  4. import configparser
  5. from core import constants
  6. from zipfile import ZipFile, ZIP_DEFLATED
  7. from path import Path
  8. build_dir = constants.MAIN / "build"
  9. build_dir.mkdir_p()
  10. version = constants.VERSION
  11. basename = "MnCheck"
  12. name = "{}_v{}.zip".format(basename, version.replace(".", "-"))
  13. config = configparser.ConfigParser()
  14. config["general"] = {"name" : basename,
  15. "qgisminimumversion" : "3.4",
  16. "description" : "Contrôle des données FTTH format MN",
  17. "version" : version,
  18. "author" : "Manche Numérique 2019",
  19. "email" : constants.CONTACT,
  20. "about" : "Auto-contrôle des livrables FTTH aux formats Manche Numérique",
  21. "tracker" : "",
  22. "repository" : "",
  23. "tags" : "python",
  24. "homepage" : "http://www.manchenumerique.fr/",
  25. "category" : "Plugins",
  26. "icon" : "icon.png",
  27. "experimental" : "False",
  28. "deprecated" : "False"}
  29. with open(constants.MAIN / 'metadata.txt', 'w+', encoding='utf-8') as mdf:
  30. mdf.write("# This file was generated by the build.py script, do not modify it direcly\n".upper())
  31. config.write(mdf)
  32. with ZipFile(build_dir / name, 'w', ZIP_DEFLATED, 9) as zip_:
  33. def _zip_write(p):
  34. if p.ext == ".pyc":
  35. return
  36. arcname = (basename + "/" + p.relpath(constants.MAIN)).replace("\\", "/")
  37. print(arcname)
  38. zip_.write(p, arcname)
  39. _zip_write(constants.MAIN)
  40. _zip_write(constants.MAIN / "core")
  41. for f in Path(constants.MAIN / "core").walkfiles():
  42. _zip_write(f)
  43. _zip_write(constants.MAIN / "schemas")
  44. for f in Path(constants.MAIN / "schemas").walkfiles():
  45. _zip_write(f)
  46. _zip_write(constants.MAIN / "ui")
  47. for f in Path(constants.MAIN / "ui").walkfiles():
  48. _zip_write(f)
  49. _zip_write(constants.MAIN / "ext")
  50. for f in Path(constants.MAIN / "ext").walkfiles():
  51. _zip_write(f)
  52. _zip_write(constants.MAIN / "__init__.py")
  53. _zip_write(constants.MAIN / "main.py")
  54. _zip_write(constants.MAIN / "README.md")
  55. _zip_write(constants.MAIN / "icon.png")
  56. _zip_write(constants.MAIN / "LICENSE")
  57. _zip_write(constants.MAIN / "metadata.txt")
  58. Path(build_dir / "metadata.txt").remove_p()
  59. print(f"-- {name} file built --")