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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#!@PYTHON@
#
# gensgmlenv.in
#
# $Id: gensgmlenv.in,v 1.4 2001/05/05 23:07:06 dnedrow Exp $
#
# Generate @etcsgml@/sgml.env, containing definition for SGML_CATALOG_FILES
#
# SGMLtools - an SGML toolkit.
# Copyright (C) 1999 Cees A. de Groot
#
# 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
#
#
"""
head1 NAME
gensgmlenv - Generate @etcsgml@/sgml.env
SYNOPSIS
gensgmlenv
DESCRIPTION
The subroutine gensgmlenv generates a file @etcsgml@/sgml.env that contains
the bourne shell command that sets SGML_CATALOG_FILES. It is meant to be
included in SGML-processing scripts and/or in /etc/profile.
EXCEPTIONS
There are some exceptions which can be thrown by this module. They
are:
Error: Base error. If that module throws an exception, and you don't
want to catch every specific one, catching of Error would be enough.
NoCatalogError: There was no catalog files found.
ReadLinkError: There was an error occured during trial of getting
the real name of the file pointed by a symbolic link.
WriteScriptError: Could not write the configuration script. The type
of the shell will be thrown within the detail attribute.
"""
import glob, os, re, string
from stat import *
class Error(Exception):
pass
class NoCatalogError(Error):
pass
class ReadLinkError(Error):
pass
class WriteScriptError(Error):
pass
_subdot = re.compile("\.\.\/\.\.\/\.\.").sub
_subslash = re.compile("\/\/").sub
def gensgmlenv():
catfiles = []
for link in glob.glob("@etcsgml@/*.cat"):
st = os.lstat( link )
if S_ISLNK(st[ST_MODE]):
file = os.readlink(link)
else:
file = link
file = _subdot("", file, 1)
file = _subslash("/", file)
catfiles.append(file)
if not catfiles:
raise NoCatalogError
files = string.join(catfiles, ":")
try:
sgmlenv = open("@etcsgml@/sgml.env", "w")
sgmlenv.write("SGML_CATALOG_FILES=%s\n"
"export SGML_CATALOG_FILES\n" % files)
sgmlenv.close()
except IOError:
raise WriteScriptError, "writing sh version"
try:
sgmlenv = open("@etcsgml@/sgml.cenv", "w")
sgmlenv.write("setenv SGML_CATALOG_FILES %s\n" % files)
sgmlenv.close()
except IOError:
raise WriteScriptError, "writing csh version"
if __name__ == "__main__":
# testcode
gensgmlenv()
|