def __build_yum_config(self, repoid):
        """
        Builds the YUM config that will be used for YUM initialization.

        @param repoid   The ID of repository to be analyzed.

        @return The path to generated YUM config file.
        """
        config_path = temporaries.create_temporary_file("yum.conf")
        config = ConfigParser()
        # FIXME: This config was get from my Ubuntu default yum config, maybe
        # we should somehow modify it.
        config.add_section("main")
        cache_path = temporaries.create_temporary_directory("yum.cache")
        config.set("main", "cachedir", cache_path)
        config.set("main", "keepcache", "1")
        config.set("main", "debuglevel", "2")
        log_path = temporaries.create_temporary_file("yum.log")
        config.set("main", "logfile", log_path)
        # FIXME: Is this a reason why ARM RPMs are ignored?
        config.set("main", "exactarch", "1")
        config.set("main", "obsoletes", "1")

        config.add_section(repoid)
        config.set(repoid, "name", "Analyzed repository")
        config.set(repoid, "baseurl",
                   "file://{0}".format(self.repository_path))

        with open(config_path, "w") as config_file:
            config.write(config_file)
            config_file.close()

        return config_path
Esempio n. 2
0
 def _has_changed(self):
     '''
     Check if the version on disk is different from what we have loaded
     '''
     on_disk = ConfigParser()
     on_disk.read(self.path)
     return not self._configparsers_equal(on_disk)
Esempio n. 3
0
    def read_ini_file(self, filename):
        cp = ConfigParser()
        cp.read(filename)

        if not self.backup_base_dir:
            self.backup_base_dir = cp.get('global', 'backup_base_dir')
        if not os.path.isdir(self.backup_base_dir):
            self.logger.info('Creating backup directory %s' %
                             self.backup_base_dir)
            os.makedirs(self.backup_base_dir)

        self.logger.debug("backup directory : " + self.backup_base_dir)
        self.dbstat = BackupStat(
            os.path.join(self.backup_base_dir, 'log', 'tisbackup.sqlite'))

        for section in cp.sections():
            if (section != 'global'):
                self.logger.debug("reading backup config " + section)
                backup_item = None
                type = cp.get(section, 'type')

                backup_item = backup_drivers[type](backup_name=section,
                                                   backup_dir=os.path.join(
                                                       self.backup_base_dir,
                                                       section),
                                                   dbstat=self.dbstat,
                                                   dry_run=self.dry_run)
                backup_item.read_config(cp)
                backup_item.verbose = self.verbose

                self.backup_list.append(backup_item)
Esempio n. 4
0
    def __generate(self):
        if not os.path.exists(self.repofile):
            return []

        # Unfortuantely, we can not use the SafeConfigParser for zypper repo
        # files because the repository urls contains strings which the
        # SafeConfigParser don't like. It would crash with
        # ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '('
        if use_zypper:
            config = ConfigParser()
        else:
            config = SafeConfigParser()
        config.read(self.repofile)
        enabled_sections = [
            section for section in config.sections()
            if config.getboolean(section, "enabled")
        ]
        enabled_repos = []
        for section in enabled_sections:
            try:
                enabled_repos.append({
                    "repositoryid":
                    section,
                    "baseurl":
                    [self._format_baseurl(config.get(section, "baseurl"))]
                })
            except ImportError:
                break
        return enabled_repos
 def parseDesktopFile(self):
     """
     Getting all necessary data from *.dektop file of the app
     """
     cmd = "rpm -qlf $(which %s)" % self.appCommand
     cmd += '| grep "^/usr/share/applications/.*%s.desktop$"' % self.desktopFileName
     proc = Popen(cmd, shell=True, stdout=PIPE)
     # !HAVE TO check if the command and its desktop file exist
     if proc.wait() != 0:
         raise Exception("*.desktop file of the app not found")
     output = proc.communicate()[0].rstrip()
     self.desktopConfig = ConfigParser()
     self.desktopConfig.read(output)
 def test_enabling_yum_plugin_with_invalid_values(self):
     """
     Test automatic enabling of configuration files of already enabled plugins
     """
     self.init_plugin_conf_files(conf_string=YUM_PLUGIN_CONF_FILE_INVALID_VALUE)
     plugin_list = YumPluginManager.enable_yum_plugins()
     self.assertEqual(len(plugin_list), 2)
     for plugin_conf_file_name in YumPluginManager.YUM_PLUGINS:
         yum_plugin_config = ConfigParser()
         result = yum_plugin_config.read(YumPluginManager.DNF_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
         self.assertGreater(len(result), 0)
         is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
         self.assertEqual(is_plugin_enabled, 1)
     self.restore_plugin_conf_files()
Esempio n. 7
0
 def test_enabling_yum_plugin_with_wrong_conf(self):
     """
     Test automatic enabling of configuration files of already plugins with wrong values in conf file.
     """
     self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_WRONG_VALUE)
     plugin_list = YumPluginManager.enable_pkg_plugins()
     self.assertEqual(len(plugin_list), 2)
     for plugin_conf_file_name in YumPluginManager.PLUGINS:
         yum_plugin_config = ConfigParser()
         result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
         self.assertGreater(len(result), 0)
         is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
         self.assertEqual(is_plugin_enabled, 1)
     self.restore_yum_plugin_conf_files()
