build.py 2.6 KB

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