Ejemplo 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)
Ejemplo n.º 2
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])
Ejemplo n.º 3
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)
Ejemplo 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
Ejemplo n.º 5
0
    def __init__(self, openshift_env, wp_site_url, full=False, dry_run=False):
        """
        Class constructor

        Argument keywords:
        openshift_env -- Name of OpenShift environment on which script is executed
        wp_site_url -- URL to Website to backup
        full -- Full backup or Inc
        dry_run -- backup simulation
        """
        # validate input
        validate_openshift_env(openshift_env)
        if not wp_site_url.startswith('https://jahia2wp-httpd/'):
            URLValidator()(wp_site_url)

        # setup site and config
        self.wp_site = WPSite(openshift_env, wp_site_url)
        self.wp_config = WPConfig(self.wp_site)

        # set backup attributes
        self.datetime = datetime.datetime.now()
        self.timestamp = self.datetime.strftime(self.TIMESTAMP_FORMAT)
        self.path = os.path.join(self.BACKUP_PATH, self.wp_site.path.replace('/', '_'))
        # set backup type, and name for list file
        listfile = self.get_daily_list()
        if listfile is None or full:
            self.backup_pattern = self.FULL_PATTERN
            self.listfile = os.path.join(
                self.path,
                self.timestamp + ".list")
        else:
            self.backup_pattern = self.INCREMENTAL_PATTERN
            self.listfile = os.path.join(self.path, listfile)

        # set filenames
        self.tarfile = os.path.join(
                self.path,
                "_".join((self.timestamp, self.backup_pattern)) + ".tar.gz")
        self.sqlfile = os.path.join(
                self.path,
                "_".join((self.timestamp, self.backup_pattern)) + ".sql")

        self.dry_run = dry_run
Ejemplo n.º 6
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
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
                    - Field wp_tagline can be :
                    None    -> No information
                    String  -> Same tagline for all languages
                    Dict    -> key=language, value=tagline for language
        admin_password -- (optional) Password to use for 'admin' account
        """

        self._site_params = site_params

        # set the 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 it's not given (it can happen), we initialize the title with a default value so we will be able, later, to
        # set a translation for it.
        if 'wp_site_title' not in self._site_params:
            self._site_params['wp_site_title'] = 'Title'

        # tagline
        if 'wp_tagline' not in self._site_params:
            self._site_params['wp_tagline'] = None
        else:
            # if information is not already in a dict (it happen if info is coming for the source of truth in which
            # we only have tagline in primary language
            if not isinstance(self._site_params['wp_tagline'], dict):
                wp_tagline = {}
                # We loop through languages to generate dict
                for lang in self._site_params['langs'].split(','):
                    # We set tagline for current language
                    wp_tagline[lang] = self._site_params['wp_tagline']
                self._site_params['wp_tagline'] = wp_tagline

        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('from_export', None) is None:
            self._site_params['from_export'] = False

        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'])

        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'],
            from_export=self._site_params['from_export'])

        # 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)