Esempio n. 8
0
 def test_enabling_enabled_yum_plugin_int(self):
     """
     Test automatic enabling of configuration files of already enabled plugins
     """
     self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_ENABLED_INT)
     plugin_list = YumPluginManager.enable_pkg_plugins()
     self.assertEqual(len(plugin_list), 0)
     for plugin_conf_file_name in YumPluginManager.PLUGINS:
         yum_plugin_config = ConfigParser()
         result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
         self.assertGreater(len(result), 0)
         is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
         self.assertEqual(is_plugin_enabled, 1)
     self.restore_yum_plugin_conf_files()
Esempio n. 9
0
 def test_not_enabling_disabled_yum_plugin(self):
     """
     Test not enabling (disabled in rhsm.conf) of configuration files of disabled plugins
     """
     self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_DISABLED_BOOL)
     plugin_list = YumPluginManager.enable_pkg_plugins()
     self.assertEqual(len(plugin_list), 0)
     for plugin_conf_file_name in YumPluginManager.PLUGINS:
         yum_plugin_config = ConfigParser()
         result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
         self.assertGreater(len(result), 0)
         is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled')
         self.assertEqual(is_plugin_enabled, False)
     self.restore_yum_plugin_conf_files()
Esempio n. 10
0
 def test_enabling_enabled_yum_plugin_bool(self):
     """
     Test automatic enabling of configuration files of already enabled plugins
     """
     self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_ENABLED_BOOL)
     plugin_list = YumPluginManager.enable_pkg_plugins()
     self.assertEqual(len(plugin_list), 0)
     for plugin_conf_file_name in YumPluginManager.PLUGINS:
         yum_plugin_config = ConfigParser()
         result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
         self.assertGreater(len(result), 0)
         # The file was not modified. We have to read value with with getboolean()
         is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled')
         self.assertEqual(is_plugin_enabled, True)
     self.restore_yum_plugin_conf_files()
Esempio n. 11
0
    def __init__(self, filename):
        '''
        @param filename: absolute path to the repo file; the repo file does not need to
                         exist at the time of instantiation, the save method will write it
                         out if it doesn't
        @type  filename: string; may not be None

        @raise ValueError: if filename is missing
        '''
        if filename is None:
            raise ValueError(
                'Filename must be specified when creating a RepoFile')

        self.filename = filename
        self.parser = ConfigParser()
