Merge "Activate l2switch verify with JDK8"
[releng/builder.git] / scripts / jjb-autoupdate-project.py
1 #!/usr/bin/python
2
3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2014 The Linux Foundation and others.
6 #
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Eclipse Public License v1.0
9 # which accompanies this distribution, and is available at
10 # http://www.eclipse.org/legal/epl-v10.html
11 #
12 # Contributors:
13 #   Thanh Ha (The Linux Foundation) - Initial implementation
14 ##############################################################################
15
16 import os
17
18
19 def get_autoupdate_projects(jjb_dir, projects):
20     """Get list of projects that should be auto-updated."""
21     project_list = []
22     for project in projects:
23         template = os.path.join(jjb_dir, project, "%s.yaml" % project)
24         if os.path.isfile(template):
25             with open(template, 'r') as f:
26                 first_line = f.readline()
27             if first_line.startswith("# REMOVE THIS LINE IF"):
28                 project_list.append(project)
29
30     return project_list
31
32
33 def update_templates(projects):
34     for project in projects:
35         cfg_file = "jjb/%s/%s.cfg" % (project, project)
36         os.system("python scripts/jjb-init-project.py %s -c %s" %
37                   (project, cfg_file))
38
39 ##############
40 # Code Start #
41 ##############
42
43 jjb_dir = "jjb"
44 all_projects = [d for d in os.listdir(jjb_dir)
45                 if os.path.isdir(os.path.join(jjb_dir, d))]
46 auto_update_projects = get_autoupdate_projects(jjb_dir, all_projects)
47 update_templates(auto_update_projects)