示例#1
0
    def handle(self, *args, **options):
        answer = None
        while not answer or answer not in "yn":
            answer = six.moves.input("Include sample games? (y or n): ")
            if not answer:
                answer = "y"
                break
            else:
                answer = answer[0].lower()

        self.core_project_template_path = os.path.join(
            os.path.dirname(otree.__file__), 'project_template')
        if answer == "y":
            project_template_path = "https://github.com/oTree-org/oTree/archive/master.zip"
        else:
            project_template_path = self.core_project_template_path
        if options.get('template', None) is None:
            options['template'] = project_template_path
        super(Command, self).handle(*args, **options)

        self.modify_project_files(options)
        try:
            check_pypi_for_updates()
        except:
            pass
        print('Created project folder.')
示例#2
0
    def handle(self, *args, **options):
        answer = None
        while not answer or answer not in "yn":
            answer = six.moves.input("Include sample games? (y or n): ")
            if not answer:
                answer = "y"
                break
            else:
                answer = answer[0].lower()

        self.core_project_template_path = os.path.join(
                os.path.dirname(otree.__file__), 'project_template')
        if answer == "y":
            project_template_path = "https://github.com/oTree-org/oTree/archive/master.zip"
        else:
            project_template_path = self.core_project_template_path
        if options.get('template', None) is None:
            options['template'] = project_template_path
        super(Command, self).handle(*args, **options)


        self.modify_project_files(options)
        try:
            check_pypi_for_updates()
        except:
            pass
        print('Created project folder.')
示例#3
0
 def handle(self, *args, **options):
     if options.get('template', None) is None:
         options['template'] = self.get_default_template()
     super(Command, self).handle(*args, **options)
     try:
         check_pypi_for_updates()
     except:
         pass
示例#4
0
 def handle(self, *args, **options):
     if options.get('template', None) is None:
         options['template'] = self.get_default_template()
     super(Command, self).handle(*args, **options)
     try:
         check_pypi_for_updates()
     except:
         pass
     print('Created app folder.')
示例#5
0
    def get_context_data(self, **kwargs):
        sqlite = settings.DATABASES['default']['ENGINE'].endswith('sqlite3')
        debug = settings.DEBUG
        update_message = check_pypi_for_updates(print_message=False)
        regular_sentry = hasattr(settings, 'RAVEN_CONFIG')
        heroku_sentry = os.environ.get('SENTRY_DSN')
        sentry = regular_sentry or heroku_sentry
        auth_level = settings.AUTH_LEVEL in {'DEMO', 'STUDY'}
        celery = self.celery_is_running()
        heroku = self.app_is_on_heroku()

        return {
            'sqlite': sqlite,
            'debug': debug,
            'update_message': update_message,
            'sentry': sentry,
            'auth_level': auth_level,
            'celery': celery,
            'heroku': heroku
        }
示例#6
0
    def get_context_data(self, **kwargs):
        sqlite = settings.DATABASES['default']['ENGINE'].endswith('sqlite3')
        debug = settings.DEBUG
        update_message = check_pypi_for_updates(print_message=False)
        otree_version = otree.__version__
        regular_sentry = hasattr(settings, 'RAVEN_CONFIG')
        heroku_sentry = os.environ.get('SENTRY_DSN')
        sentry = regular_sentry or heroku_sentry
        auth_level = settings.AUTH_LEVEL in {'DEMO', 'STUDY'}
        heroku = self.app_is_on_heroku()
        runserver = 'runserver' in sys.argv

        return {
            'sqlite': sqlite,
            'debug': debug,
            'update_message': update_message,
            'otree_version': otree_version,
            'sentry': sentry,
            'auth_level': auth_level,
            'heroku': heroku,
            'runserver': runserver,
        }
