CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.mit.edu
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.
 
 
 

80 lines
2.6 KiB

  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2020 by The CAT-SOOP Developers <catsoop-dev@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import os
  17. import io
  18. from zipfile import ZipFile, ZIP_DEFLATED
  19. course = cs_form.get("course", None)
  20. def keep_file(full, base):
  21. # ignore nohup output from scripts
  22. if base == "nohup.out":
  23. return False
  24. # ignore compiled python files
  25. if base.endswith(".pyc") or ".pycs" in base:
  26. return False
  27. # ignore vim temporary files and swap files
  28. if base.endswith("~") or base.endswith(".swp"):
  29. return False
  30. # ignore emacs temporary files
  31. if base.startswith("#") and base.endswith("#"):
  32. return False
  33. # ignore Mercurial backup files
  34. if base.endswith(".orig"):
  35. return False
  36. # ignore dotfiles
  37. if base.startswith("."):
  38. return False
  39. # ignore plugins
  40. if "__PLUGINS__" in full:
  41. return False
  42. # ignore config.py in catsoop root
  43. if full == os.path.join(cs_fs_root, "catsoop", "config.py"):
  44. return False
  45. return True
  46. def add_files_to_zip(zipfile, base_dir, zip_base):
  47. for root, dirs, files in os.walk(base_dir):
  48. to_remove = set()
  49. for d in dirs:
  50. if d.startswith(".") or d == "node_modules":
  51. to_remove.add(d)
  52. for d in to_remove:
  53. dirs.remove(d)
  54. for f in files:
  55. fullname = os.path.join(root, f)
  56. if keep_file(fullname, f):
  57. name = fullname.replace(base_dir, zip_base)
  58. zipfile.write(fullname, name)
  59. out_bytes = io.BytesIO()
  60. outfile = ZipFile(out_bytes, "w", ZIP_DEFLATED)
  61. add_files_to_zip(outfile, cs_fs_root, "catsoop-src/catsoop")
  62. now = csm_time.from_detailed_timestamp(cs_timestamp)
  63. now = csm_time.long_timestamp(now).replace("; ", " at ")
  64. outfile.writestr("catsoop-src/README.txt", SOURCE_README % (cs_url_root, now))
  65. outfile.close()
  66. cs_handler = "raw_response"
  67. content_type = "application/zip"
  68. response = out_bytes.getvalue()