-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSConstruct
94 lines (73 loc) · 2.7 KB
/
SConstruct
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Sloveniacontrol Ltd. (www.sloveniacontrol.si)
# This file is part of asterix-data.
#
# asterix-data 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 3 of the License, or
# (at your option) any later version.
#
# asterix-data 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 asterix-data. If not, see <http://www.gnu.org/licenses/>.
# Author:
# Zoran Bošnjak, Sloveniacontrol Ltd.
import os
name = 'asterix-data'
formatDef = 'format.rnc'
AddOption('--prefix', dest='prefix', type='string', nargs=1,
action='store', metavar='DIR', default='/usr/local/share',
help='installation prefix')
env = Environment(
PREFIX = GetOption('prefix'),
# need to expose $PATH in order to see python and jing at non-standard
# locations, for example during a nix-build
ENV = {
'PATH': os.environ['PATH']
}
)
Decider('content')
def validate(target, source, env):
"""Validate xml files"""
# check non asci
cmd = 'python3 charvalidate.py ' + ' '.join(map(str,source))
rv = env.Execute(cmd)
assert rv==0
# check with template
cmd = 'jing -c {} '.format(formatDef) + ' '.join(map(str,source))
rv = env.Execute(cmd)
assert rv==0
print
print('No errors found.')
def install(target, source, env):
base = os.path.join("$PREFIX", name)
# make sure that target directory is empty, create target if necessary
target = env.subst(base)
if os.path.exists(target):
assert os.path.isdir(target), target + " is not a directory!"
assert os.listdir(target) == [], target + " directory is not empty!"
else:
env.Execute(Mkdir(base))
# copy files
env.Execute(Copy(base, formatDef))
xml = os.path.join(base, 'xml')
env.Execute(Mkdir(xml))
for i in Glob('xml/*.xml'):
env.Execute(Copy(xml, i))
# [(target, help, src, cmd)]
targets = [
('validate', 'validate xml files', Glob('xml/*.xml'), validate),
('install', 'install data to the system (requires root permission)', [], install)
]
Default('validate')
helpString = ''.join([' scons {} - {}\n'.format(a,b) for (a,b,c,d) in targets])
Help('Type:\n' + helpString)
# define commands
for a,b,c,d in targets:
env.Command(a, c, d)