1 # Utils (c) 2002, 2004, 2007 David Turner <david@freetype.org>
4 import string
, sys
, os
, glob
6 # current output directory
11 # This function is used to sort the index. It is a simple lexicographical
12 # sort, except that it places capital letters before lowercase ones.
14 def index_sort( s1
, s2
):
23 m1
= string
.lower( s1
)
24 m2
= string
.lower( s2
)
27 if i
>= l2
or m1
[i
] > m2
[i
]:
44 # Sort input_list, placing the elements of order_list in front.
46 def sort_order_list( input_list
, order_list
):
47 new_list
= order_list
[:]
49 if not id in order_list
:
55 # Open the standard output to a given project documentation file. Use
56 # "output_dir" to determine the filename location if necessary and save the
57 # old stdout in a tuple that is returned by this function.
59 def open_output( filename
):
62 if output_dir
and output_dir
!= "":
63 filename
= output_dir
+ os
.sep
+ filename
65 old_stdout
= sys
.stdout
66 new_file
= open( filename
, "w" )
69 return ( new_file
, old_stdout
)
72 # Close the output that was returned by "close_output".
74 def close_output( output
):
76 sys
.stdout
= output
[1]
79 # Check output directory.
85 if not os
.path
.isdir( output_dir
):
86 sys
.stderr
.write( "argument" + " '" + output_dir
+ "' " +
87 "is not a valid directory" )
92 def file_exists( pathname
):
93 """checks that a given file exists"""
96 file = open( pathname
, "r" )
100 sys
.stderr
.write( pathname
+ " couldn't be accessed\n" )
105 def make_file_list( args
= None ):
106 """builds a list of input files from command-line arguments"""
109 # sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
114 for pathname
in args
:
115 if string
.find( pathname
, '*' ) >= 0:
116 newpath
= glob
.glob( pathname
)
117 newpath
.sort() # sort files -- this is important because
118 # of the order of files
122 file_list
.extend( newpath
)
124 if len( file_list
) == 0:
127 # now filter the file list to remove non-existing ones
128 file_list
= filter( file_exists
, file_list
)