File: run.py

package info (click to toggle)
txt2tags 2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,264 kB
  • ctags: 471
  • sloc: python: 2,461; lisp: 414; ruby: 347; xml: 96; php: 95; sh: 83; makefile: 26
file content (65 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# txt2tags nesting marks tester (http://txt2tags.sf.net)
# See also: ../run.py ../lib.py
#

import os, sys, string, glob

sys.path.insert(0, '..')
import lib
del sys.path[0]

# sux
lib.OK = lib.FAILED = 0
lib.ERROR_FILES = []

# left files are generated from right ones (using smart filters)
ALIASES = {
	'numlist' : 'list',
	'deflist' : 'list',
}

# smart filters to allow source inheritance and macros normalization
FILTERS = {
  'deflist' : [ ('pre', '^-( |$)', r':\1') ],
  'numlist' : [ ('pre', '^-( |$)', r'+\1') ],
}

# convert FILTERS tuples to txt2tags pre/postproc rules
def addFilters(filters):
	if not filters: return []
	config = []
	cmdline = []
	for filter in filters:
		config.append("%%!%sproc: '%s' '%s'"%filter)
	if config:
		lib.WriteFile(lib.CONFIG_FILE, string.join(config, '\n'))
		cmdline = ['-C', lib.CONFIG_FILE]
	return cmdline

def run():
	# test all .t2t files found
	for infile in glob.glob("*.t2t"):
		basename = string.replace(infile, '.t2t', '')
		outfile = basename + '.html'
		if lib.initTest(basename, infile, outfile):
			cmdline = [infile]
			lib.convert(cmdline)
			lib.diff(outfile)
	# using smart filters, same files generate more than one output
	for alias in ALIASES.keys():
		infile = ALIASES[alias] + '.t2t'
		outfile = alias + '.html'
		if lib.initTest(alias, infile, outfile):
			cmdline = addFilters(FILTERS.get(alias))
			cmdline.append('-H')
			cmdline.extend(['-o', outfile, infile])
			lib.convert(cmdline)
			lib.diff(outfile)
	# clean up
	if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE)
	
	return lib.OK, lib.FAILED, lib.ERROR_FILES

if __name__ == '__main__':
	print lib.MSG_RUN_ALONE