2019-04-05 00:21:12 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# repod.py: Automatic management tool for an arch repo.
|
|
|
|
# This file is part of Buildbot by JerryXiao
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from multiprocessing.connection import Client
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
from config import REPOD_BIND_ADDRESS, REPOD_BIND_PASSWD
|
|
|
|
from utils import print_exc_plus
|
|
|
|
|
2019-04-09 15:43:17 +08:00
|
|
|
logger = logging.getLogger(f'buildbot.{__name__}')
|
2019-04-05 00:21:12 +08:00
|
|
|
|
2019-04-09 15:43:17 +08:00
|
|
|
def run(funcname, args=list(), kwargs=dict(), retries=0):
|
2019-04-05 00:21:12 +08:00
|
|
|
try:
|
|
|
|
logger.info('client: %s %s %s',funcname, args, kwargs)
|
|
|
|
with Client(REPOD_BIND_ADDRESS, authkey=REPOD_BIND_PASSWD) as conn:
|
|
|
|
conn.send([funcname, args, kwargs])
|
|
|
|
return conn.recv()
|
|
|
|
except ConnectionRefusedError:
|
|
|
|
if retries <= 10:
|
|
|
|
logger.info("Server refused, retry after 60s")
|
|
|
|
sleep(60)
|
|
|
|
return ping(funcname, args=args, kwargs=kwargs, retries=retries+1)
|
|
|
|
else:
|
|
|
|
logger.error("Server refused")
|
|
|
|
return False
|
|
|
|
except EOFError:
|
|
|
|
logger.error('Internal server error')
|
|
|
|
return False
|
|
|
|
except Exception:
|
|
|
|
print_exc_plus()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import argparse
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
2019-04-09 15:43:17 +08:00
|
|
|
logger.info('result: %s', run('push_files', args=('aaa', 1)))
|
|
|
|
logger.info('result: %s', run('add_files', args=('aaa',)))
|
|
|
|
#logger.info('result: %s', run('update'))
|