aboutsummaryrefslogtreecommitdiff
path: root/prepare-agenda.py
blob: 061be7f58c3348d8b7d6b28198c12d7fc7973ccb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
#
# Workload Automation v2 for LAVA
#
# Copyright (C) 2014, Linaro Limited.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Author: Milosz Wasilewski <milosz.wasilewski@linaro.org>
#

import yaml
from optparse import OptionParser

TEMPLATE_PATH = "templates/"
SQLITE_DB_GLOBAL_PATH = "/root/db_results/"
SQLITE_DB = 'sqlite_database'
CONFIG = 'config'

if __name__ == '__main__':

    usage = "usage: %prog [OPTIONS]"
    parser = OptionParser(usage=usage)
    parser.add_option("-a", "--agenda", dest="agenda",
                  help="Agenda file template to be used")
    parser.add_option("-n", "--job-name", dest="job_name",
                  help="Job name to be used as db name in agenda file")
    (options, args) = parser.parse_args()

    if not options.agenda:
        parser.error("Agenda name missing")
    if not options.job_name:
        parser.error("Job name missing")

    agenda = open(TEMPLATE_PATH + options.agenda, "r")
    agenda_yaml = yaml.load(agenda)
    agenda_yaml[CONFIG][SQLITE_DB] = SQLITE_DB_GLOBAL_PATH + options.job_name + ".db"
    agenda.close()
    with open(options.agenda, 'w') as outfile:
        outfile.write( yaml.dump(agenda_yaml, default_flow_style=True) )