示例#7
0
文件: admin.py 项目: jpg75/otree-core
    def get_context_data(self, **kwargs):
        sqlite = settings.DATABASES['default']['ENGINE'].endswith('sqlite3')
        debug = settings.DEBUG
        update_message = check_pypi_for_updates(print_message=False)
        otree_version = otree.__version__
        regular_sentry = hasattr(settings, 'RAVEN_CONFIG')
        heroku_sentry = os.environ.get('SENTRY_DSN')
        sentry = regular_sentry or heroku_sentry
        auth_level = settings.AUTH_LEVEL in {'DEMO', 'STUDY'}
        heroku = self.app_is_on_heroku()
        runserver = 'runserver' in sys.argv

        return {
            'sqlite': sqlite,
            'debug': debug,
            'update_message': update_message,
            'otree_version': otree_version,
            'sentry': sentry,
            'auth_level': auth_level,
            'heroku': heroku,
            'runserver': runserver,
        }
示例#8
0
    def get_context_data(self, **kwargs):
        sqlite = settings.DATABASES['default']['ENGINE'].endswith('sqlite3')
        debug = settings.DEBUG
        regular_sentry = hasattr(settings, 'RAVEN_CONFIG')
        heroku_sentry = os.environ.get('SENTRY_DSN')
        sentry = regular_sentry or heroku_sentry
        auth_level = settings.AUTH_LEVEL in {'DEMO', 'STUDY'}
        heroku = self.app_is_on_heroku()
        runserver = 'runserver' in sys.argv
        db_synced = db_status_ok()
        pypi_results = check_pypi_for_updates()

        return {
            'sqlite': sqlite,
            'debug': debug,
            'sentry': sentry,
            'auth_level': auth_level,
            'heroku': heroku,
            'runserver': runserver,
            'db_synced': db_synced,
            'pypi_results': pypi_results
        }
示例#9
0
    def get_context_data(self, **kwargs):
        sqlite = settings.DATABASES['default']['ENGINE'].endswith('sqlite3')
        debug = settings.DEBUG
        regular_sentry = hasattr(settings, 'RAVEN_CONFIG')
        heroku_sentry = os.environ.get('SENTRY_DSN')
        sentry = regular_sentry or heroku_sentry
        auth_level = settings.AUTH_LEVEL
        auth_level_ok = settings.AUTH_LEVEL in {'DEMO', 'STUDY'}
        heroku = self.app_is_on_heroku()
        runserver = 'runserver' in sys.argv
        db_synced = db_status_ok()
        pypi_results = check_pypi_for_updates()

        return {
            'sqlite': sqlite,
            'debug': debug,
            'sentry': sentry,
            'auth_level': auth_level,
            'auth_level_ok': auth_level_ok,
            'heroku': heroku,
            'runserver': runserver,
            'db_synced': db_synced,
            'pypi_results': pypi_results
        }
示例#10
0
def execute_from_command_line(arguments, script_file):

    try:
        subcommand = arguments[1]
    except IndexError:
        subcommand = 'help'  # default

    # Workaround for windows. Celery (more precicely the billard library) will
    # complain if the script you are using to initialize celery does not end
    # on '.py'. That's why we require a manage.py file to be around.
    # See https://github.com/celery/billiard/issues/129 for more details.
    cond = (
        platform.system() == 'Windows' and
        not script_file.lower().endswith('.py') and
        subcommand not in NO_SETTINGS_COMMANDS
    )

    if cond:

        scriptdir = os.path.dirname(os.path.abspath(script_file))
        managepy = os.path.join(scriptdir, 'manage.py')
        if not os.path.exists(managepy):
            error_lines = []

            error_lines.append(
                "It seems that you do not have a file called 'manage.py' in "
                "your current directory. This is a requirement when using "
                "otree on windows."
            )
            error_lines.append("")
            error_lines.append("")
            error_lines.append(
                "Please download the file {url} and save it as 'manage.py' in "
                "the directory {directory}".format(
                    url=MANAGE_URL, directory=scriptdir))
            raise CommandError("\n".join(error_lines))
        args = [sys.executable] + [managepy] + arguments[1:]
        process = subprocess.Popen(args,
                                   stdin=sys.stdin,
                                   stdout=sys.stdout,
                                   stderr=sys.stderr)
        return_code = process.wait()
        sys.exit(return_code)

    # in issue #300 we agreed that sslserver should
    # run only if user has specified credentials for AWS
    # 2016-05-27: not working because we switched to Daphne
    '''
    runsslserver = (
        len(arguments) >= 2 and arguments[1] == 'runserver' and
        settings.AWS_ACCESS_KEY_ID
    )
    if runsslserver:
        arguments[1] = 'runsslserver'
        sys.stdout.write(
            'Note: your server URL will start with https, not http '
            '(because the env var AWS_ACCESS_KEY_ID was found)\n')
    '''
    # only monkey patch when is necesary
    if "version" in arguments or "--version" in arguments:
        sys.stdout.write(otree_and_django_version() + '\n')
        try:
            check_pypi_for_updates()
        except:
            pass
    else:
        utility = OTreeManagementUtility(arguments)
        utility.execute()
