lasso/lasso/extract_sections.py

63 lines
2.1 KiB
Python
Raw Normal View History

Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
#! /usr/bin/env python
import io
Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
import re
import sys
import os
import os.path
Make more Python scripts compatible with both Py2 and Py3 While porting other Python code in the repo to run under Py3 (as well as Py2) it was discovered there were a number of other Python scripts which also needed porting. However these scripts are never invoked during a build so there was no easy way to test the porting work. I assume these scripts are for developers only and/or are historical. Because there was no way for me to test the porting changes on these scripts I did not want to include the changes in the patch for the Py3 porting which fixed scripts that are invoked during the build (the former patch is mandatory, this patch is optional at the moment). I did verify the scripts compile cleanly under both Py2 and Py3, however it's possible I missed porting something or the error does not show up until run-time. Examples of the required changes are: * Replace use of the built-in function file() with open(). file() does not exist in Py3, open works in both Py2 and Py3. The code was also modified to use a file context manager (e.g. with open(xxx) as f:). This assures open files are properly closed when the code block using the file goes out of scope. This is a standard modern Python idiom. * Replace all use of the print keyword with the six.print_() function, which itself is an emulation of Py3's print function. Py3 no longer has a print keyword, only a print() function. * The dict methods .keys(), .values(), .items() no longer return a list in Py3, instead they return a "view" object which is an iterator whose result is an unordered set. The most notable consequence is you cannot index the result of these functions like your could in Py2 (e.g. dict.keys()[0] will raise a run time exception). * Replace use of StringIO.StringIO and cStringIO with six.StringIO. Py3 no longer has cStringIO and the six variant handles the correct import. * Py3 no longer allows the "except xxx, variable" syntax, where variable appering after the comma is assigned the exception object, you must use the "as" keyword to perform the variable assignment (e.g. execpt xxx as variable) * Python PEP 3113 removed tuple parameter unpacking. Therefore you can no longer define a formal parameter list that contains tuple notation representing a single parameter that is unpacked into multiple arguments. License: MIT Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
from six import print_
Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
enable_wsf = False
if '-wsf' in sys.argv:
enable_wsf = True
if len(sys.argv) == 2+enable_wsf:
srcdir = sys.argv[1]
else:
srcdir = '.'
for root, dirs, files in os.walk(srcdir):
prefixes = list()
for file in files:
if file.endswith('.c'):
prefixes.append(os.path.splitext(file)[0])
for prefix in prefixes:
try:
header = io.open(os.path.join(root, prefix + '.h'), encoding='utf-8').read()
implementation = io.open(os.path.join(root, prefix + '.c'), encoding='utf-8').read()
Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
exported_functions = re.findall('LASSO_EXPORT.*(lasso_\w*)', header)
normal_functions = sorted ([ x for x in exported_functions if not x.endswith('get_type') ])
get_type = [ x for x in exported_functions if x.endswith('get_type') ][0]
file_name = re.findall('lasso_(.*)_get_type', get_type)[0]
try:
macro_type = re.findall('LASSO_(\w*)_CLASS\(', header)[0]
except:
macro_type = None
try:
type = re.findall(r'^struct _(Lasso\w*)', header, re.MULTILINE)[0]
except:
type = None
types = re.findall('^} (Lasso\w*);', header)
def convert(x):
if '%s' in x:
return x % macro_type
else:
return x
if type and macro_type:
standard_decl = [ convert(x) for x in [ 'LASSO_%s', 'LASSO_IS_%s', 'LASSO_TYPE_%s', get_type, 'LASSO_%s_CLASS', 'LASSO_IS_%s_CLASS', 'LASSO_%s_GET_CLASS' ] ]
Make more Python scripts compatible with both Py2 and Py3 While porting other Python code in the repo to run under Py3 (as well as Py2) it was discovered there were a number of other Python scripts which also needed porting. However these scripts are never invoked during a build so there was no easy way to test the porting work. I assume these scripts are for developers only and/or are historical. Because there was no way for me to test the porting changes on these scripts I did not want to include the changes in the patch for the Py3 porting which fixed scripts that are invoked during the build (the former patch is mandatory, this patch is optional at the moment). I did verify the scripts compile cleanly under both Py2 and Py3, however it's possible I missed porting something or the error does not show up until run-time. Examples of the required changes are: * Replace use of the built-in function file() with open(). file() does not exist in Py3, open works in both Py2 and Py3. The code was also modified to use a file context manager (e.g. with open(xxx) as f:). This assures open files are properly closed when the code block using the file goes out of scope. This is a standard modern Python idiom. * Replace all use of the print keyword with the six.print_() function, which itself is an emulation of Py3's print function. Py3 no longer has a print keyword, only a print() function. * The dict methods .keys(), .values(), .items() no longer return a list in Py3, instead they return a "view" object which is an iterator whose result is an unordered set. The most notable consequence is you cannot index the result of these functions like your could in Py2 (e.g. dict.keys()[0] will raise a run time exception). * Replace use of StringIO.StringIO and cStringIO with six.StringIO. Py3 no longer has cStringIO and the six variant handles the correct import. * Py3 no longer allows the "except xxx, variable" syntax, where variable appering after the comma is assigned the exception object, you must use the "as" keyword to perform the variable assignment (e.g. execpt xxx as variable) * Python PEP 3113 removed tuple parameter unpacking. Therefore you can no longer define a formal parameter list that contains tuple notation representing a single parameter that is unpacked into multiple arguments. License: MIT Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
print_('')
print_('<SECTION>')
print_('<FILE>%s</FILE>' % file_name)
print_('<TITLE>%s</TITLE>' % type)
print_(type)
Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
for x in types + normal_functions:
Make more Python scripts compatible with both Py2 and Py3 While porting other Python code in the repo to run under Py3 (as well as Py2) it was discovered there were a number of other Python scripts which also needed porting. However these scripts are never invoked during a build so there was no easy way to test the porting work. I assume these scripts are for developers only and/or are historical. Because there was no way for me to test the porting changes on these scripts I did not want to include the changes in the patch for the Py3 porting which fixed scripts that are invoked during the build (the former patch is mandatory, this patch is optional at the moment). I did verify the scripts compile cleanly under both Py2 and Py3, however it's possible I missed porting something or the error does not show up until run-time. Examples of the required changes are: * Replace use of the built-in function file() with open(). file() does not exist in Py3, open works in both Py2 and Py3. The code was also modified to use a file context manager (e.g. with open(xxx) as f:). This assures open files are properly closed when the code block using the file goes out of scope. This is a standard modern Python idiom. * Replace all use of the print keyword with the six.print_() function, which itself is an emulation of Py3's print function. Py3 no longer has a print keyword, only a print() function. * The dict methods .keys(), .values(), .items() no longer return a list in Py3, instead they return a "view" object which is an iterator whose result is an unordered set. The most notable consequence is you cannot index the result of these functions like your could in Py2 (e.g. dict.keys()[0] will raise a run time exception). * Replace use of StringIO.StringIO and cStringIO with six.StringIO. Py3 no longer has cStringIO and the six variant handles the correct import. * Py3 no longer allows the "except xxx, variable" syntax, where variable appering after the comma is assigned the exception object, you must use the "as" keyword to perform the variable assignment (e.g. execpt xxx as variable) * Python PEP 3113 removed tuple parameter unpacking. Therefore you can no longer define a formal parameter list that contains tuple notation representing a single parameter that is unpacked into multiple arguments. License: MIT Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
print_(x)
print_('<SUBSECTION Standard>')
Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
for x in standard_decl:
Make more Python scripts compatible with both Py2 and Py3 While porting other Python code in the repo to run under Py3 (as well as Py2) it was discovered there were a number of other Python scripts which also needed porting. However these scripts are never invoked during a build so there was no easy way to test the porting work. I assume these scripts are for developers only and/or are historical. Because there was no way for me to test the porting changes on these scripts I did not want to include the changes in the patch for the Py3 porting which fixed scripts that are invoked during the build (the former patch is mandatory, this patch is optional at the moment). I did verify the scripts compile cleanly under both Py2 and Py3, however it's possible I missed porting something or the error does not show up until run-time. Examples of the required changes are: * Replace use of the built-in function file() with open(). file() does not exist in Py3, open works in both Py2 and Py3. The code was also modified to use a file context manager (e.g. with open(xxx) as f:). This assures open files are properly closed when the code block using the file goes out of scope. This is a standard modern Python idiom. * Replace all use of the print keyword with the six.print_() function, which itself is an emulation of Py3's print function. Py3 no longer has a print keyword, only a print() function. * The dict methods .keys(), .values(), .items() no longer return a list in Py3, instead they return a "view" object which is an iterator whose result is an unordered set. The most notable consequence is you cannot index the result of these functions like your could in Py2 (e.g. dict.keys()[0] will raise a run time exception). * Replace use of StringIO.StringIO and cStringIO with six.StringIO. Py3 no longer has cStringIO and the six variant handles the correct import. * Py3 no longer allows the "except xxx, variable" syntax, where variable appering after the comma is assigned the exception object, you must use the "as" keyword to perform the variable assignment (e.g. execpt xxx as variable) * Python PEP 3113 removed tuple parameter unpacking. Therefore you can no longer define a formal parameter list that contains tuple notation representing a single parameter that is unpacked into multiple arguments. License: MIT Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
print_(x)
print_('</SECTION>')
Docs: change the doc production and lot of other fixes * lasso/Makefile.am: distribute extract_sections.py * docs/references/lasso/lasso.types.in: add missing class (mainly SAML2 and ID-WSF 1.0/2.0) from docs/references/lasso.types.in * lasso/xml/strings.h: add lots of documentation, or at least documentation template to strings constants. * id-ff/login.h: * saml-2.0/assertion_query.h: * xml/xml.h: document undocumented enumerations. * lasso/errors.h: add proper documentation about error codes. * lasso/errors.c: new version of the lasso_strerror function * lasso/build_strerror.py: update the script that generater lasso_strerror from the documentation comments. Remove usage of OFTYPE * lasso/id-ff/session.c: * lasso/id-ff/session.h: remove usage of oftype, prefer gtk-introspection annotations instead. * lasso/id-wsf/data_service.h: * lasso/id-wsf/data_service.c: do the same. Add a script to build lasso-sections.txt * lasso/extract_sections.py: this script parses header files and generated lasso-sections.txt content for GObject class descriptions. Add a template file for the lasso-section.txt file * docs/references/lasso-sections.txt.in: this file serves as a base for the generation of lasso-sections.txt Update docs/references/Makefile.am for generating lasso-sections.txt * docs/references/Makefile.am: always rebuild template, using out of source build directory is too weird without it. call new script extract_sections.py to regenerate lasso-sections.txt if header files changed. Update lasso.sgml file with all missing sections * docs/reference/lasso.sgml: add all missing sections, mainly objects from XML schemas. * docs/reference/lasso-sections.txt: update it * *.c: add section documentation to some files. * lasso/xml/strings.h: fix bad usage or docbook markup
2009-08-26 17:15:07 +02:00
except:
continue