Esempio n. 12
0
    def enable_yum_plugins(cls):
        """
        This function tries to enable yum plugins: subscription-manager and product-id.
        It takes no action, when automatic enabling of yum plugins is disabled in rhsm.conf.
        :return: It returns list of enabled plugins
        """

        # When user doesn't want to automatically enable yum plugins, then return empty list
        if cls.is_auto_enable_enabled() is False:
            log.info(
                'The rhsm.auto_enable_yum_plugins is disabled. Skipping the enablement of yum plugins.'
            )
            return []

        log.debug('The rhsm.auto_enable_yum_plugins is enabled')

        # List of successfully enabled plugins
        enabled_yum_plugins = []
        plugin_dir = ""
        if version.use_dnf:
            plugin_dir = cls.DNF_PLUGIN_DIR
        else:
            plugin_dir = cls.YUM_PLUGIN_DIR

        # Go through the list of yum plugins and try to find configuration
        # file of these plugins.
        for yum_plugin_name in cls.YUM_PLUGINS:
            yum_plugin_file_name = plugin_dir + '/' + yum_plugin_name + '.conf'
            yum_plugin_config = ConfigParser()
            try:
                result = yum_plugin_config.read(yum_plugin_file_name)
            except Exception as err:
                # Capture all errors during reading yum plugin conf file
                # report them and skip this conf file
                log.error(
                    "Error during reading yum plugin config file '%s': %s. Skipping this file."
                    % (yum_plugin_file_name, err))
                continue

            if len(result) == 0:
                log.info(
                    'Configuration file of yum plugin: "%s" cannot be read' %
                    yum_plugin_file_name)
                continue

            is_plugin_enabled = False
            if not yum_plugin_config.has_section('main'):
                log.warn(
                    'Configuration file of yum plugin: "%s" does not include main section. Adding main section.'
                    % yum_plugin_file_name)
                yum_plugin_config.add_section('main')
            elif yum_plugin_config.has_option('main', 'enabled'):
                try:
                    # Options 'enabled' can be 0 or 1
                    is_plugin_enabled = yum_plugin_config.getint(
                        'main', 'enabled')
                except ValueError:
                    try:
                        # Options 'enabled' can be also: true or false
                        is_plugin_enabled = yum_plugin_config.getboolean(
                            'main', 'enabled')
                    except ValueError:
                        log.warn(
                            "File %s has wrong value of options: 'enabled' in section: 'main' (not a int nor boolean)"
                            % yum_plugin_file_name)

            if is_plugin_enabled == cls.YUM_PLUGIN_ENABLED:
                log.debug('Yum plugin: "%s" already enabled. Nothing to do.' %
                          yum_plugin_file_name)
            else:
                log.warn('Enabling yum plugin: "%s".' % yum_plugin_file_name)
                # Change content of plugin configuration file and enable this plugin.
                with open(yum_plugin_file_name, 'w') as cfg_file:
                    yum_plugin_config.set('main', 'enabled',
                                          cls.YUM_PLUGIN_ENABLED)
                    yum_plugin_config.write(cfg_file)
                enabled_yum_plugins.append(yum_plugin_file_name)

        return enabled_yum_plugins
Esempio n. 13
0
    def _enable_plugins(cls, pkg_mgr_name, plugin_dir):
        """
        This class method tries to enable plugins for DNF or YUM
        :param pkg_mgr_name: It can be "dnf" or "yum"
        :type pkg_mgr_name: str
        :param plugin_dir: Directory with configuration files for (dnf/yum) plugins
        :type plugin_dir: str
        :return:
        """
        # List of successfully enabled plugins
        enabled_lugins = []
        # Go through the list of yum plugins and try to find configuration
        # file of these plugins.
        for plugin_name in cls.PLUGINS:
            plugin_file_name = plugin_dir + '/' + plugin_name + '.conf'
            plugin_config = ConfigParser()
            try:
                result = plugin_config.read(plugin_file_name)
            except Exception as err:
                # Capture all errors during reading yum plugin conf file
                # report them and skip this conf file
                log.error(
                    "Error during reading %s plugin config file '%s': %s. Skipping this file."
                    % (pkg_mgr_name, plugin_file_name, err))
                continue

            if len(result) == 0:
                log.info(
                    'Configuration file of %s plugin: "%s" cannot be read' %
                    (pkg_mgr_name, plugin_file_name))
                continue

            is_plugin_enabled = False
            if not plugin_config.has_section('main'):
                log.warning(
                    'Configuration file of %s plugin: "%s" does not include main section. Adding main section.'
                    % (pkg_mgr_name, plugin_file_name))
                plugin_config.add_section('main')
            elif plugin_config.has_option('main', 'enabled'):
                try:
                    # Options 'enabled' can be 0 or 1
                    is_plugin_enabled = plugin_config.getint('main', 'enabled')
                except ValueError:
                    try:
                        # Options 'enabled' can be also: true or false
                        is_plugin_enabled = plugin_config.getboolean(
                            'main', 'enabled')
                    except ValueError:
                        log.warning(
                            "File %s has wrong value of options: 'enabled' in section: 'main' (not a int nor boolean)"
                            % plugin_file_name)

            if is_plugin_enabled == cls.PLUGIN_ENABLED:
                log.debug('%s plugin: "%s" already enabled. Nothing to do.' %
                          (pkg_mgr_name, plugin_file_name))
            else:
                log.warning('Enabling %s plugin: "%s".' %
                            (pkg_mgr_name, plugin_file_name))
                # Change content of plugin configuration file and enable this plugin.
                with open(plugin_file_name, 'w') as cfg_file:
                    plugin_config.set('main', 'enabled', cls.PLUGIN_ENABLED)
                    plugin_config.write(cfg_file)
                enabled_lugins.append(plugin_file_name)

        return enabled_lugins
