wiki.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  2. import sys
  3. WEBSITE = "https://notabug.org/GPast/$NAME/"
  4. def build_dlmod(tag, vrs):
  5. LINES = ["## $TAG$VRS", "* [Debian Package]("+WEBSITE+"raw/archive/$VRS/$NAME\-$VRS.deb)", \
  6. "* [Source Code (tar.gz)]("+WEBSITE+"raw/archive/$VRS/$NAME\-$VRS.tar.gz)", ""]
  7. return "\n\n".join(LINES).replace("$VRS", vrs).replace("$TAG", tag)
  8. def build_dlpage(name):
  9. with open("../Wiki/versions.txt", mode="r") as f:
  10. vrs = f.read().splitlines()
  11. PAGE = "Welcome to the $NAME downloads page! The latest version is **"+vrs[0].split("\t")[1]+\
  12. "**, and we recommend you use this.\nFor information on installation, please see the [User Documentation]("+\
  13. WEBSITE+"wiki/User+Documentation).\n\n"
  14. for line in vrs:
  15. if line == "":
  16. continue
  17. segs = line.split("\t", maxsplit=1)
  18. PAGE += build_dlmod(*segs)
  19. PAGE += "## [ALL RELEASES]("+WEBSITE+"src/archive/)"
  20. with open("../Wiki/Downloads.md", mode="w") as f:
  21. f.write(PAGE.replace("$NAME", name))
  22. return 0
  23. def srs_update(vrs):
  24. with open("../Wiki/versions.txt", mode="r") as f:
  25. vrsPub = f.read()
  26. srs = vrs.rsplit(".", maxsplit=1)[0]+"."
  27. segs = vrsPub.split(srs, maxsplit=1)
  28. if len(segs) != 2:
  29. if len(segs) == 1:
  30. print("Error: series for %s not found in releases." % vrs)
  31. else:
  32. print("Error: series for %s appears to be duplicated." % vrs)
  33. sys.exit(3)
  34. segsone = segs[1].split("\n", maxsplit=1)
  35. with open("../Wiki/versions.txt", mode="w") as f:
  36. f.write(segs[0]+vrs+"\n"+segsone[1])
  37. return 1
  38. def srs_make(vrs):
  39. with open("../Wiki/versions.txt", mode="r") as f:
  40. vrsPub = f.read()
  41. with open("../Wiki/versions.txt", mode="w") as f:
  42. f.write("LATEST\\- \t%s\n" % vrs)
  43. f.write(vrsPub.replace("LATEST\\- ", ""))
  44. return 1
  45. def srs_dep(srs):
  46. with open("../Wiki/versions.txt", mode="r") as f:
  47. vrsPub = f.read().splitlines()
  48. vrs = ""
  49. for line in vrsPub:
  50. if not srs+"." in line:
  51. vrs += line+"\n"
  52. with open("../Wiki/versions.txt", mode="w") as f:
  53. f.write(vrs)
  54. return 1
  55. def sites_update(name):
  56. with open(name+"/docs/supportedsites.md", mode="r") as f:
  57. sites = f.read().splitlines()[1:]
  58. with open("../Wiki/Supported Sites.md", mode="w") as f:
  59. f.write("The following sites, listed alphabetically, are supported by the latest release of %s:\n\n" % name)
  60. f.write("\n".join(sites))
  61. FUNCS = {"dlpage": (build_dlpage, 1), "series-update": (srs_update, 1), "series-make": (srs_make, 1), "series-dep": (srs_dep, 1), "sites-update": (sites_update, 1)}
  62. args = sys.argv[1:]
  63. while len(args) != 0:
  64. cmd = args.pop(0)[2:]
  65. cmd, argcnt = FUNCS[cmd]
  66. argset = args[:argcnt]
  67. args = args[argcnt:]
  68. cmd(*argset)