]> git.donarmstrong.com Git - lilypond.git/blob - bin/flower.py
release: 0.1.44
[lilypond.git] / bin / flower.py
1 #!@PYTHON@
2
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
10
11 class File:
12     """silly wrapper for Python file object."""
13     def __init__ (self,nm, mode='r'):
14         if nm:
15             self.file_ = open (nm, mode);
16         elif mode == 'w':
17             self.file_ = sys.stdout
18         else:
19             self.file_ = sys.stdin
20             
21         self.eof_ = 0;
22     def readline (self):
23         l=  self.file_.readline ();
24         if not l:
25             self.eof_ = 1;
26         return l;
27     def write (self, str):
28         self.file_.write (str)
29     def eof (self):
30         return self.eof_
31     def close (self):
32         self.file_.close ()
33     def __del__ (self):
34         self.close ();
35
36
37
38 import fnmatch
39 import os
40
41 _debug = 0
42
43 _prune = ['(*)']
44
45
46 def my_find(patterns, dir = os.curdir):
47         list = []
48         names = os.listdir(dir)
49         names.sort()
50         for name in names:
51                 if name in (os.curdir, os.pardir):
52                         continue
53                 fullname = os.path.join(dir, name)
54                 for pat in patterns:
55                     if fnmatch.fnmatch(name, pat):
56                         list.append(fullname)
57                 if os.path.isdir(fullname) and not os.path.islink(fullname):
58                         for p in _prune:
59                                 if fnmatch.fnmatch(name, p):
60                                         if _debug: print "skip", `fullname`
61                                         break
62                         else:
63                                 if _debug: print "descend into", `fullname`
64                                 found = my_find(patterns, fullname)
65                                 if found:
66                                     list = list + found
67         return list
68
69 def multiple_find(pats, dirnames):
70     from find import find
71     l = []
72     for d in dirnames:
73         l = l + my_find(pats,  d)
74     return l