示例#11
0
 def get(self, request, *args, **kwargs):
     if OtreeCoreUpdateCheck.results is None:
         OtreeCoreUpdateCheck.results = check_pypi_for_updates()
     return JsonResponse(OtreeCoreUpdateCheck.results, safe=True)
示例#12
0
 def get(self, request, *args, **kwargs):
     if OtreeCoreUpdateCheck.results is None:
         OtreeCoreUpdateCheck.results = check_pypi_for_updates()
     return JsonResponse(OtreeCoreUpdateCheck.results, safe=True)
示例#13
0
def execute_from_command_line(arguments, script_file):

    try:
        subcommand = arguments[1]
    except IndexError:
        subcommand = 'help'  # default

    # Workaround for windows. Celery (more precicely the billard library) will
    # complain if the script you are using to initialize celery does not end
    # on '.py'. That's why we require a manage.py file to be around.
    # See https://github.com/celery/billiard/issues/129 for more details.
    cond = (platform.system() == 'Windows'
            and not script_file.lower().endswith('.py')
            and subcommand not in NO_SETTINGS_COMMANDS)

    if cond:

        scriptdir = os.path.dirname(os.path.abspath(script_file))
        managepy = os.path.join(scriptdir, 'manage.py')
        if not os.path.exists(managepy):
            error_lines = []

            error_lines.append(
                "It seems that you do not have a file called 'manage.py' in "
                "your current directory. This is a requirement when using "
                "otree on windows.")
            error_lines.append("")
            error_lines.append("")
            error_lines.append(
                "Please download the file {url} and save it as 'manage.py' in "
                "the directory {directory}".format(url=MANAGE_URL,
                                                   directory=scriptdir))
            raise CommandError("\n".join(error_lines))
        args = [sys.executable] + [managepy] + arguments[1:]
        process = subprocess.Popen(args,
                                   stdin=sys.stdin,
                                   stdout=sys.stdout,
                                   stderr=sys.stderr)
        return_code = process.wait()
        sys.exit(return_code)

    # in issue #300 we agreed that sslserver should
    # run only if user has specified credentials for AWS
    runsslserver = (len(arguments) >= 2 and arguments[1] == 'runserver'
                    and settings.AWS_ACCESS_KEY_ID)
    if runsslserver:
        arguments[1] = 'runsslserver'
        sys.stdout.write(
            'Note: your server URL will start with https, not http '
            '(because the env var AWS_ACCESS_KEY_ID was found)\n')

    # only monkey patch when is necesary
    if "version" in arguments or "--version" in arguments:
        sys.stdout.write(otree_and_django_version() + '\n')
        try:
            check_pypi_for_updates()
        except:
            pass
    else:
        utility = OTreeManagementUtility(arguments)
        utility.execute()