You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

  1. import os
  2. import shutil
  3. def toFileList(text):
  4. lines = text.splitlines()
  5. files = []
  6. stack = []
  7. def push(val):
  8. pre = ''
  9. if len(stack) > 0:
  10. pre = stack[-1]
  11. stack.append(pre + val)
  12. def pop():
  13. return stack.pop()
  14. def replace(val):
  15. val2 = pop()
  16. push(val)
  17. return val2
  18. for line in lines:
  19. spl = line.split('"');
  20. spath = spl[-1]
  21. semis = len(spl[:-1])
  22. if spath.startswith('::'):
  23. spl = spath.split(' ')
  24. cmd = spl[0][2:]
  25. if cmd == 'from': # basically just import
  26. content = ''
  27. with open(' '.join(spl[1:]),'r') as f:
  28. content = f.read()
  29. spath = content
  30. elif cmd == 'prompt':
  31. spath = input(' '.join(spl[1:]))
  32. else:
  33. spath = ''
  34. print("No such command", cmd)
  35. if semis > (len(stack)-1):
  36. push(spath)
  37. elif semis == (len(stack)-1):
  38. files.append(replace(spath))
  39. elif semis < (len(stack)-1):
  40. files.append(pop())
  41. while semis < (len(stack)):
  42. pop()
  43. push(spath)
  44. files.append(pop())
  45. return files
  46. if __name__ == '__main__':
  47. file = ''
  48. with open("refs.txt","r") as f:
  49. file = f.read()
  50. refs = toFileList(file)
  51. tgtDir = "target/"
  52. shutil.rmtree(tgtDir, ignore_errors=True)
  53. if not os.path.exists(tgtDir):
  54. os.makedirs(tgtDir)
  55. for filename in refs:
  56. if (os.path.isfile(filename)):
  57. print("Copying",filename)
  58. shutil.copy(filename, tgtDir)