Unify spacing

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
Gabor Mezei 2024-09-09 17:20:49 +02:00
parent 24d7cc71af
commit a12ed6bcb7
No known key found for this signature in database
GPG Key ID: 6310BD29B0BFF98C

View File

@ -18,6 +18,7 @@ import sys
from abc import ABCMeta from abc import ABCMeta
class Setting: class Setting:
"""Representation of one Mbed TLS mbedtls_config.h pr PSA crypto_config.h setting. """Representation of one Mbed TLS mbedtls_config.h pr PSA crypto_config.h setting.
@ -38,6 +39,7 @@ class Setting:
self.section = section self.section = section
self.configfile = configfile self.configfile = configfile
class Config: class Config:
"""Representation of the Mbed TLS and PSA configuration. """Representation of the Mbed TLS and PSA configuration.
@ -197,6 +199,7 @@ class Config:
return self._get_configfile(name).filename return self._get_configfile(name).filename
def is_full_section(section): def is_full_section(section):
"""Is this section affected by "config.py full" and friends? """Is this section affected by "config.py full" and friends?
@ -445,6 +448,7 @@ def no_platform_adapter(adapter):
return adapter(name, active, section) return adapter(name, active, section)
return continuation return continuation
class ConfigFile(metaclass=ABCMeta): class ConfigFile(metaclass=ABCMeta):
"""Representation of a configuration file.""" """Representation of a configuration file."""
@ -574,6 +578,7 @@ class ConfigFile(metaclass=ABCMeta):
with open(filename, 'w', encoding='utf-8') as output: with open(filename, 'w', encoding='utf-8') as output:
self.write_to_stream(settings, output) self.write_to_stream(settings, output)
class MbedTLSConfigFile(ConfigFile): class MbedTLSConfigFile(ConfigFile):
"""Representation of an MbedTLS configuration file.""" """Representation of an MbedTLS configuration file."""
@ -589,6 +594,7 @@ class MbedTLSConfigFile(ConfigFile):
super().__init__(self.default_path, 'Mbed TLS', filename) super().__init__(self.default_path, 'Mbed TLS', filename)
self.current_section = 'header' self.current_section = 'header'
class CryptoConfigFile(ConfigFile): class CryptoConfigFile(ConfigFile):
"""Representation of a Crypto configuration file.""" """Representation of a Crypto configuration file."""
@ -610,6 +616,7 @@ class CryptoConfigFile(ConfigFile):
def __init__(self, filename=None): def __init__(self, filename=None):
super().__init__(self.default_path, 'Crypto', filename) super().__init__(self.default_path, 'Crypto', filename)
class MbedTLSConfig(Config): class MbedTLSConfig(Config):
"""Representation of the Mbed TLS configuration. """Representation of the Mbed TLS configuration.
@ -635,6 +642,7 @@ class MbedTLSConfig(Config):
super().set(name, value) super().set(name, value)
class CryptoConfig(Config): class CryptoConfig(Config):
"""Representation of the PSA crypto configuration. """Representation of the PSA crypto configuration.
@ -665,6 +673,7 @@ class CryptoConfig(Config):
super().set(name, value) super().set(name, value)
class CombinedConfig(Config): class CombinedConfig(Config):
"""Representation of MbedTLS and PSA crypto configuration """Representation of MbedTLS and PSA crypto configuration
@ -768,49 +777,42 @@ class ConfigTool(metaclass=ABCMeta):
def _common_parser_options(self, file_type): def _common_parser_options(self, file_type):
"""Common parser options for config manipulation tool.""" """Common parser options for config manipulation tool."""
self.parser.add_argument('--file', '-f', self.parser.add_argument(
help="""File to read (and modify if requested). '--file', '-f',
Default: {}. help="""File to read (and modify if requested). Default: {}.
""".format(file_type.default_path)) """.format(file_type.default_path))
self.parser.add_argument('--force', '-o', self.parser.add_argument(
action='store_true', '--force', '-o',
help="""For the set command, if SYMBOL is not action='store_true',
present, add a definition for it.""") help="""For the set command, if SYMBOL is not present, add a definition for it.""")
self.parser.add_argument('--write', '-w', metavar='FILE', self.parser.add_argument(
help="""File to write to instead of the input file.""") '--write', '-w',
metavar='FILE',
help="""File to write to instead of the input file.""")
parser_get = self.subparsers.add_parser('get', parser_get = self.subparsers.add_parser(
help="""Find the value of SYMBOL 'get',
and print it. Exit with help="""Find the value of SYMBOL and print it. Exit with
status 0 if a #define for SYMBOL is status 0 if a #define for SYMBOL is found, 1 otherwise.""")
found, 1 otherwise.
""")
parser_get.add_argument('symbol', metavar='SYMBOL') parser_get.add_argument('symbol', metavar='SYMBOL')
parser_set = self.subparsers.add_parser('set', parser_set = self.subparsers.add_parser(
help="""Set SYMBOL to VALUE. 'set',
If VALUE is omitted, just uncomment help="""Set SYMBOL to VALUE. If VALUE is omitted, just uncomment
the #define for SYMBOL. the #define for SYMBOL. Error out of a line defining
Error out of a line defining SYMBOL (commented or not) is not found, unless --force is passed. """)
SYMBOL (commented or not) is not
found, unless --force is passed.
""")
parser_set.add_argument('symbol', metavar='SYMBOL') parser_set.add_argument('symbol', metavar='SYMBOL')
parser_set.add_argument('value', metavar='VALUE', nargs='?', parser_set.add_argument('value', metavar='VALUE', nargs='?', default='')
default='') parser_set_all = self.subparsers.add_parser(
parser_set_all = self.subparsers.add_parser('set-all', 'set-all',
help="""Uncomment all #define help="""Uncomment all #define whose name contains a match for REGEX.""")
whose name contains a match for
REGEX.""")
parser_set_all.add_argument('regexs', metavar='REGEX', nargs='*') parser_set_all.add_argument('regexs', metavar='REGEX', nargs='*')
parser_unset = self.subparsers.add_parser('unset', parser_unset = self.subparsers.add_parser(
help="""Comment out the #define 'unset',
for SYMBOL. Do nothing if none help="""Comment out the #define for SYMBOL. Do nothing if none is present.""")
is present.""")
parser_unset.add_argument('symbol', metavar='SYMBOL') parser_unset.add_argument('symbol', metavar='SYMBOL')
parser_unset_all = self.subparsers.add_parser('unset-all', parser_unset_all = self.subparsers.add_parser(
help="""Comment out all #define 'unset-all',
whose name contains a match for help="""Comment out all #define whose name contains a match for REGEX.""")
REGEX.""")
parser_unset_all.add_argument('regexs', metavar='REGEX', nargs='*') parser_unset_all.add_argument('regexs', metavar='REGEX', nargs='*')
def custom_parser_options(self): def custom_parser_options(self):
@ -861,41 +863,49 @@ class MbedTLSConfigTool(ConfigTool):
def custom_parser_options(self): def custom_parser_options(self):
"""Adds MbedTLS specific options for the parser.""" """Adds MbedTLS specific options for the parser."""
self.parser.add_argument('--cryptofile', '-c', self.parser.add_argument(
help="""Crypto file to read (and modify if requested). '--cryptofile', '-c',
Default: {}. help="""Crypto file to read (and modify if requested). Default: {}."""
""".format(CryptoConfigFile.default_path)) .format(CryptoConfigFile.default_path))
add_adapter('baremetal', baremetal_adapter, self.add_adapter(
"""Like full, but exclude features that require platform 'baremetal', baremetal_adapter,
features such as file input-output.""") """Like full, but exclude features that require platform features
add_adapter('baremetal_size', baremetal_size_adapter, such as file input-output.
"""Like baremetal, but exclude debugging features. """)
Useful for code size measurements.""") self.add_adapter(
add_adapter('full', full_adapter, 'baremetal_size', baremetal_size_adapter,
"""Uncomment most features. """Like baremetal, but exclude debugging features. Useful for code size measurements.
Exclude alternative implementations and platform support """)
options, as well as some options that are awkward to test. self.add_adapter(
""") 'full', full_adapter,
add_adapter('full_no_deprecated', no_deprecated_adapter(full_adapter), """Uncomment most features.
"""Uncomment most non-deprecated features. Exclude alternative implementations and platform support options, as well as
Like "full", but without deprecated features. some options that are awkward to test.
""") """)
add_adapter('full_no_platform', no_platform_adapter(full_adapter), self.add_adapter(
"""Uncomment most non-platform features. 'full_no_deprecated', no_deprecated_adapter(full_adapter),
Like "full", but without platform features. """Uncomment most non-deprecated features.
""") Like "full", but without deprecated features.
add_adapter('realfull', realfull_adapter, """)
"""Uncomment all boolean #defines. self.add_adapter(
Suitable for generating documentation, but not for building.""") 'full_no_platform', no_platform_adapter(full_adapter),
add_adapter('crypto', crypto_adapter(None), """Uncomment most non-platform features. Like "full", but without platform features.
"""Only include crypto features. Exclude X.509 and TLS.""") """)
add_adapter('crypto_baremetal', crypto_adapter(baremetal_adapter), self.add_adapter(
"""Like baremetal, but with only crypto features, 'realfull', realfull_adapter,
excluding X.509 and TLS.""") """Uncomment all boolean #defines.
add_adapter('crypto_full', crypto_adapter(full_adapter), Suitable for generating documentation, but not for building.
"""Like full, but with only crypto features, """)
excluding X.509 and TLS.""") self.add_adapter(
'crypto', crypto_adapter(None),
"""Only include crypto features. Exclude X.509 and TLS.""")
self.add_adapter(
'crypto_baremetal', crypto_adapter(baremetal_adapter),
"""Like baremetal, but with only crypto features, excluding X.509 and TLS.""")
self.add_adapter(
'crypto_full', crypto_adapter(full_adapter),
"""Like full, but with only crypto features, excluding X.509 and TLS.""")
if __name__ == '__main__': if __name__ == '__main__':