예제 #1
0
    def sanity_check(self):
        """ Method to check dir tree structure and config file integrity. """

        # make sure 'usr' dir tree is intact & create anew if not
        for d in [self.usrcfg['path'],
                  self.tmpcfg['path'],
                  self.poolsd,
                  self.profilesd]:

            if not path.exists(d):
                if not mb_mkdirs(d):
                    return self._err("==> ERROR: Unable to create '%s'" % (d) )
                self._log("==> Created new directory at\n  -> %s" % (d) )

        # make sure '.cfg' files exist for 'usr', 'tmp' and 'skel*', else make
        if not path.isfile( self.usrcfg['cfgf'] ):
            prop_d = MBRAT_DEF_USR_D.copy()
            self.usrmgr = SecManager('prefs', self.usrcfg['cfgf'])
            self.usrmgr.set_configf( self.usrcfg['cfgf'] )
            self.usrmgr.set_write( prop_d['prefs'] )
            self._log("==> Created new usr.cfg at\n  -> %s" %
                      (self.usrcfg['cfgf']) )

        if not path.isfile( self.tmpcfg['cfgf'] ):
            self.secmgr['tmp'] = SecManager('tmp', self.tmpcfg['cfgf'])
            self._mkcfg_tmp()
            self._log("==> Created new tmp.cfg at\n  -> %s" %
                      (self.tmpcfg['cfgf']) )

        # skel* and _current sanity iters [pool, poolkey, profile, privkey,..]
        for cfg_t in [t for t in MBRAT_CFG_TYPE_L if t != 'pubkey']:
            cfgname = "skel{}".format(cfg_t)
            cfg_parentd = self.get_cfg_parentd(cfg_t)
            configf = path.join( cfg_parentd, cfgname, "%s.cfg" % (cfgname) )
            cfg_l = os.listdir(cfg_parentd)

            if not cfgname in cfg_l:
                self.secmgr[cfg_t] = SecManager( cfg_t, configf )
                self.make_config( cfg_t, cfgname, update=False, current=False )
                self._log(
                    "==> Created skeleton '%s' config at\n  -> %s"
                    % (cfg_t, configf)
                )

            if not MBRAT_CURRENTL in cfg_l:
                current_cfg = path.join( cfg_parentd, MBRAT_CURRENTL )
                os.symlink( configf, current_cfg )
예제 #2
0
def _install_dirs(install_path):
    """ Pre-install required directory structure in user's $MBRAT_HOME directory. """

    print "Installing directory structure and files ..."

    if not mb_mkdirs(MBRAT_CONFD):
        print "==> ERROR: Unable to create {}".format(MBRAT_CONFD)
        return False

    # copy python scripts ...
    err_l = []
    try:
        copytree( path.join(install_path, 'mbrat'), 
                  path.join(MBRAT_CONFD, 'mbrat'), 
                  ignore=ignore_patterns('*~', '*#*'), symlinks=True )
    except Error as e:
        err_l.extend(e)

    # copy etc ...
    try:
        copytree( path.join(install_path, 'etc'), 
                  path.join(MBRAT_CONFD, 'etc'),
                  ignore=ignore_patterns('*~', '*#*'), symlinks=True )
    except Error as e:
        err_l.extend(e)

    # copy executable script ...
    copy2( path.join(install_path, 'mbrat.py'), 
           path.join(MBRAT_CONFD) )
    if not path.exists( path.join(MBRAT_CONFD, 'mbrat.py') ):
        err_l.append( (path.join(install_path, 'mbrat.py'),
                       path.join(MBRAT_CONFD, 'mbrat.py'),
                       "unable to copy 'mbrat.py'") )

    # check for copy errors & exit if yep
    if err_l:
        for e in err_l:
            print str(e) + "\n"
        return False

    return True