Esempio n. 14
0
def read_config():
    config_file = CONFIG[config_number]
    cp = ConfigParser()
    cp.read(config_file)

    backup_base_dir = cp.get('global', 'backup_base_dir')
    backup = tis_backup(backup_base_dir=backup_base_dir)
    backup.read_ini_file(config_file)

    backup_sections = SECTIONS or []

    all_sections = [
        backup_item.backup_name for backup_item in backup.backup_list
    ]
    if not backup_sections:
        backup_sections = all_sections
    else:
        for b in backup_sections:
            if not b in all_sections:
                raise Exception('Section %s is not defined in config file' % b)

    result = []
    if not backup_sections:
        sections = [
            backup_item.backup_name for backup_item in backup.backup_list
        ]

    for backup_item in backup.backup_list:
        if backup_item.backup_name in backup_sections:
            b = {}
            for attrib_name in backup_item.required_params + backup_item.optional_params:
                if hasattr(backup_item, attrib_name):
                    b[attrib_name] = getattr(backup_item, attrib_name)
            result.append(b)

    backup_dict = {}
    backup_dict['rsync_ssh_list'] = []
    backup_dict['rsync_btrfs_list'] = []
    backup_dict['rsync_list'] = []
    backup_dict['null_list'] = []
    backup_dict['pgsql_list'] = []
    backup_dict['mysql_list'] = []
    backup_dict['sqlserver_list'] = []
    backup_dict['xva_list'] = []
    backup_dict['metadata_list'] = []
    backup_dict['switch_list'] = []
    backup_dict['oracle_list'] = []
    backup_dict['samba_list'] = []
    for row in result:
        backup_name = row['backup_name']
        server_name = row['server_name']
        backup_type = row['type']
        if backup_type == "xcp-dump-metadata":
            backup_dict['metadata_list'].append(
                [server_name, backup_name, backup_type, ""])
        if backup_type == "rsync+ssh":
            remote_dir = row['remote_dir']
            backup_dict['rsync_ssh_list'].append(
                [server_name, backup_name, backup_type, remote_dir])
        if backup_type == "rsync+btrfs+ssh":
            remote_dir = row['remote_dir']
            backup_dict['rsync_btrfs_list'].append(
                [server_name, backup_name, backup_type, remote_dir])
        if backup_type == "rsync":
            remote_dir = row['remote_dir']
            backup_dict['rsync_list'].append(
                [server_name, backup_name, backup_type, remote_dir])
        if backup_type == "null":
            backup_dict['null_list'].append(
                [server_name, backup_name, backup_type, ""])
            if backup_type == "pgsql+ssh":
                db_name = row['db_name'] if len(row['db_name']) > 0 else '*'
                backup_dict['pgsql_list'].append(
                    [server_name, backup_name, backup_type, db_name])
            if backup_type == "mysql+ssh":
                db_name = row['db_name'] if len(row['db_name']) > 0 else '*'
                backup_dict['mysql_list'].append(
                    [server_name, backup_name, backup_type, db_name])
        if backup_type == "sqlserver+ssh":
            db_name = row['db_name']
            backup_dict['sqlserver_list'].append(
                [server_name, backup_name, backup_type, db_name])
        if backup_type == "oracle+ssh":
            db_name = row['db_name']
            backup_dict['oracle_list'].append(
                [server_name, backup_name, backup_type, db_name])
        if backup_type == "xen-xva":
            backup_dict['xva_list'].append(
                [server_name, backup_name, backup_type, ""])
        if backup_type == "switch":
            backup_dict['switch_list'].append(
                [server_name, backup_name, backup_type, ""])
        if backup_type == "samba4":
            backup_dict['samba_list'].append(
                [server_name, backup_name, backup_type, ""])
    return backup_dict
Esempio n. 15
0
from libtisbackup.common import *
import time
from flask import request, Flask, session, g, appcontext_pushed, redirect, url_for, abort, render_template, flash, jsonify, Response
from urlparse import urlparse
import json
import glob
import time

from config import huey
from tasks import run_export_backup, get_task, set_task

from tisbackup import tis_backup
import logging
import re

cp = ConfigParser()
cp.read("/etc/tis/tisbackup_gui.ini")

CONFIG = cp.get('general', 'config_tisbackup').split(",")
SECTIONS = cp.get('general', 'sections')
ADMIN_EMAIL = cp.get('general', 'ADMIN_EMAIL')

tisbackup_config_file = CONFIG[0]
config_number = 0

