1 ################################################################################
2 # Copyright (C) 2003-2005 Travis Shirk <travis@pobox.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # $Id: utils.py,v 1.11.2.1 2005/12/02 03:18:42 travis Exp $
19 ################################################################################
22 def versionsToConstant(v
):
38 raise str("Invalid ID3 version: %s" % str(v
));
40 def versionToString(v
):
58 if v
== ID3_ANY_VERSION
:
60 raise str("versionToString - Invalid ID3 version constant: %s" % hex(v
));
62 def constantToVersions(v
):
79 raise str("constantToVersions - Invalid ID3 version constant: %s" % hex(v
));
81 ################################################################################
83 prefix
= "eyeD3 trace> ";
88 except UnicodeEncodeError:
94 ################################################################################
102 # MUST return R_CONT or R_HALT
103 def handleFile(self
, f
):
106 # MUST for all files processed return 0 for success and a positive int
108 def handleDone(self
):
112 def __init__(self
, handler
, root
, excludes
= []):
113 self
._handler
= handler
;
115 self
._excludes
= excludes
;
118 for (root
, dirs
, files
) in os
.walk(self
._root
):
120 f
= os
.path
.abspath(root
+ os
.sep
+ f
);
121 if not self
._isExcluded
(f
):
122 if self
._handler
.handleFile(f
) == FileHandler
.R_HALT
:
123 return FileHandler
.R_HALT
;
124 return self
._handler
.handleDone();
126 def _isExcluded(self
, path
):
127 for ex
in self
._excludes
:
128 match
= re
.compile(exd
).search(path
);
129 if match
and match
.start() == 0: