|
24 | 24 | __revision__ = '$Format:%H$'
|
25 | 25 |
|
26 | 26 | import os
|
| 27 | +import codecs |
| 28 | + |
27 | 29 | from processing.core.Processing import Processing
|
| 30 | +from processing.core.parameters import * |
| 31 | + |
28 | 32 | from processing.tools.system import mkdir
|
29 |
| -from processing.core.parameters import ParameterSelection |
30 | 33 |
|
31 | 34 |
|
32 | 35 | def createBaseHelpFile(alg, folder):
|
33 |
| - folder = os.path.join(folder, alg.provider.getName().lower()) |
34 |
| - mkdir(folder) |
35 |
| - cmdLineName = alg.commandLineName()[ |
36 |
| - alg.commandLineName().find(':') + 1:].lower() |
| 36 | + baseDir = os.path.join(folder, alg.provider.getName().lower()) |
| 37 | + mkdir(baseDir) |
| 38 | + |
| 39 | + groupName = alg.group.lower() |
| 40 | + groupName = groupName.replace('[', '').replace(']', '').replace(' - ', '_') |
| 41 | + groupName = groupName.replace(' ', '_') |
| 42 | + cmdLineName = alg.commandLineName() |
| 43 | + algName = cmdLineName[cmdLineName.find(':') + 1:].lower() |
37 | 44 | validChars = \
|
38 |
| - 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' |
39 |
| - safeFilename = ''.join(c for c in cmdLineName if c in validChars) |
40 |
| - filepath = os.path.join(folder, safeFilename + '.rst') |
41 |
| - file = open(filepath, 'w') |
42 |
| - file.write(alg.name.upper()) |
43 |
| - file.write('\n') |
44 |
| - file.write('=' * len(alg.name)) |
45 |
| - file.write('\n\n') |
46 |
| - file.write('Description\n') |
47 |
| - file.write('-----------\n\n') |
48 |
| - file.write('Parameters\n') |
49 |
| - file.write('----------\n\n') |
50 |
| - for param in alg.parameters: |
51 |
| - file.write('- ``' + param.description + '[' + |
52 |
| - param.parameterName()[9:] + ']``:\n') |
53 |
| - file.write('\nOutputs\n') |
54 |
| - file.write('-------\n\n') |
55 |
| - for out in alg.outputs: |
56 |
| - file.write('- ``' + out.description + '[' + |
57 |
| - out.outputTypeName()[6:] + ']``:\n') |
58 |
| - file.write('\nSee also\n') |
59 |
| - file.write('---------\n\n') |
60 |
| - file.write('\nConsole usage\n') |
61 |
| - file.write('-------------\n\n') |
62 |
| - file.write('\n::\n\n') |
63 |
| - s = "\tprocessing.runalg('" + alg.commandLineName() + "', " |
64 |
| - for param in alg.parameters: |
65 |
| - s += str(param.name.lower().strip()) + ', ' |
66 |
| - for out in alg.outputs: |
67 |
| - if not out.hidden: |
68 |
| - s += str(out.name.lower().strip()) + ', ' |
69 |
| - s = s[:-2] + ')\n' |
70 |
| - file.write(s) |
71 |
| - |
72 |
| - s = '' |
73 |
| - hasSelection = False |
74 |
| - for param in alg.parameters: |
75 |
| - if isinstance(param, ParameterSelection): |
76 |
| - hasSelection = True |
77 |
| - s += '\n\t' + param.name.lower() + '(' + param.description + ')\n' |
78 |
| - i = 0 |
79 |
| - for option in param.options: |
80 |
| - s += '\t\t' + str(i) + ' - ' + str(option) + '\n' |
81 |
| - i += 1 |
82 |
| - if hasSelection: |
83 |
| - file.write('\n\tAvailable options for selection parameters:\n') |
84 |
| - file.write(s) |
85 |
| - file.close() |
| 45 | + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' |
| 46 | + safeGroupName = ''.join(c for c in groupName if c in validChars) |
| 47 | + safeAlgName = ''.join(c for c in algName if c in validChars) |
| 48 | + |
| 49 | + dirName = os.path.join(baseDir, safeGroupName) |
| 50 | + mkdir(dirName) |
| 51 | + filePath = os.path.join(dirName, safeAlgName + '.rst') |
| 52 | + |
| 53 | + with codecs.open(filePath, 'w', encoding='utf-8') as f: |
| 54 | + f.write('{}\n'.format(alg.name)) |
| 55 | + f.write('{}\n\n'.format('=' * len(alg.name))) |
| 56 | + f.write('Description\n') |
| 57 | + f.write('-----------\n\n<put algortithm description here>\n\n') |
| 58 | + |
| 59 | + # Algorithm parameters |
| 60 | + f.write('Parameters\n') |
| 61 | + f.write('----------\n\n') |
| 62 | + for p in alg.parameters: |
| 63 | + if isinstance(p, (ParameterMultipleInput, |
| 64 | + ParameterTableField, ParameterVector)): |
| 65 | + f.write('``{}`` [{}: {}]\n'.format(p.description, p.typeName(), p.dataType())) |
| 66 | + else: |
| 67 | + f.write('``{}`` [{}]\n'.format(p.description, p.typeName())) |
| 68 | + |
| 69 | + if hasattr(p, 'optional'): |
| 70 | + if p.optional: |
| 71 | + f.write(' Optional.\n\n') |
| 72 | + |
| 73 | + f.write(' <put parameter description here>\n\n') |
| 74 | + |
| 75 | + if isinstance(p, ParameterSelection): |
| 76 | + f.write(' Options:\n\n') |
| 77 | + for count, opt in enumerate(p.options): |
| 78 | + f.write(' * {} --- {}\n'.format(count, opt)) |
| 79 | + f.write('\n') |
| 80 | + |
| 81 | + if hasattr(p, 'default'): |
| 82 | + f.write(' Default: *{}*\n\n'.format(p.default if p.default != '' else '(not set)')) |
| 83 | + |
| 84 | + # Algorithm outputs |
| 85 | + f.write('Outputs\n') |
| 86 | + f.write('-------\n\n') |
| 87 | + for o in alg.outputs: |
| 88 | + f.write('``{}`` [{}]\n'.format(o.description, o.typeName())) |
| 89 | + f.write(' <put output description here>\n\n') |
| 90 | + |
| 91 | + # Console usage |
| 92 | + f.write('Console usage\n') |
| 93 | + f.write('-------------\n') |
| 94 | + f.write('\n::\n\n') |
| 95 | + cmd = " processing.runalg('{}', ".format(alg.commandLineName()) |
| 96 | + for p in alg.parameters: |
| 97 | + cmd += '{}, '.format(p.name.lower().strip()) |
| 98 | + |
| 99 | + for o in alg.outputs: |
| 100 | + if not o.hidden: |
| 101 | + cmd += '{}, '.format(o.name.lower().strip()) |
| 102 | + cmd = cmd[:-2] + ')\n\n' |
| 103 | + f.write(cmd) |
| 104 | + |
| 105 | + f.write('See also\n') |
| 106 | + f.write('--------\n\n') |
86 | 107 |
|
87 | 108 |
|
88 | 109 | def createBaseHelpFiles(folder):
|
89 | 110 | for provider in Processing.providers:
|
| 111 | + if 'grass' in provider.getName(): |
| 112 | + continue |
| 113 | + |
90 | 114 | for alg in provider.algs:
|
91 | 115 | createBaseHelpFile(alg, folder)
|
0 commit comments