cp = ConfigParser()
cp.read(tisbackup_config_file)
backup_base_dir = cp.get('global', 'backup_base_dir')
dbstat = BackupStat(os.path.join(backup_base_dir, 'log', 'tisbackup.sqlite'))
mindate = None
error = None
Esempio n. 16
0
def main():
    (options, args) = parser.parse_args()

    if len(args) != 1:
        print "ERROR : You must provide one action to perform"
        parser.print_usage()
        sys.exit(2)

    backup_start_date = datetime.datetime.now().strftime('%Y%m%d-%Hh%Mm%S')

    # options
    action = args[0]
    if action == "listdrivers":
        for t in backup_drivers:
            print backup_drivers[t].get_help()
        sys.exit(0)

    config_file = options.config
    dry_run = options.dry_run
    verbose = options.verbose

    loglevel = options.loglevel

    # setup Logger
    logger = logging.getLogger('tisbackup')
    hdlr = logging.StreamHandler()
    hdlr.setFormatter(
        logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
    logger.addHandler(hdlr)

    # set loglevel
    if loglevel in ('debug', 'warning', 'info', 'error', 'critical'):
        numeric_level = getattr(logging, loglevel.upper(), None)
        if not isinstance(numeric_level, int):
            raise ValueError('Invalid log level: %s' % loglevel)
        logger.setLevel(numeric_level)

    # Config file
    if not os.path.isfile(config_file):
        logger.error("Error : could not find file : " + config_file +
                     ", please check the path")
    logger.info("Using " + config_file + " config file")

    cp = ConfigParser()
    cp.read(config_file)

    backup_base_dir = options.backup_base_dir or cp.get(
        'global', 'backup_base_dir')
    log_dir = os.path.join(backup_base_dir, 'log')
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    # if we run the nagios check, we don't create log file, everything is piped to stdout
    if action != 'checknagios':
        hdlr = logging.FileHandler(
            os.path.join(log_dir, 'tisbackup_%s.log' % (backup_start_date)))
        hdlr.setFormatter(
            logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
        logger.addHandler(hdlr)

    # Main
    backup = tis_backup(dry_run=dry_run,
                        verbose=verbose,
                        backup_base_dir=backup_base_dir)
    backup.read_ini_file(config_file)

    backup_sections = options.sections.split(',') if options.sections else []

    all_sections = [
        backup_item.backup_name for backup_item in backup.backup_list
    ]
    if not backup_sections:
        backup_sections = all_sections
    else:
        for b in backup_sections:
            if not b in all_sections:
                raise Exception('Section %s is not defined in config file' % b)

    if dry_run:
        logger.warning(
            "WARNING : DRY RUN, nothing will be done, just printing on screen..."
        )

    if action == "backup":
        backup.process_backup(backup_sections)
    elif action == "exportbackup":
        if not options.exportdir:
            raise Exception(
                'No export directory supplied dor exportbackup action')
        backup.export_backups(backup_sections, options.exportdir)
    elif action == "cleanup":
        backup.cleanup_backup_section(backup_sections)
    elif action == "checknagios":
        backup.checknagios(backup_sections)
    elif action == "dumpstat":
        for s in backup_sections:
            backup.dbstat.last_backups(s, count=options.statscount)
    elif action == "retryfailed":
        backup.retry_failed_backups()
    elif action == "register_existing":
        backup.register_existingbackups(backup_sections)

    else:
        logger.error('Unhandled action "%s", quitting...', action)
        sys.exit(1)
Esempio n. 17
0
import datetime
import xlrd
from xls import *
from vt import *
from iniparse import ConfigParser
import sys
#ayarlar
ayar = ConfigParser()
ayardos = '.\exnet\DATA\default.ini'
ayardosyol = '.\\exnet\\DATA\\'
if len(sys.argv) > 1:
    ayardos = sys.argv[1]
ayar.read(ayardos)
dosya = ayar.get("excel", "dosya")
sayfa = ayar.get("excel", "sayfa")
fisler = ayar.get("excel", "fisler")
fisler = fisler.split("@")
form = xls()
#komut satirindan yukleme yapmak icin
#form nesnesine ilgili sayfa yukleniyor.
form.sayfa(ayardosyol + dosya, sayfa)

for fis in fisler:
    print fis
    merkezhc = ayar.get(fis, "merkez")
    merkez = form.deger(merkezhc)
    tarihhc = ayar.get(fis, "tarih")
    tarih = form.degertarih(tarihhc)
    islemhc = ayar.get(fis, "islem")
    islem = form.deger(islemhc)
    urtkodhc = ayar.get(fis, "urtkod")