Exemplo n.º 1
0
    def __init__(self,
                 openshift_env,
                 wp_site_url,
                 wp_default_site_title=None,
                 backup_type=None):
        """
        Class constructor

        Argument keywords:
        openshift_env -- Name of OpenShift environment on which script is executed
        wp_site_url -- URL to Website to backup
        wp_default_site_title -- (optional) website title
        backup_type -- (optional) Backup type to do. 'inc' or 'full'
        """
        # validate input
        validate_openshift_env(openshift_env)
        URLValidator()(wp_site_url)
        if wp_default_site_title is not None:
            validate_string(wp_default_site_title)
        if backup_type is not None:
            validate_backup_type(backup_type)

        # setup site and config
        self.wp_site = WPSite(openshift_env,
                              wp_site_url,
                              wp_default_site_title=wp_default_site_title)
        self.wp_config = WPConfig(self.wp_site)
        self.type = backup_type or self.DEFAULT_TYPE

        # Create a backup folder data/backups/wp_site_name
        self.path = os.path.join(settings.BACKUP_PATH, self.wp_site.name)
Exemplo n.º 2
0
    def __init__(self,
                 openshift_env,
                 wp_site_url,
                 wp_default_site_title=None,
                 unit_name=None,
                 installs_locked=settings.DEFAULT_CONFIG_INSTALLS_LOCKED,
                 updates_automatic=settings.DEFAULT_CONFIG_UPDATES_AUTOMATIC,
                 admin_password=None,
                 theme=settings.DEFAULT_THEME_NAME,
                 theme_faculty=None):
        """
        Class constructor

        Argument keywords:
        openshift_env -- Name of OpenShift environment on which script is executed
        wp_site_url -- Website URL
        wp_default_site_title -- (optional) website title
        admin_password -- (optional) Password to use for 'admin' account
        theme -- (optional) WordPress Theme name
        theme_faculty -- (optional) Faculty name to use with theme (to select color)
        """
        # validate input
        self.validate_mockable_args(wp_site_url, unit_name)
        validate_openshift_env(openshift_env)
        if wp_default_site_title is not None:
            validate_string(wp_default_site_title)
        if theme is not None:
            validate_theme(theme)
        if theme_faculty is not None:
            validate_theme_faculty(theme_faculty)

        # create WordPress site and config
        self.wp_site = WPSite(openshift_env,
                              wp_site_url,
                              wp_default_site_title=wp_default_site_title)
        self.wp_config = WPConfig(self.wp_site,
                                  installs_locked=installs_locked,
                                  updates_automatic=updates_automatic)

        # prepare admin for exploitation/maintenance
        self.wp_admin = WPUser(self.WP_ADMIN_USER, self.WP_ADMIN_EMAIL)
        self.wp_admin.set_password(password=admin_password)

        # plugin configuration
        self.plugin_config_custom = {
            'unit_name': unit_name,
            'unit_id': self.get_the_unit_id(unit_name)
        }

        # Theme configuration
        self.theme = theme or settings.DEFAULT_THEME_NAME
        self.theme_faculty = None if theme_faculty == '' else theme_faculty

        # create mysql credentials
        self.wp_db_name = Utils.generate_name(self.DB_NAME_LENGTH,
                                              prefix='wp_').lower()
        self.mysql_wp_user = Utils.generate_name(
            self.MYSQL_USER_NAME_LENGTH).lower()
        self.mysql_wp_password = Utils.generate_password(
            self.MYSQL_PASSWORD_LENGTH)
Exemplo n.º 3
0
    def __init__(self, openshift_env, wp_site_url, wp_site_title=None, wp_tagline=None):
        """
        Class constructor
        :param openshift_env: name of openshift environement
        :param wp_site_url: WordPress website URL
        :param wp_site_title: WordPress website title (same for all languages)
        :param wp_tagline: Dict with langs as key and tagline as value
        """
        # validate & transform args
        self.openshift_env = openshift_env.lower()
        url = urlparse(wp_site_url.lower())

        validate_openshift_env(self.openshift_env)
        if wp_site_title is not None:
            validate_string(wp_site_title)

        # set WP information
        self.domain = url.netloc.strip('/')
        self.folder = url.path.strip('/')
        self.wp_site_title = wp_site_title or self.DEFAULT_TITLE
        # If parameter not given
        if not wp_tagline:
            self.wp_tagline = self.DEFAULT_TAGLINE
        # Parameter given (dict)
        else:
            self.wp_tagline = wp_tagline
            # We check given information to be sure that we don't have a 'None' given
            for lang, wp_tagline in self.wp_tagline.items():
                if not wp_tagline:
                    self.wp_tagline[lang] = self.DEFAULT_TAGLINE
                validate_string(self.wp_tagline[lang])
