createdevproject.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Creates a dev project for local development
  3. """
  4. import os
  5. import sys
  6. from misago.core import setup
  7. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. def main():
  9. project_name = 'devproject'
  10. # Allow for overriding project name
  11. if len(sys.argv) > 1:
  12. project_name = sys.argv[1]
  13. else:
  14. sys.argv.append(project_name)
  15. settings_file = os.path.join(BASE_DIR, project_name, 'settings.py')
  16. # Avoid recreating if already present
  17. if os.path.exists(settings_file):
  18. return
  19. setup.start_misago_project()
  20. fill_in_settings(settings_file)
  21. def fill_in_settings(f):
  22. with open(f, 'r') as fd:
  23. s = fd.read()
  24. # Postgres
  25. s = s.replace("'NAME': '',", "'NAME': os.environ.get('POSTGRES_DB'),")
  26. s = s.replace("'USER': '',", "'USER': os.environ.get('POSTGRES_USER'),")
  27. s = s.replace("'PASSWORD': '',", "'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),")
  28. s = s.replace("'HOST': 'localhost',", "'HOST': os.environ.get('POSTGRES_HOST'),")
  29. # Specify console backend for email
  30. s += "\nEMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'\n"
  31. # Empty the contents of STATICFILES_DIRS (STATICFILES_DIRS = [])
  32. pos = s.find('STATICFILES_DIRS')
  33. s = s[:s.find('[', pos) + 1] + s[s.find(']', pos):]
  34. # Remote theme dir from template dirs
  35. pos = s.find("'DIRS': [")
  36. s = s[:s.find('[', pos) + 1] + s[s.find(']', pos):]
  37. with open(f, 'w') as fd:
  38. fd.write(s)
  39. if __name__ == '__main__':
  40. main()