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)
|
2019-04-11 16:32:39 +08:00
|
|
|
def print_log():
|
|
|
|
import os, re
|
|
|
|
abspath=os.path.abspath(__file__)
|
|
|
|
abspath=os.path.dirname(abspath)
|
|
|
|
os.chdir(abspath)
|
|
|
|
def is_debug_msg(msg, DEBUG):
|
|
|
|
if '- DEBUG -' in msg:
|
|
|
|
return True
|
|
|
|
elif re.match(r'[0-9]{4}-[0-9]{2}-[0-9]{2}.*', msg):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return DEBUG
|
|
|
|
with open('buildbot.log', 'r') as f:
|
|
|
|
DEBUG = False
|
|
|
|
lines = list()
|
|
|
|
lines += f.read().split('\n')
|
|
|
|
while len(lines) >= 100:
|
|
|
|
lines.pop(0)
|
|
|
|
while True:
|
|
|
|
nlines = f.read().split('\n')
|
2019-04-11 16:37:58 +08:00
|
|
|
if not lines and \
|
|
|
|
len(nlines) == 1 and nlines[0] == '':
|
2019-04-11 16:32:39 +08:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
lines += nlines
|
|
|
|
for line in lines:
|
|
|
|
DEBUG = is_debug_msg(line, DEBUG)
|
|
|
|
if not DEBUG:
|
|
|
|
print(line)
|
|
|
|
lines = list()
|
|
|
|
sleep(1)
|
2019-04-10 20:36:43 +08:00
|
|
|
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')
|
2019-04-11 16:32:39 +08:00
|
|
|
parser.add_argument('--log', action='store_true' , help='print log')
|
2019-04-10 20:36:43 +08:00
|
|
|
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)
|
2019-04-10 21:10:53 +08:00
|
|
|
logger.info(run('rebuild_package', args=(args.rebuild,), kwargs={'clean': True}, server=server))
|
2019-04-11 16:32:39 +08:00
|
|
|
elif args.log:
|
|
|
|
logger.info('printing logs')
|
|
|
|
print_log()
|
2019-04-10 20:36:43 +08:00
|
|
|
else:
|
|
|
|
parser.error("Please choose an action")
|
|
|
|
except Exception:
|
|
|
|
print_exc_plus()
|
|
|
|
parser.exit(status=1)
|