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
|
|
|
|
|
2019-04-10 20:36:43 +08:00
|
|
|
from config import REPOD_BIND_ADDRESS, REPOD_BIND_PASSWD, \
|
|
|
|
MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD
|
|
|
|
|
2019-04-05 00:21:12 +08:00
|
|
|
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-10 20:36:43 +08:00
|
|
|
def run(funcname, args=list(), kwargs=dict(), retries=0, server=(REPOD_BIND_ADDRESS, REPOD_BIND_PASSWD)):
|
2019-04-05 00:21:12 +08:00
|
|
|
try:
|
|
|
|
logger.info('client: %s %s %s',funcname, args, kwargs)
|
2019-04-10 20:36:43 +08:00
|
|
|
(addr, authkey) = server
|
|
|
|
with Client(addr, authkey=authkey) as conn:
|
2019-04-05 00:21:12 +08:00
|
|
|
conn.send([funcname, args, kwargs])
|
|
|
|
return conn.recv()
|
|
|
|
except ConnectionRefusedError:
|
|
|
|
if retries <= 10:
|
|
|
|
logger.info("Server refused, retry after 60s")
|
|
|
|
sleep(60)
|
2019-04-10 20:36:43 +08:00
|
|
|
return run(funcname, args=args, kwargs=kwargs, retries=retries+1)
|
2019-04-05 00:21:12 +08:00
|
|
|
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
|
2019-04-10 20:36:43 +08:00
|
|
|
from utils import configure_logger
|
|
|
|
configure_logger(logger)
|
|
|
|
try:
|
|
|
|
parser = argparse.ArgumentParser(description='Client for buildbot')
|
2019-04-10 20:51:34 +08:00
|
|
|
parser.add_argument('--info', action='store_true', help='show buildbot info')
|
2019-04-10 20:36:43 +08:00
|
|
|
parser.add_argument('--update', action='store_true', help='update pushed files to the repo')
|
|
|
|
parser.add_argument('--cleanall', action='store_true', help='checkout pkgbuilds')
|
|
|
|
parser.add_argument('--clean', nargs='?', default=None, help='checkout pkgbuilds in one package')
|
|
|
|
parser.add_argument('--rebuild', nargs='?', default=None, help='rebuild a package with its dirname')
|
|
|
|
args = parser.parse_args()
|
2019-04-10 20:51:34 +08:00
|
|
|
if args.info:
|
|
|
|
server=(MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD)
|
|
|
|
logger.info(run('info', server=server))
|
|
|
|
elif args.update:
|
2019-04-10 20:36:43 +08:00
|
|
|
server=(REPOD_BIND_ADDRESS, REPOD_BIND_PASSWD)
|
|
|
|
logger.info(run('update', kwargs={'overwrite': False}, server=server))
|
|
|
|
elif args.cleanall:
|
|
|
|
server=(MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD)
|
|
|
|
logger.info(run('clean_all', server=server))
|
|
|
|
elif args.clean:
|
|
|
|
server=(MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD)
|
|
|
|
logger.info(run('clean', args=(args.clean,), server=server))
|
|
|
|
elif args.rebuild:
|
|
|
|
server=(MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD)
|
|
|
|
logger.info(run('rebuild', args=(args.rebuild,), kwargs={'clean': True}, server=server))
|
|
|
|
else:
|
|
|
|
parser.error("Please choose an action")
|
|
|
|
except Exception:
|
|
|
|
print_exc_plus()
|
|
|
|
parser.exit(status=1)
|