Exemple #1
0
def rotate_backup_inventory(path, dry_run=False, **kwargs):

    if dry_run:
        logging.info("! DRY RUN !")

    for site_details in WPConfig.inventory(path):

        if site_details.valid == settings.WP_SITE_INSTALL_OK:

            try:
                path = WPBackup(
                    WPSite.openshift_env_from_path(site_details.path),
                    site_details.url).path

                # rotate full backups first
                for pattern in [["*full.sql"], ["*full.tar", "*full.tar.gz"]]:

                    RotateBackups(FULL_BACKUP_RETENTION_THEME,
                                  dry_run=dry_run,
                                  include_list=pattern).rotate_backups(path)
                # rotate incremental backups
                for pattern in [["*.list"], ["*inc.sql"],
                                ["*inc.tar", "*inc.tar.gz"]]:

                    RotateBackups(INCREMENTAL_BACKUP_RETENTION_THEME,
                                  dry_run=dry_run,
                                  include_list=pattern).rotate_backups(path)

            except:

                logging.error("Site %s - Error %s", site_details.url,
                              sys.exc_info())
Exemple #2
0
def backup_inventory(path, dry_run=False, **kwargs):
    """
    Backup all WordPress instances found in a given path
    :param path:
    :param dry_run:
    :param kwargs:
    :return:
    """
    if dry_run:
        logging.info("! DRY RUN !")
    logging.info("Backup from inventory...")

    for site_details in WPConfig.inventory(path):

        if site_details.valid == settings.WP_SITE_INSTALL_OK:

            logging.info("Running backup for %s", site_details.url)
            try:
                WPBackup(WPSite.openshift_env_from_path(site_details.path),
                         site_details.url,
                         dry_run=dry_run).backup()
            except:
                logging.error("Site %s - Error %s", site_details.url,
                              sys.exc_info())

    logging.info("All backups done for path: %s", path)
Exemple #3
0
def update_plugins_inventory(path,
                             plugin=None,
                             force_plugin=False,
                             force_options=False,
                             strict_list=False,
                             extra_config=None,
                             **kwargs):

    logging.info("Update plugins from inventory...")

    for site_details in WPConfig.inventory(path):

        if site_details.valid == settings.WP_SITE_INSTALL_OK:
            logging.info("Updating plugins for %s", site_details.url)

            all_params = {
                'openshift_env':
                WPSite.openshift_env_from_path(site_details.path),
                'wp_site_url': site_details.url
            }

            # if we have extra configuration to load,
            if extra_config is not None:
                all_params = _add_extra_config(extra_config, all_params)

            WPGenerator(all_params).update_plugins(
                only_one=plugin,
                force_plugin=force_plugin,
                force_options=force_options,
                strict_plugin_list=strict_list)

    logging.info("All plugins updates done for path: %s", path)
Exemple #4
0
    def locate_existing(self, path):
        """
        Locate all existing shortcodes in a given path. Go through all WordPress installs and parse pages to extract
        shortcode list.
        :param path: path where to start search
        :return:
        """

        for site_details in WPConfig.inventory(path):

            if site_details.valid == settings.WP_SITE_INSTALL_OK:

                logging.info("Checking %s...", site_details.url)

                try:

                    # Getting site posts
                    post_ids = Utils.run_command("wp post list --post_type=page --format=csv --fields=ID "
                                                 "--skip-plugins --skip-themes --path={}".format(site_details.path))

                except Exception as e:
                    logging.error("Error getting page list, skipping to next site: %s", str(e))
                    continue

                # Getting list of registered shortcodes to be sure to list only registered and not all strings
                # written between [ ]
                registered_shortcodes = self._get_site_registered_shortcodes(site_details.path)

                if not post_ids:
                    continue

                post_ids = post_ids.split('\n')[1:]

                logging.debug("%s pages to analyze...", len(post_ids))

                # Looping through posts
                for post_id in post_ids:
                    try:
                        content = Utils.run_command("wp post get {} --field=post_content --skip-plugins --skip-themes "
                                                    "--path={}".format(post_id, site_details.path))
                    except Exception as e:
                        logging.error("Error getting page, skipping to next page: %s", str(e))
                        continue

                    # Looking for all shortcodes in current post
                    for shortcode in re.findall(self.regex, content):

                        # This is not a registered shortcode
                        if shortcode not in registered_shortcodes:
                            continue

                        if shortcode not in self.list:
                            self.list[shortcode] = []

                        if site_details.path not in self.list[shortcode]:
                            self.list[shortcode].append(site_details.path)
Exemple #5
0
def inventory(wp_env, path, **kwargs):
    logging.info("Building inventory...")
    print(";".join(
        ['path', 'valid', 'url', 'version', 'db_name', 'db_user', 'admins']))
    for site_details in WPConfig.inventory(wp_env, path):
        print(";".join([
            site_details.path, site_details.valid, site_details.url,
            site_details.version, site_details.db_name, site_details.db_user,
            site_details.admins
        ]))
    logging.info("Inventory made for %s", path)
Exemple #6
0
    def get_details(self, path, shortcode_list):
        """
        Locate all instance of given shortcode in a given path. Go through all WordPress installs and parse pages to
        extract shortcode details
        :param path: path where to start search
        :param shortcode_list: list with shortcode name to look for
        :return: Dict - Key is WP site URL and value is a list of dict containing shortcode infos.
        """

        # Building "big" regex to match all given shortcodes
        regexes = []
        for shortcode in shortcode_list:
            regexes.append('\[{}\s?.*?\]'.format(shortcode))

        regex = re.compile('|'.join(regexes), re.VERBOSE)

        shortcode_details = {}

        for site_details in WPConfig.inventory(path):

            if site_details.valid == settings.WP_SITE_INSTALL_OK:

                logging.info("Checking %s...", site_details.url)

                try:
                    # Getting site posts
                    post_ids = Utils.run_command("wp post list --post_type=page --format=csv --fields=ID "
                                                 "--skip-plugins --skip-themes --path={}".format(site_details.path))

                    if not post_ids:
                        continue

                    post_ids = post_ids.split('\n')[1:]

                    # Looping through posts
                    for post_id in post_ids:
                        content = Utils.run_command("wp post get {} --field=post_content --skip-plugins --skip-themes "
                                                    "--path={}".format(post_id, site_details.path))

                        # Looking for given shortcode in current post
                        for shortcode_with_args in re.findall(regex, content):

                            if site_details.path not in shortcode_details:
                                shortcode_details[site_details.path] = []

                            post_url = '{}/wp-admin/post.php?post={}&action=edit'.format(site_details.url, post_id)
                            shortcode_details[site_details.path].append({'post_url': post_url,
                                                                         'shortcode_call': shortcode_with_args})

                except Exception as e:
                    logging.error("Error, skipping to next site: %s", str(e))
                    pass

        return shortcode_details
Exemple #7
0
def backup_inventory(path, **kwargs):

    logging.info("Backup from inventory...")

    for site_details in WPConfig.inventory(path):

        if site_details.valid == settings.WP_SITE_INSTALL_OK:

            logging.info("Running backup for %s", site_details.url)
            try:
                WPBackup(WPSite.openshift_env_from_path(site_details.path),
                         site_details.url).backup()
            except:
                logging.error("Site %s - Error %s", site_details.url,
                              sys.exc_info())

    logging.info("All backups done for path: %s", path)