From 07c66ff7a0fb4d24ab147f7e8a91b91bb6f11241 Mon Sep 17 00:00:00 2001 From: hyokeun Date: Mon, 8 Jan 2018 16:53:24 +0900 Subject: [PATCH] Update dashboard main_project table when rep conf updated Change-Id: I5ab25b234325300bc7d99a924f124df6197706f5 --- job_load_repos.yaml.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/job_load_repos.yaml.py b/job_load_repos.yaml.py index 910492c..d61278c 100755 --- a/job_load_repos.yaml.py +++ b/job_load_repos.yaml.py @@ -31,6 +31,55 @@ from common.git import Git, clone_gitproject from gbp.git.repository import GitRepositoryError +from common import buildmonitor_db + +def update_dashboard_db(repo_map): + if os.getenv('BUILDMONITOR_ENABLED', '0') != '1': + return + + try: + buildmonitor_db.connect_db() + + query = 'SELECT id, name, release_name, snapshot_dir FROM main_project WHERE name IN (%s)' % ('%s,' * len(repo_map.keys()))[:-1] + ret_data = buildmonitor_db.get_multi_values_from_query_data(query, tuple(repo_map.keys())) + + existing_projects = [] + diff_projects = [] + + for single in ret_data: + existing_projects.append(single[1]) + if repo_map[single[1]]['Release'] != single[2] or \ + repo_map[single[1]]['SnapshotDir'] != single[3]: + diff_projects.append(single[1]) + + new_projects = [ x for x in repo_map.keys() if x not in existing_projects ] + + print '\nNew Projects:' + print new_projects + print '\nExisting Projects:' + print existing_projects + print '\nDiff Projects:' + print diff_projects + + query = 'INSERT INTO main_project (name, fake, release_name, snapshot_dir) ' \ + 'VALUES (%s, %s, %s, %s)' + query_list = [] + for x in new_projects: + query_list.append((x, 1, repo_map[x]['Release'], repo_map[x]['SnapshotDir'])) + buildmonitor_db.do_many_query(query, query_list) + + query = 'UPDATE main_project SET release_name=%s, snapshot_dir=%s ' \ + 'WHERE name=%s LIMIT 1' + for x in diff_projects: + query_data = (repo_map[x]['Release'], repo_map[x]['SnapshotDir'], x) + buildmonitor_db.do_query(query,query_data) + + except Exception as err: + print repr(err) + + if True: + buildmonitor_db.disconnect_db() + def load_repos(config_file): """ store the repos conf in repos.yaml to redis @@ -48,13 +97,21 @@ def load_repos(config_file): ret = bdb.read_repos(file(config_file, 'r').read(), extra_files=extra_files) + # Update Dashboard DB + repo_map = {} + # Print db contents repos = bdb.get_repos() for x in repos: + if 'Project' in repos[x] and 'SnapshotDir' in repos[x] and 'Release' in repos[x]: + repo_map[repos[x]['Project']] = {'SnapshotDir': repos[x]['SnapshotDir'], \ + 'Release': repos[x]['Release']} print '\n%s\n----' % x for k in repos[x]: print ' %s: %s' % (k, repos[x][k]) + update_dashboard_db(repo_map) + return ret def main(): -- 2.7.4