lilypond-1.3.140
[lilypond.git] / bin / flower.py
blob768a56eb611884b5978494ca4da01b9c1b6579d5
1 #!@PYTHON@
3 #
4 # flower.py -- python flower lib
5 #
6 # source file of the GNU LilyPond music typesetter
7 #
8 # (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #
11 import sys
13 class File:
14 """silly wrapper for Python file object."""
15 def __init__ (self,nm, mode='r'):
16 if nm:
17 self.file_ = open (nm, mode);
18 elif mode == 'w':
19 self.file_ = sys.stdout
20 else:
21 self.file_ = sys.stdin
23 self.eof_ = 0;
24 def readline (self):
25 l= self.file_.readline ();
26 if not l:
27 self.eof_ = 1;
28 return l;
29 def write (self, str):
30 self.file_.write (str)
31 def eof (self):
32 return self.eof_
33 def close (self):
34 self.file_.close ()
35 def __del__ (self):
36 self.close ();
40 import fnmatch
41 import os
43 _debug = 0
45 _prune = ['(*)']
48 def my_find(patterns, dir = os.curdir):
49 list = []
50 names = os.listdir(dir)
51 names.sort()
52 for name in names:
53 if name in (os.curdir, os.pardir):
54 continue
55 fullname = os.path.join(dir, name)
56 for pat in patterns:
57 if fnmatch.fnmatch(name, pat):
58 list.append(fullname)
59 if os.path.isdir(fullname) and not os.path.islink(fullname):
60 for p in _prune:
61 if fnmatch.fnmatch(name, p):
62 if _debug: print "skip", `fullname`
63 break
64 else:
65 if _debug: print "descend into", `fullname`
66 found = my_find(patterns, fullname)
67 if found:
68 list = list + found
69 return list
71 def multiple_find(pats, dirnames):
72 from find import find
73 l = []
74 for d in dirnames:
75 l = l + my_find(pats, d)
76 return l
78 def file_exist_b(name):
79 try:
80 f = open(name)
81 except IOError:
82 return 0
83 f.close ()
84 return 1