tools: Modernize generate-docs-nm-settings-docs-gir.py to 2022 standards
* Create main() function and put its execution under __name__ == '__main__' guard. * Only one module import per line * Use required=True to check if necessary arguments have been passed. * Remove usage() as ArgumentParser handles that already
This commit is contained in:

committed by
Thomas Haller

parent
8df3cb1355
commit
a2298d31c0
@@ -3,16 +3,16 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2009 - 2017 Red Hat, Inc.
|
# Copyright (C) 2009 - 2017 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
|
from __future__ import print_function, unicode_literals
|
||||||
from __future__ import print_function
|
import argparse
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import gi
|
import gi
|
||||||
import xml.sax.saxutils as saxutils
|
import xml.sax.saxutils as saxutils
|
||||||
|
import re
|
||||||
|
|
||||||
gi.require_version("GIRepository", "2.0")
|
gi.require_version("GIRepository", "2.0")
|
||||||
from gi.repository import GIRepository
|
from gi.repository import GIRepository
|
||||||
import argparse, re, sys
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -190,32 +190,9 @@ def xml_quoteattr(val):
|
|||||||
return saxutils.quoteattr(str(val))
|
return saxutils.quoteattr(str(val))
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def main(gir_path_str, output_path_str):
|
||||||
print("Usage: %s --gir FILE --output FILE" % sys.argv[0])
|
girxml = ET.parse(gir_path_str).getroot()
|
||||||
exit()
|
outfile = open(output_path_str, mode="w")
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument(
|
|
||||||
"-l",
|
|
||||||
"--lib-path",
|
|
||||||
metavar="PATH",
|
|
||||||
action="append",
|
|
||||||
help="path to scan for shared libraries",
|
|
||||||
)
|
|
||||||
parser.add_argument("-g", "--gir", metavar="FILE", help="NM-1.0.gir file")
|
|
||||||
parser.add_argument("-o", "--output", metavar="FILE", help="output file")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
if args.gir is None or args.output is None:
|
|
||||||
usage()
|
|
||||||
|
|
||||||
if args.lib_path:
|
|
||||||
for lib in args.lib_path:
|
|
||||||
GIRepository.Repository.prepend_library_path(lib)
|
|
||||||
|
|
||||||
girxml = ET.parse(args.gir).getroot()
|
|
||||||
outfile = open(args.output, mode="w")
|
|
||||||
|
|
||||||
basexml = girxml.find('./gi:namespace/gi:class[@name="Setting"]', ns_map)
|
basexml = girxml.find('./gi:namespace/gi:class[@name="Setting"]', ns_map)
|
||||||
settings = girxml.findall('./gi:namespace/gi:class[@parent="Setting"]', ns_map)
|
settings = girxml.findall('./gi:namespace/gi:class[@parent="Setting"]', ns_map)
|
||||||
@@ -247,7 +224,8 @@ for settingxml in settings:
|
|||||||
class_desc = get_docs(settingxml)
|
class_desc = get_docs(settingxml)
|
||||||
if class_desc is None:
|
if class_desc is None:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"%s needs a gtk-doc block with one-line description" % setting.props.name
|
"%s needs a gtk-doc block with one-line description"
|
||||||
|
% setting.props.name
|
||||||
)
|
)
|
||||||
outfile.write(
|
outfile.write(
|
||||||
' <setting name="%s" description=%s name_upper="%s" >\n'
|
' <setting name="%s" description=%s name_upper="%s" >\n'
|
||||||
@@ -281,7 +259,8 @@ for settingxml in settings:
|
|||||||
|
|
||||||
if value_desc is None:
|
if value_desc is None:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"%s.%s needs a documentation description" % (setting.props.name, prop)
|
"%s.%s needs a documentation description"
|
||||||
|
% (setting.props.name, prop)
|
||||||
)
|
)
|
||||||
|
|
||||||
default_value_as_xml = ""
|
default_value_as_xml = ""
|
||||||
@@ -303,3 +282,36 @@ for settingxml in settings:
|
|||||||
|
|
||||||
outfile.write("</nm-setting-docs>\n")
|
outfile.write("</nm-setting-docs>\n")
|
||||||
outfile.close()
|
outfile.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"-l",
|
||||||
|
"--lib-path",
|
||||||
|
metavar="PATH",
|
||||||
|
action="append",
|
||||||
|
help="path to scan for shared libraries",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-g",
|
||||||
|
"--gir",
|
||||||
|
metavar="FILE",
|
||||||
|
help="NM-1.0.gir file",
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--output",
|
||||||
|
metavar="FILE",
|
||||||
|
help="output file",
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.lib_path:
|
||||||
|
for lib in args.lib_path:
|
||||||
|
GIRepository.Repository.prepend_library_path(lib)
|
||||||
|
|
||||||
|
main(args.gir, args.output)
|
||||||
|
Reference in New Issue
Block a user