File: lib.py

package info (click to toggle)
txt2tags 2.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 2,448 kB
  • ctags: 706
  • sloc: python: 2,323; lisp: 414; ruby: 347; php: 114; sh: 81; makefile: 67; xml: 59
file content (83 lines) | stat: -rw-r--r-- 1,719 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
# txt2tags test-suite library (http://txt2tags.sf.net)
# See also: run.py, */run.py
#

import os, string, time

# default program call to all tests
TXT2TAGS = "txt2tags -q --no-rc"

CONFIG_FILE = 'config'
CSS_FILE = 'css'
DIR_OK = 'ok'
DIR_ERROR = 'error'

OK = FAILED = 0
ERROR_FILES = []

MSG_RUN_ALONE = "No No No. Call me with ../run.py\nI can't be runned alone."

#
# file tools
#
def ReadFile(filename):
	return open(filename, 'r').read()

def WriteFile(filename, content=''):
	f = open(filename, 'w')
	f.write(content)
	f.close()

def MoveFile(orig, target):
	if os.path.isfile(target): os.remove(target)
	os.link(orig, target)
	os.remove(orig)

#
# auxiliar tools
#
def initTest(name, infile, outfile):
		okfile  = os.path.join(DIR_OK, outfile)
		print '  Testing %s ...' % name,
		if not os.path.isfile(okfile):
			print 'Skipping test (missing %s)' % okfile
			return False
		return True

def getFileMtime(file):
	ret = "-NO-MTIME-"
	if os.path.isfile(file):
		ret = time.strftime('%Y%m%d',time.localtime(os.path.getmtime(file)))
	return ret

def getCurrentDate():
	return time.strftime('%Y%m%d',time.localtime(time.time()))

#
# the hot tools
#
def convert(options):
	if type(options) in [type(()), type([])]:
		options = string.join(options, ' ')
	cmdline = TXT2TAGS + ' ' + options
	#print "+ Executing:",cmdline
	os.system(cmdline)

def diff(file):
	global OK, FAILED, ERROR_FILES
	okfile = os.path.join(DIR_OK, file)
	out = ReadFile(file)
	ok = ReadFile(okfile)
	if out != ok:
		print 'FAILED'
		FAILED = FAILED + 1
		if not os.path.isdir(DIR_ERROR):
			os.mkdir(DIR_ERROR)
		MoveFile(file, os.path.join(DIR_ERROR, file))
		ERROR_FILES.append(file)
	else:
		print 'OK'
		OK = OK + 1
		os.remove(file)