mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
sb: Introduce formatter classes
Use inheritance instead of ifs.
This commit is contained in:
parent
ae338e08e8
commit
5d565849b3
@ -49,6 +49,41 @@ except:
|
|||||||
print 'error: unknown application load error'
|
print 'error: unknown application load error'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
class formatter(object):
|
||||||
|
def format(self):
|
||||||
|
raise error.general('internal error: formatter.format() not implemented')
|
||||||
|
|
||||||
|
def ext(self):
|
||||||
|
raise error.general('internal error: formatter.ext() not implemented')
|
||||||
|
|
||||||
|
class asciidoc_formatter(formatter):
|
||||||
|
def format(self):
|
||||||
|
return 'asciidoc'
|
||||||
|
|
||||||
|
def ext(self):
|
||||||
|
return '.txt'
|
||||||
|
|
||||||
|
class ini_formatter(formatter):
|
||||||
|
def format(self):
|
||||||
|
return 'ini'
|
||||||
|
|
||||||
|
def ext(self):
|
||||||
|
return '.ini'
|
||||||
|
|
||||||
|
class html_formatter(formatter):
|
||||||
|
def format(self):
|
||||||
|
return 'html'
|
||||||
|
|
||||||
|
def ext(self):
|
||||||
|
return '.html'
|
||||||
|
|
||||||
|
class text_formatter(formatter):
|
||||||
|
def format(self):
|
||||||
|
return 'text'
|
||||||
|
|
||||||
|
def ext(self):
|
||||||
|
return '.txt'
|
||||||
|
|
||||||
def _tree_name(path_):
|
def _tree_name(path_):
|
||||||
return path.splitext(path.basename(path_))[0]
|
return path.splitext(path.basename(path_))[0]
|
||||||
|
|
||||||
@ -65,8 +100,9 @@ class report:
|
|||||||
|
|
||||||
line_len = 78
|
line_len = 78
|
||||||
|
|
||||||
def __init__(self, format, _configs, opts, macros = None):
|
def __init__(self, formatter, _configs, opts, macros = None):
|
||||||
self.format = format
|
self.formatter = formatter
|
||||||
|
self.format = formatter.format()
|
||||||
self.configs = _configs
|
self.configs = _configs
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
if macros is None:
|
if macros is None:
|
||||||
@ -581,8 +617,7 @@ def run(args):
|
|||||||
output = opts.get_arg('--output')
|
output = opts.get_arg('--output')
|
||||||
if output is not None:
|
if output is not None:
|
||||||
output = output[1]
|
output = output[1]
|
||||||
format = 'text'
|
formatter = text_formatter()
|
||||||
ext = '.txt'
|
|
||||||
format_opt = opts.get_arg('--format')
|
format_opt = opts.get_arg('--format')
|
||||||
if format_opt:
|
if format_opt:
|
||||||
if len(format_opt) != 2:
|
if len(format_opt) != 2:
|
||||||
@ -590,20 +625,17 @@ def run(args):
|
|||||||
if format_opt[1] == 'text':
|
if format_opt[1] == 'text':
|
||||||
pass
|
pass
|
||||||
elif format_opt[1] == 'asciidoc':
|
elif format_opt[1] == 'asciidoc':
|
||||||
format = 'asciidoc'
|
formatter = asciidoc_formatter()
|
||||||
ext = '.txt'
|
|
||||||
elif format_opt[1] == 'html':
|
elif format_opt[1] == 'html':
|
||||||
format = 'html'
|
formatter = html_formatter()
|
||||||
ext = '.html'
|
|
||||||
elif format_opt[1] == 'ini':
|
elif format_opt[1] == 'ini':
|
||||||
format = 'ini'
|
formatter = ini_formatter()
|
||||||
ext = '.ini'
|
|
||||||
else:
|
else:
|
||||||
raise error.general('invalid format: %s' % (format_opt[1]))
|
raise error.general('invalid format: %s' % (format_opt[1]))
|
||||||
r = report(format, configs, opts)
|
r = report(formatter, configs, opts)
|
||||||
for _config in opts.params():
|
for _config in opts.params():
|
||||||
if output is None:
|
if output is None:
|
||||||
outname = path.splitext(_config)[0] + ext
|
outname = path.splitext(_config)[0] + formatter.ext()
|
||||||
outname = outname.replace('/', '-')
|
outname = outname.replace('/', '-')
|
||||||
else:
|
else:
|
||||||
outname = output
|
outname = output
|
||||||
|
Loading…
x
Reference in New Issue
Block a user