|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
3
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
4
|
|
|
# this work for additional information regarding copyright ownership. |
|
5
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
7
|
|
|
# the License. You may obtain a copy of the License at |
|
8
|
|
|
# |
|
9
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
# |
|
11
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
# See the License for the specific language governing permissions and |
|
15
|
|
|
# limitations under the License. |
|
16
|
|
|
|
|
17
|
|
|
""" |
|
18
|
|
|
Script which generates a table with system triggers which is included in the |
|
19
|
|
|
documentation. |
|
20
|
|
|
""" |
|
21
|
|
|
|
|
22
|
|
|
import os |
|
23
|
|
|
|
|
24
|
|
|
from st2common.constants.triggers import INTERNAL_TRIGGER_TYPES |
|
25
|
|
|
|
|
26
|
|
|
from utils import as_rest_table |
|
27
|
|
|
|
|
28
|
|
|
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) |
|
29
|
|
|
HEADER = '.. NOTE: This file has been generated automatically, don\'t manually edit it' |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def main(): |
|
33
|
|
|
lines = [] |
|
34
|
|
|
lines.append(HEADER) |
|
35
|
|
|
lines.append('') |
|
36
|
|
|
|
|
37
|
|
|
for resource_type, trigger_definitions in INTERNAL_TRIGGER_TYPES.items(): |
|
38
|
|
|
resource_title = resource_type.title().replace('_', ' ') |
|
39
|
|
|
lines.append(resource_title) |
|
40
|
|
|
lines.append('~' * (len(resource_title))) |
|
41
|
|
|
lines.append('') |
|
42
|
|
|
|
|
43
|
|
|
rows = [] |
|
44
|
|
|
rows.append(['Reference', 'Description', 'Properties']) |
|
45
|
|
|
|
|
46
|
|
|
for trigger_definition in trigger_definitions: |
|
47
|
|
|
properties = trigger_definition['payload_schema']['properties'].keys() |
|
48
|
|
|
properties = ', '.join(properties) |
|
49
|
|
|
row = [trigger_definition['name'], trigger_definition['description'], properties] |
|
50
|
|
|
rows.append(row) |
|
51
|
|
|
|
|
52
|
|
|
table = as_rest_table(rows, full=True) |
|
53
|
|
|
lines.extend(table.split('\n')) |
|
54
|
|
|
lines.append('') |
|
55
|
|
|
|
|
56
|
|
|
result = '\n'.join(lines) |
|
57
|
|
|
|
|
58
|
|
|
destination_path = os.path.join(CURRENT_DIR, |
|
59
|
|
|
'../docs/source/_includes/internal_trigger_types.rst') |
|
60
|
|
|
with open(destination_path, 'w') as fp: |
|
61
|
|
|
fp.write(result) |
|
62
|
|
|
|
|
63
|
|
|
print('Generated: %s' % (destination_path)) |
|
64
|
|
|
return result |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
if __name__ == '__main__': |
|
68
|
|
|
main() |
|
69
|
|
|
|