Ejemplo n.º 1
0
    def _modify_configfile(self, conffile):
        """This method modifies a single configuration file, i.e.
        
        * it reads the existing value from the file
        * retrieves the new value under consideration of the profile name
        * writes the new value to the configuration file.
        
        Files that are not readable/writable are skipped.
        
        """
        if os.path.isfile(conffile) and\
           os.access(conffile, os.F_OK and os.R_OK and os.W_OK):
            print "checking file: %s" % conffile
            config = _Config(conffile)
            _default_config = ConfigManager.get_default_config_obj()
            if config.has_section("log"):
                if config.has_option("log", "file"):
                    logfile = config.get("log", "file")
                    logdir = os.path.dirname(logfile)

                    new_logfn = ConfigManager.get_logfile_name_template(
                        conffile)
                    new_log = os.path.join(logdir, new_logfn)

                    if logfile == new_log:
                        print "   nothing to do. skipped"
                    else:
                        print "   changing log file option"
                        print "   from `%s`" % (logfile)
                        print "   to   `%s`" % (new_log)
                        config.set("log", "file", str(new_log))
                else:
                    config.set(
                        "log", "file",
                        os.path.join(
                            _default_config.get_logdir(),
                            ConfigManager.get_logfile_name_template(conffile)))
                    print "   no log file specified. Default value set"

                if not config.has_option("log", "level"):
                    config.set("log", "level", _default_config.get_loglevel())
                    print "   no log level specified. Default value set"
            else:
                config.add_section("log")
                config.set(
                    "log", "file",
                    os.path.join(
                        _default_config.get_logdir(),
                        ConfigManager.get_logfile_name_template(conffile)))
                config.set("log", "level", _default_config.get_loglevel())
                print "   no section `log` found. Default values set"

            config.commit_to_disk()

            if config.has_section("general"):
                # remove old backuplinks options - it's now always done.
                if config.has_option("general", "backuplinks"):
                    print "   Removing backuplinks option (not needed anymore)"
                    config.remove_option("general", "backuplinks")
                    config.commit_to_disk()
Ejemplo n.º 2
0
    def _copy_other_profiles(self):
        """Modifies the configuration files for the other profiles.
        
        """
        for cdir in self._configdirs:
            pdir = os.path.join(
                cdir, ConfigManager.ConfigManagerStaticData.get_profiles_dir())

            cdir_nssb = cdir.replace("sbackup", "nssbackup")
            pdir_nssb = os.path.join(
                cdir_nssb,
                ConfigManager.ConfigManagerStaticData.
                get_profiles_dir_nssbackup())

            # get the profile directory for current configuration directory
            if os.path.isdir(pdir_nssb) and\
               os.access(pdir_nssb, os.F_OK and os.R_OK):
                # and get the profiles from the profiles directory
                self._mk_dir(pdir, pdir_nssb)
                profiles_nssb = ConfigManager.get_profiles_nssbackup(pdir_nssb)
                for cprof in profiles_nssb:
                    _src = profiles_nssb[cprof][0]
                    _pname = os.path.basename(_src)
                    _dst = os.path.join(
                        pdir, "sbackup%s" % (_pname.lstrip("nssbackup")))
                    self._copy_configfile(_src, _dst)
Ejemplo n.º 3
0
 def _query_default_conffile(self):
     print "Reading schedule info from superuser's default profile"
     _conffilehdl = ConfigManager.ConfigurationFileHandler()
     _defconffile = _conffilehdl.get_default_conffile_fullpath()
     print "Configuration: `%s`" % _defconffile
     self._conffile = _defconffile
     if not os.path.exists(self._conffile):
         self._conffile = None
Ejemplo n.º 4
0
    def do_upgrade(self):
        """Public method that performs the setting.
        Returns always `NO_ERRORS` as exit code.
        """
        if system.is_superuser():
            try:
                print "Reading schedule info from superuser's default profile"
                _conffilehdl = ConfigManager.ConfigurationFileHandler()
                _defconffile = _conffilehdl.get_default_conffile_fullpath()
                print "Configuration: `%s`" % _defconffile

                if os.path.exists(_defconffile):
                    _conf = ConfigManager.ConfigManager(_defconffile)
                    _conf.write_schedule()
            except Exception, error:
                print "Error while writing CRON settings: %s" % error
                traceback.print_exc()
Ejemplo n.º 5
0
 def _modify_other_profiles(self):
     """Modifies the configuration files for the other profiles.
     
     """
     for cdir in self._configdirs:
         pdir = os.path.join(
             cdir, ConfigManager.ConfigManagerStaticData.get_profiles_dir())
         # get the profile directory for current configuration directory
         if os.path.isdir(pdir) and\
            os.access(pdir, os.F_OK and os.R_OK and os.W_OK):
             # and get the profiles from the profiles directory
             profiles = ConfigManager.get_profiles(pdir)
             for cprof in profiles:
                 cconf = profiles[cprof][0]
                 self._modify_configfile(cconf)
Ejemplo n.º 6
0
    def _update_schedule(self):
        _conf = ConfigManager.ConfigManager(self._conffile)

        if not _conf.has_section("schedule") \
                or (not _conf.has_option("schedule", "cron") \
                and not _conf.has_option("schedule", "anacron")):
            _sched = _conf.get_schedule_and_probe()
            if _sched is not None:  # entry in cron.* found that is not stored in conf file
                print "Schedule found on FS: %s" % str(_sched)
                _ctype = _sched[0]
                _cexpr = _sched[1]
                assert _ctype in ConfigManager.SCHEDULE_TYPES, "Given schedule type `%s` is invalid" % _ctype
                assert (_cexpr is not None) and (_cexpr != "None"), \
                       "Given cron expression `%s` is invalid" % _cexpr

                _conf.setSchedule(_ctype, _cexpr)
                _conf.saveConf()
Ejemplo n.º 7
0
    def __init__(self):
        """
        Constructor
        @param configManager:
        """
        interfaces.ITargetHandler.__init__(self)

        self._logger = log.LogFactory.getLogger()

        # destination/target specific instances
        self._dest = None
        self._eff_path = None
        self._configuration = None
        self._initialize_callback = None
        self._terminate_callback = None
        self._is_initialized = False

        ## This is the base directory where all mountpoints of remote sites will be located
        _defaults = ConfigManager.get_default_config_obj()
        self.__mountdir = _defaults.get_mountdir()

        ## the list of all mounted dirs , should be filled by initialize.
        # It's a dict with key = remoteSource and value = mountpoint
        self.__mountedDirs = {}