Disable builder-weekly job
[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, 2015 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 from jjblib import Project
19
20
21 def _is_project(jjb_dir, project):
22     """Returns true if project is a project that should be auto-generated"""
23     p = Project(project)
24     if p.meta_project:
25         template = os.path.join(jjb_dir, project, "%s.yaml" % p.project)
26     else:
27         template = os.path.join(jjb_dir, p.project, "%s.yaml" % p.project)
28
29     if os.path.isfile(template):  # Project found
30         with open(template, 'r') as f:
31             first_line = f.readline()
32         if first_line.startswith("# REMOVE THIS LINE IF"):
33             return True
34     return False
35
36
37 def get_autoupdate_projects(jjb_dir):
38     """Get list of projects that should be auto-updated."""
39     project_list = []
40
41     for root, dirs, files in os.walk(jjb_dir):
42         project = root.replace("%s/" % jjb_dir, '')
43
44         if _is_project(jjb_dir, project):
45             project_list.append(project)
46
47     return project_list
48
49
50 def update_templates(projects):
51     for project in projects:
52         print("Updating... %s" % project)
53         p = Project(project)
54         if p.meta_project:  # Meta project
55             cfg_file = "jjb/%s/%s.cfg" % (project, p.project)
56         else:
57             cfg_file = "jjb/%s/%s.cfg" % (p.project, p.project)
58         os.system("python scripts/jjb-init-project.py %s -c %s" %
59                   (project, cfg_file))
60
61 ##############
62 # Code Start #
63 ##############
64
65 jjb_dir = "jjb"
66 all_projects = [d for d in os.listdir(jjb_dir)
67                 if os.path.isdir(os.path.join(jjb_dir, d))]
68 auto_update_projects = get_autoupdate_projects(jjb_dir)
69 update_templates(auto_update_projects)