-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
37 lines (26 loc) · 936 Bytes
/
script.py
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
import os
import click
from sortViews import sortAndFormatXmlElems
@click.command(help="A utility for formatting Specify views.xml files so they are easier to work with")
@click.option('--file', help='The target file name (and relative path)')
def format(file):
if not file:
print('a file name is required, try sortviews --help')
return
if os.path.isfile(file):
#just check we're working with a views.xml file
if not file.endswith('views.xml'):
click.echo('we can only format Specify forms xml files')
return
with open(file, 'r') as f:
xml = f.read()
sortedviewsxml = sortAndFormatXmlElems(xml, 'views')
sortedviewdefsxml = sortAndFormatXmlElems(sortedviewsxml, 'viewdefs')
with open(file, 'w') as f:
f.write(sortedviewdefsxml)
click.echo('all done')
else:
click.echo('please provide a valid filename')
return
if __name__ == '__main__':
format()