Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/e0eb2d0f0822
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 00:40:29 2012
Кодировка:
allpy: e0eb2d0f0822

allpy

changeset 1110:e0eb2d0f0822

markup_to_html. Html template files and path to imported module can be passed on the command line. In the imported module can be function "init" which takes an alignment for adding some attributes after alignment is loaded.
author Mmmasha!
date Tue, 19 Jun 2012 16:55:37 +0400
parents f0d2f37d05b9
children 7bc44212ca15
files utils/markup_to_html.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/utils/markup_to_html.py	Tue Jun 19 15:51:12 2012 +0400
     1.2 +++ b/utils/markup_to_html.py	Tue Jun 19 16:55:37 2012 +0400
     1.3 @@ -13,10 +13,14 @@
     1.4  template_file = join(template_prefix, "markup_to_html.html")
     1.5  
     1.6  parser = optparse.OptionParser(description=__doc__, usage="%prog [options] [infile]")
     1.7 +parser.add_option("-t", "--template-file", default=template_file,
     1.8 +	help="HTML template file")
     1.9  parser.add_option("-o", "--outfile",
    1.10  	help="Output file name, default: stdout")
    1.11 +parser.add_option("-p", "--import-path", default=".",
    1.12 +	help="Path to imported module")
    1.13  parser.add_option("-m", "--import-module",
    1.14 -	help="Import this module before anything, useful for custom markup classes")
    1.15 +	help="import this module before anything, useful for custom markup classes")
    1.16  options, args = parser.parse_args()
    1.17  
    1.18  outfile = options.outfile and open(options.outfile, "w") or sys.stdout
    1.19 @@ -24,9 +28,11 @@
    1.20  if len(args) > 1:
    1.21  	parser.error("Too many arguments on the command line")
    1.22  
    1.23 +module = None
    1.24 +
    1.25  if options.import_module:
    1.26 -	sys.path.append(".")
    1.27 -	__import__(options.import_module)
    1.28 +	sys.path.insert(0, options.import_path)
    1.29 +	module = __import__(options.import_module)
    1.30  
    1.31  aln = protein.Alignment().append_file(infile, format="markup")
    1.32  
    1.33 @@ -43,6 +49,9 @@
    1.34  		items += repr_items([('sequence ' + k, v) for k, v in vars(sequence).items() if k != 'markups'])
    1.35  		monomer.description = "\n".join(items)
    1.36  
    1.37 +if hasattr(module, 'init'):
    1.38 +	module.init(aln)
    1.39 +
    1.40  rows = aln.rows_as_lists()
    1.41 -template = Template(open(template_file).read())
    1.42 +template = Template(open(options.template_file).read())
    1.43  outfile.write(template.render(vars()))