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