Exemplo n.º 4
0
    def __init__(self, openshift_env, wp_site_url, wp_default_site_title=None):

        # validate env and title
        validate_openshift_env(openshift_env)
        if wp_default_site_title is not None:
            validate_string(wp_default_site_title)

        # extract domain and folder from given url
        url = urlparse(wp_site_url)

        self.openshift_env = openshift_env

        # set WP informations
        self.domain = url.netloc.strip('/')
        self.folder = url.path.strip('/')
        self.wp_default_site_title = wp_default_site_title or self.DEFAULT_TITLE
Exemplo n.º 5
0
    def __init__(self,
                 openshift_env,
                 wp_site_url,
                 wp_site_title=None,
                 wp_tagline=None):

        # validate & transform args
        self.openshift_env = openshift_env.lower()
        url = urlparse(wp_site_url.lower())

        validate_openshift_env(self.openshift_env)
        if wp_site_title is not None:
            validate_string(wp_site_title)

        if wp_tagline is not None:
            validate_string(wp_tagline)

        # set WP informations
        self.domain = url.netloc.strip('/')
        self.folder = url.path.strip('/')
        self.wp_site_title = wp_site_title or self.DEFAULT_TITLE
        self.wp_tagline = wp_tagline or self.DEFAULT_TAGLINE
Exemplo n.º 6
0
    def __init__(self, site_params, admin_password=None):
        """
        Class constructor

        Argument keywords:
        site_params -- dict with row coming from CSV file (source of truth)
        admin_password -- (optional) Password to use for 'admin' account
        """

        self._site_params = site_params

        # Setting default values
        if 'unit_name' in self._site_params and 'unit_id' not in self._site_params:
            logging.info(
                "WPGenerator.__init__(): Please use 'unit_id' from CSV file (now recovered from 'unit_name')"
            )
            self._site_params['unit_id'] = self.get_the_unit_id(
                self._site_params['unit_name'])

        if 'wp_site_title' not in self._site_params:
            self._site_params['wp_site_title'] = None

        if 'wp_tagline' not in self._site_params:
            self._site_params['wp_tagline'] = None

        if self._site_params.get('installs_locked', None) is None:
            self._site_params[
                'installs_locked'] = settings.DEFAULT_CONFIG_INSTALLS_LOCKED

        if self._site_params.get('updates_automatic', None) is None:
            self._site_params[
                'updates_automatic'] = settings.DEFAULT_CONFIG_UPDATES_AUTOMATIC

        if self._site_params.get('theme', None) is None:
            self._site_params['theme'] = settings.DEFAULT_THEME_NAME

        if ('theme_faculty' not in self._site_params
                or ('theme_faculty' in self._site_params
                    and self._site_params['theme_faculty'] == '')):
            self._site_params['theme_faculty'] = None

        if self._site_params.get('openshift_env') is None:
            self._site_params['openshift_env'] = settings.OPENSHIFT_ENV

        # validate input
        self.validate_mockable_args(self._site_params['wp_site_url'])
        validate_openshift_env(self._site_params['openshift_env'])

        if self._site_params['wp_site_title'] is not None:
            validate_string(self._site_params['wp_site_title'])

        if self._site_params['wp_tagline'] is not None:
            validate_string(self._site_params['wp_tagline'])

        validate_theme(self._site_params['theme'])

        if self._site_params['theme_faculty'] is not None:
            validate_theme_faculty(self._site_params['theme_faculty'])

        # create WordPress site and config
        self.wp_site = WPSite(self._site_params['openshift_env'],
                              self._site_params['wp_site_url'],
                              wp_site_title=self._site_params['wp_site_title'],
                              wp_tagline=self._site_params['wp_tagline'])
        self.wp_config = WPConfig(
            self.wp_site,
            installs_locked=self._site_params['installs_locked'],
            updates_automatic=self._site_params['updates_automatic'])

        # prepare admin for exploitation/maintenance
        self.wp_admin = WPUser(self.WP_ADMIN_USER, self.WP_ADMIN_EMAIL)
        self.wp_admin.set_password(password=admin_password)

        # create mysql credentials
        self.wp_db_name = Utils.generate_name(self.DB_NAME_LENGTH,
                                              prefix='wp_').lower()
        self.mysql_wp_user = Utils.generate_name(
            self.MYSQL_USER_NAME_LENGTH).lower()
        self.mysql_wp_password = Utils.generate_password(
            self.MYSQL_PASSWORD_LENGTH)