badcode.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #Copyright (C) 2017 avideo authors (see AUTHORS)
  2. #
  3. # This file is part of AVideo.
  4. #
  5. # AVideo is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # AVideo is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with AVideo. If not, see <http://www.gnu.org/licenses/>.
  17. import os
  18. #Reader Function- used to read fragments from external files, for the sake of cleanliness
  19. def rd(name, lines=1):
  20. with open(name, mode="r") as f:
  21. text = f.read().split("\n", maxsplit=lines)
  22. return text
  23. files, PATCHES = {}, []
  24. for dirname in ("Patches/Perm/", "Patches/Bug/"):
  25. if not os.path.exists(dirname):
  26. continue
  27. for fileX in sorted(os.listdir(dirname)):
  28. if fileX.startswith("g"):
  29. break
  30. else:
  31. comment, link, scab = rd(dirname+fileX, 2)
  32. file, link = comment[1:].split(":", maxsplit=1)[0], link[4:]
  33. if link == "":
  34. link = rd(dirname+"g"+fileX)[1]
  35. else:
  36. link = link.replace("\\n", "\n").replace("\\t", "\t").replace("\z", "")
  37. if file in files.keys():
  38. PATCHES[files[file]].append((scab, link))
  39. else:
  40. files[file] = len(PATCHES)
  41. PATCHES.append([file, (scab, link)])
  42. #The youtube-dl or whatever --> youtu`be-dl or whatever patches in namae.txt
  43. f = open("Patches/namae.txt", mode="r")
  44. segs = f.read().split("\n\n")[1:]
  45. f.close()
  46. for seg in segs:
  47. seglets = seg.split("\n")
  48. SAFECODES = [seglets[0][:-1]]
  49. for seglet in seglets[1:]:
  50. if seglet != "":
  51. SAFECODES.append((seglet, seglet.replace("youtube-dl", "youtu`be-dl")))
  52. PATCHES.append(SAFECODES)