wiki.py 2.6 KB

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