예제 #1
0
    def deploy_askbot(self, options):
        """function that creates django project files,
        all the neccessary directories for askbot,
        and the log file
        """

        create_new_project = True
        if os.path.exists(options['dir_name']) and \
           path_utils.has_existing_django_project(options['dir_name']) and \
           options.force is False:
             create_new_project = False

        options['staticfiles_app'] = "'django.contrib.staticfiles',"
        options['auth_context_processor'] = 'django.contrib.auth.context_processors.auth'

        if create_new_project is True:
            self._create_new_django_project(options['dir_name'], options)

        self._create_new_django_app('askbot_app', options)

        help_file = path_utils.get_path_to_help_file()

        if create_new_project:
            print_message(
                messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
                self.verbosity
            )
        else:
            print_message(
                messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
                self.verbosity
            )
예제 #2
0
파일: __init__.py 프로젝트: maxwward/SCOPE
def deploy_askbot(directory, options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """

    help_file = path_utils.get_path_to_help_file()
    context = {
        'database_name': options.database_name,
        'database_password': options.database_password,
        'database_user': options.database_user,
        'domain_name': options.domain_name,
        'local_settings': options.local_settings,
    }
    if not options.force:
        for key in context.keys():
            if context[key] == None:
                input_message = 'Please enter a value for %s:' \
                    % (key.replace('_', ' '))
                new_value = raw_input(input_message)
                context[key] = new_value

    create_new_project = False
    if os.path.exists(directory):
        if path_utils.has_existing_django_project(directory):
            create_new_project = bool(options.force)
        else:
            create_new_project = True
    else:
        create_new_project = True

    path_utils.create_path(directory)

    if django.VERSION[0] == 1 and django.VERSION[1] < 3:
        #force people install the django-staticfiles app
        context['staticfiles_app'] = ''
    else:
        context['staticfiles_app'] = "'django.contrib.staticfiles',"

    path_utils.deploy_into(
        directory,
        new_project = create_new_project,
        verbosity = options.verbosity,
        context = context
    )

    if create_new_project:
        print_message(
            messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
            options.verbosity
        )
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            options.verbosity
        )
예제 #3
0
def deploy_askbot(options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """
    create_new_project = False
    if os.path.exists(options['dir_name']):
        if path_utils.has_existing_django_project(options['dir_name']):
            create_new_project = bool(options['force'])
        else:
            create_new_project = True
    else:
        create_new_project = True

    path_utils.create_path(options['dir_name'])

    if django.VERSION[0] > 1:
        raise Exception(
            'Django framework with major version > 1 is not supported'
        )

    if django.VERSION[1] < 3:
        #force people install the django-staticfiles app
        options['staticfiles_app'] = ''
    else:
        options['staticfiles_app'] = "'django.contrib.staticfiles',"

    if django.VERSION[1] <=3:
        auth_context_processor = 'django.core.context_processors.auth'
    else:
        auth_context_processor = 'django.contrib.auth.context_processors.auth'
    options['auth_context_processor'] = auth_context_processor

    verbosity = options['verbosity']

    path_utils.deploy_into(
        options['dir_name'],
        new_project=create_new_project,
        verbosity=verbosity,
        context=options
    )

    help_file = path_utils.get_path_to_help_file()

    if create_new_project:
        print_message(
            messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
            verbosity
        )
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            verbosity
        )
예제 #4
0
    def __call__(self): # this is the main part of the original askbot_setup()
      try:
        options = self.parser.parse_args()
        self._set_verbosity(options)
        self._set_create_project(options)
        print_message(messages.DEPLOY_PREAMBLE, self.verbosity)

        # the destination directory
        directory = path_utils.clean_directory(options.dir_name)
        while directory is None:
            directory = path_utils.get_install_directory(force=options.get('force')) # i.e. ask the user
        options.dir_name = directory

        if options.database_engine not in DATABASE_ENGINE_CHOICES:
            options.database_engine = console.choice_dialog(
                'Please select database engine:\n1 - for postgresql, '
                '2 - for sqlite, 3 - for mysql, 4 - oracle',
                choices=DATABASE_ENGINE_CHOICES
            )

        options_dict = vars(options)
        if options.force is False:
            options_dict = collect_missing_options(options_dict)

        database_engine_codes = {
            '1': 'postgresql_psycopg2',
            '2': 'sqlite3',
            '3': 'mysql',
            '4': 'oracle'
        }
        database_engine = database_engine_codes[options.database_engine]
        options_dict['database_engine'] = database_engine

        self.deploy_askbot(options_dict)

        if database_engine == 'postgresql_psycopg2':
            try:
                import psycopg2
            except ImportError:
                print('\nNEXT STEPS: install python binding for postgresql')
                print('pip install psycopg2\n')
        elif database_engine == 'mysql':
            try:
                import _mysql
            except ImportError:
                print('\nNEXT STEP: install python binding for mysql')
                print('pip install mysql-python\n')

      except KeyboardInterrupt:
        print("\n\nAborted.")
        sys.exit(1)
        pass
