This repository has been archived by the owner on Feb 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlampadas-filter
executable file
·66 lines (60 loc) · 2.01 KB
/
lampadas-filter
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
#! /usr/bin/python
#
# This file is part of the Lampadas Documentation System.
#
# Copyright (c) 2000, 2001, 2002 David Merrill <[email protected]>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# This script will do any special little cleanups that we want to do on source
# files.
import fnmatch
import os
import sys
import stat
HTML_ENTITIES = {' ': ' ',
'$': '$'}
def filter_file(filename):
print 'Filtering file ' + filename
filestat = os.stat(filename)
fileatime = filestat[stat.ST_ATIME]
filemtime = filestat[stat.ST_MTIME]
fh = open(filename, 'r')
buffer = fh.read()
fh.close()
for char in HTML_ENTITIES.keys():
buffer = buffer.replace(char, HTML_ENTITIES[char])
fh = open(filename, 'w')
fh.write(buffer)
fh.close()
os.utime(filename, [fileatime, filemtime])
return
def callback(arg, directory, files):
for file in files:
if fnmatch.fnmatch(file, arg):
absfilename = os.path.abspath(os.path.join(directory, file))
filter_file(absfilename)
# Options passed on the command line
if len(sys.argv) <> 2:
sys.exit(1)
filename = sys.argv[1]
filestat = os.stat(filename)
filemode = filestat[stat.ST_MODE]
if stat.S_ISDIR(filemode)==1:
os.path.walk(filename, callback, '*.sgml')
os.path.walk(filename, callback, '*.xml')
else:
filter_file(filename)