misago-start.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. from optparse import OptionParser
  5. from django.core import management
  6. def start_misago_project():
  7. parser = OptionParser(usage="usage: %prog project_name")
  8. (options, args) = parser.parse_args()
  9. if len(args) != 1:
  10. parser.error("project_name must be specified")
  11. project_name = args[0]
  12. if project_name.startswith("-"):
  13. parser.error("project_name cannot start with '-'")
  14. # Ensure the given directory name doesn't clash with an existing
  15. # Python package/module.
  16. try:
  17. __import__(project_name)
  18. except ImportError:
  19. pass
  20. else:
  21. parser.error("'%s' conflicts with the name of an existing "
  22. "Python module and cannot be used as a project "
  23. "name. Please try another name." % project_name)
  24. MISAGO_PROJECT_TEMPLATE = os.path.join(os.path.dirname(__file__),
  25. 'misago/project_template')
  26. argv = [sys.argv[0], 'startproject', project_name,
  27. '--template=%s' % MISAGO_PROJECT_TEMPLATE]
  28. management.execute_from_command_line(argv)
  29. if __name__ == "__main__":
  30. start_misago_project()