source: sites/merengueprojectorg/manage.py @ 1329

Revision 1329, 2.5 KB checked in by msaelices, 2 years ago (diff)

First step to adapt merengueproject.org to new directories. See #522.
no-pyflakes.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2import sys
3import os
4import site
5
6
7def 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
19def 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
41try:
42    import django
43except 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
47try:
48    import merengue
49except ImportError:
50    sys.stderr.write("Error: merengue cannot be found\n")
51    fix_merengue_links()
52
53try:
54    import settings # Assumed to be in the same directory.
55except 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
59from merengue.base.management import execute_manager
60
61path = site.addsitedir(os.path.join(settings.BASEDIR, "libs"), set())
62if path:
63    sys.path = list(path) + sys.path
64sys.path.insert(0, os.path.join(settings.MERENGUEDIR, "apps"))
65sys.path.insert(0, os.path.join(settings.BASEDIR, "apps"))
66
67
68if __name__ == "__main__":
69    execute_manager(settings)
Note: See TracBrowser for help on using the repository browser.