Beispiel #1
0
 def setup_logger(self):
     if self.debug >= 2:
         path = get_path('log', abspath=str(Path.home()) + '/.waldorf')
         # logging async server
         _nf = [
             '[%(asctime)s]', '[%(name)s]',
             '[%(filename)20s:%(funcName)15s:%(lineno)5d]',
             '[%(levelname)s]', ' %(message)s'
         ]
         _cf = [
             '$GREEN[%(asctime)s]$RESET', '[%(name)s]',
             '$BLUE[%(filename)20s:%(funcName)15s:%(lineno)5d]$RESET',
             '[%(levelname)s]', ' $CYAN%(message)s$RESET'
         ]
         nformatter = logging.Formatter('-'.join(_nf))
         cformatter = ColoredFormatter('-'.join(_cf))
         root = logging.getLogger()
         root.setLevel(logging.DEBUG)
         ch = logging.StreamHandler(sys.stdout)
         ch.setFormatter(cformatter)
         rf = logging.handlers.RotatingFileHandler(path + '/wd_master.log',
                                                   maxBytes=50 * 1024 *
                                                   1024,
                                                   backupCount=5)
         rf.setFormatter(nformatter)
         root.addHandler(ch)
         root.addHandler(rf)
     if self.debug >= 1:
         # logging Waldorf master
         self.logger = init_logger(
             'wd_master',
             get_path('log', abspath=str(Path.home()) + '/.waldorf'),
             (logging.DEBUG, logging.DEBUG))
     else:
         self.logger = DummyLogger()
Beispiel #2
0
 def __init__(self, name, cfg: WaldorfCfg):
     self.name = name
     self.cfg = cfg
     self.git_credential = self.cfg.env_cfg.git_credential
     self.default_expect = self.cfg.env_cfg.default_expect
     self.default_timeout = self.cfg.env_cfg.default_timeout
     self._root_dir = get_path('.waldorf', abspath=str(Path.home()))
     self._env_dir = get_path('env', abspath=self._root_dir)
     self.update_env_list()
Beispiel #3
0
 def setup_logger(self):
     if self.cfg.debug >= 1:
         self.logger = init_logger(
             'wd_slave', get_path(relative_path='.'),
             (logging.DEBUG, logging.DEBUG))
     else:
         self.logger = DummyLogger()
Beispiel #4
0
def load_cfg(prefix):
    cfg_dir = get_path('cfg', abspath=str(Path.home()) + '/.waldorf')
    cfg_fp = cfg_dir + '/{}_cfg.json'.format(prefix)
    cfg_file = Path(cfg_fp)
    if cfg_file.exists() and cfg_file.is_file():
        return WaldorfCfg.loads(open(cfg_fp).read())
    return WaldorfCfg()
Beispiel #5
0
    def setup_logger(self):
        if self.debug >= 2:
            # Logging socketIO-client output.
            _cf = [
                '$GREEN[%(asctime)s]$RESET', '[%(name)s]',
                '$BLUE[%(filename)20s:%(funcName)15s:%(lineno)5d]$RESET',
                '[%(levelname)s]', ' $CYAN%(message)s$RESET'
            ]
            cformatter = ColoredFormatter('-'.join(_cf))

            logger = logging.getLogger('socketIO-client')
            logger.setLevel(logging.DEBUG)
            ch = logging.StreamHandler(sys.stdout)
            ch.setFormatter(cformatter)
            logger.addHandler(ch)
        if self.debug >= 1:
            # Logging Waldorf client.
            self.logger = init_logger('wd_client', get_path(relative_path='.'),
                                      (logging.DEBUG, logging.DEBUG))
        else:
            self.logger = DummyLogger()
Beispiel #6
0
 def setup_rsa(self):
     """Setup public key and private key for git credential."""
     cfg_path = get_path('config', abspath=str(Path.home()) + '/.waldorf')
     public_pem_path = cfg_path + '/public.pem'
     private_pem_path = cfg_path + '/private.pem'
     if not os.path.exists(public_pem_path) or \
             not os.path.exists(private_pem_path):
         random_generator = Random.new().read
         rsa = RSA.generate(1024, random_generator)
         self._private_pem = rsa.exportKey()
         self._public_pem = rsa.publickey().exportKey()
         with open(cfg_path + '/private.pem', 'wb') as f:
             f.write(self._private_pem)
         with open(cfg_path + '/public.pem', 'wb') as f:
             f.write(self._public_pem)
     with open(cfg_path + '/private.pem', 'rb') as f:
         self._private_pem = f.read()
     with open(cfg_path + '/public.pem', 'rb') as f:
         self._public_pem = f.read()
     self._private_key = RSA.importKey(self._private_pem)
     self._private_cipher = PKCS1_v1_5.new(self._private_key)
     self.random_generator = Random.new().read
Beispiel #7
0
def save_cfg(prefix, cfg):
    cfg_dir = get_path('cfg', abspath=str(Path.home()) + '/.waldorf')
    cfg_fp = cfg_dir + '/{}_cfg.json'.format(prefix)
    with open(cfg_fp, 'w') as f:
        f.write(WaldorfCfg.dumps(cfg))