| 1 | #!/usr/bin/env python |
|---|
| 2 | import sys |
|---|
| 3 | import os |
|---|
| 4 | import site |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | def ask_yesno_question(question, default_answer): |
|---|
| 8 | while True: |
|---|
| 9 | prompt = '%s: (yes/no) [%s]: ' % (question, default_answer) |
|---|
| 10 | answer = raw_input(prompt).strip() |
|---|
| 11 | if answer == '': |
|---|
| 12 | return default_answer == 'yes' and True or False |
|---|
| 13 | elif answer in ('yes', 'no'): |
|---|
| 14 | return answer == 'yes' and True or False |
|---|
| 15 | else: |
|---|
| 16 | print 'Please answer yes or no' |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | def fix_merengue_links(): |
|---|
| 20 | cwd = os.getcwd() |
|---|
| 21 | if os.path.islink(os.path.join(cwd, 'merengue')): |
|---|
| 22 | print "We have detected a broked merengue link in project directory\n" |
|---|
| 23 | fix_links = ask_yesno_question("Do you want to try fix merengue links?", "no") |
|---|
| 24 | if not fix_links: |
|---|
| 25 | sys.exit(1) |
|---|
| 26 | while True: |
|---|
| 27 | merengue_path = raw_input("What is the path to merengueproj directory?: ") |
|---|
| 28 | sys.path.append(merengue_path) |
|---|
| 29 | try: |
|---|
| 30 | import merengue |
|---|
| 31 | except ImportError: |
|---|
| 32 | print "In this directory merengue module cannot be imported" |
|---|
| 33 | else: |
|---|
| 34 | break |
|---|
| 35 | merengue_link_path = os.path.join(cwd, 'merengueproj') |
|---|
| 36 | link_src = os.path.realpath(merengue_link_path) |
|---|
| 37 | os.remove(merengue_link_path) |
|---|
| 38 | os.symlink(merengue_path, merengue_link_path) |
|---|
| 39 | print 'Fixing %s, changing from broken "%s" to "%s" location...' % (merengue_link_path, link_src, merengue_path) |
|---|
| 40 | |
|---|
| 41 | try: |
|---|
| 42 | import django |
|---|
| 43 | except ImportError: |
|---|
| 44 | sys.stderr.write("Error: django cannot be found. Make sure you have django installed and in your python path\n") |
|---|
| 45 | sys.exit(1) |
|---|
| 46 | |
|---|
| 47 | try: |
|---|
| 48 | import merengue |
|---|
| 49 | except ImportError: |
|---|
| 50 | sys.stderr.write("Error: merengue cannot be found\n") |
|---|
| 51 | fix_merengue_links() |
|---|
| 52 | |
|---|
| 53 | try: |
|---|
| 54 | import settings # Assumed to be in the same directory. |
|---|
| 55 | except ImportError: |
|---|
| 56 | sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) |
|---|
| 57 | sys.exit(1) |
|---|
| 58 | |
|---|
| 59 | from merengue.base.management import execute_manager |
|---|
| 60 | |
|---|
| 61 | path = site.addsitedir(os.path.join(settings.BASEDIR, "libs"), set()) |
|---|
| 62 | if path: |
|---|
| 63 | sys.path = list(path) + sys.path |
|---|
| 64 | sys.path.insert(0, os.path.join(settings.MERENGUEDIR, "apps")) |
|---|
| 65 | sys.path.insert(0, os.path.join(settings.BASEDIR, "apps")) |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | if __name__ == "__main__": |
|---|
| 69 | execute_manager(settings) |
|---|