예제 #5
0
def deploy_askbot(directory, options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """

    help_file = path_utils.get_path_to_help_file()
    context = {
        'database_name': options.database_name,
        'database_password': options.database_password,
        'database_user': options.database_user,
        'domain_name': options.domain_name,
        'local_settings': options.local_settings,
    }
    if not options.force:
        for key in context.keys():
            if context[key] == None:
                input_message = 'Please enter a value for %s:' \
                    % (key.replace('_', ' '))
                new_value = raw_input(input_message)
                context[key] = new_value

    create_new_project = False
    if os.path.exists(directory):
        if path_utils.has_existing_django_project(directory):
            create_new_project = bool(options.force)
        else:
            create_new_project = True
    else:
        create_new_project = True

    path_utils.create_path(directory)

    if django.VERSION[0] == 1 and django.VERSION[1] < 3:
        #force people install the django-staticfiles app
        context['staticfiles_app'] = ''
    else:
        context['staticfiles_app'] = "'django.contrib.staticfiles',"

    path_utils.deploy_into(directory,
                           new_project=create_new_project,
                           verbosity=options.verbosity,
                           context=context)

    if create_new_project:
        print_message(messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
                      options.verbosity)
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            options.verbosity)
예제 #6
0
    def _create_new_django_app(self, app_name, options):
        options['askbot_site'] = options['dir_name']
        options['askbot_app']  = app_name
        app_dir =  os.path.join(options['dir_name'], app_name)

        create_me = [ app_dir ]
        copy_me   = list()
        render_me = list()

        if 'django' in self._todo.get('create_project',[]):
            src = lambda x:os.path.join(self.SOURCE_DIR, 'setup_templates', x)
            dst = lambda x:os.path.join(app_dir, x)
            copy_me.extend([
                ( src(file_name), dst(file_name) )
                for file_name in self.APP_FILES_TO_CREATE
                ])
            render_me.extend([
                ( src('settings.py.jinja2'), dst('settings.py') )
                ])

        if 'container-uwsgi' in self._todo.get('create_project',[]):
            src = lambda x:os.path.join(self.SOURCE_DIR, 'container', x)
            dst = lambda x:os.path.join(app_dir, x)
            copy_me.extend([
                ( src(file_name), dst(file_name) )
                for file_name in [ 'cron-askbot.sh', 'prestart.sh', 'prestart.py' ]
            ])
            render_me.extend([
                ( src(file_name), dst(file_name) )
                for file_name in [ 'crontab', 'uwsgi.ini' ]
            ])

        for d in create_me:
            path_utils.create_path(d)

        self._install_copy(copy_me, skip_silently=path_utils.BLANK_FILES,
                                    forced_overwrite=['urls.py'])

        self._install_render_with_jinja2(render_me, options)

        if len(options['local_settings']) > 0 \
        and os.path.exists(options['local_settings']):
            dst = os.path.join(app_dir, 'settings.py')
            print_message(f'Appending {options["local_settings"]} to {dst}', self.verbosity)
            with open(dst, 'a') as settings_file:
                with open(context['local_settings'], 'r') as local_settings:
                    settings_file.write('\n')
                    settings_file.write(local_settings.read())
            print_message('Done.', self.verbosity)
예제 #7
0
 def _install_copy(self, copy_list, forced_overwrite=[], skip_silently=[]):
     print_message('Copying files:', self.verbosity)
     for src,dst in copy_list:
         print_message(f'* to {dst} from {src}', self.verbosity)
         if not os.path.exists(dst):
             shutil.copy(src, dst)
             continue
         matches = [ dst for c in forced_overwrite
                         if dst.endswith(f'{os.path.sep}{c}') ]
         if len(matches) > 0:
             print_message('  ^^^ forced overwrite!', self.verbosity)
             shutil.copy(src, dst)
         elif dst.split(os.path.sep)[-1] not in skip_silently:
             print_message(f'  ^^^ you already have one, please add contents of {src_file}', self.verbosity)
     print_message('Done.', self.verbosity)
예제 #8
0
 def _install_render_with_jinja2(self, render_list, context):
     print_message('Rendering files:', self.verbosity)
     template = DeploymentTemplate('dummy.name') # we use this a little differently than originally intended
     for src, dst in render_list:
         if os.path.exists(dst):
             print_message(f'* you already have a file "{dst}" please merge the contents', self.verbosity)
             continue
         print_message(f'*    {dst} from {src}', self.verbosity)
         template.tmpl_path = src
         output = template.render(context)
         with open(dst, 'w+') as output_file:
             output_file.write(output)
     print_message('Done.', self.verbosity)
예제 #9
0
def deploy_askbot(options):
    """function that creates django project files,
    all the neccessary directories for askbot,
    and the log file
    """
    create_new_project = True
    if os.path.exists(options['dir_name']):
        if path_utils.has_existing_django_project(options['dir_name']):
            create_new_project = bool(options['force'])

    path_utils.create_path(options['dir_name'])

    options['staticfiles_app'] = "'django.contrib.staticfiles',"

    options['auth_context_processor'] = 'django.contrib.auth.context_processors.auth'

    verbosity = options['verbosity']

    path_utils.deploy_into(
        options['dir_name'],
        new_project=create_new_project,
        verbosity=verbosity,
        context=options
    )

    help_file = path_utils.get_path_to_help_file()

    if create_new_project:
        print_message(
            messages.HOW_TO_DEPLOY_NEW % {'help_file': help_file},
            verbosity
        )
    else:
        print_message(
            messages.HOW_TO_ADD_ASKBOT_TO_DJANGO % {'help_file': help_file},
            verbosity
        )