~ubuntu-branches/ubuntu/oneiric/eyed3/oneiric

« back to all changes in this revision

Viewing changes to src/eyeD3/utils.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt
  • Date: 2006-11-18 01:47:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20061118014738-bcwcoe9gywrgorz2
New upstream version  

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#  along with this program; if not, write to the Free Software
16
16
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
#
18
 
#  $Id: utils.py,v 1.9 2005/02/06 02:03:02 travis Exp $
 
18
#  $Id: utils.py,v 1.11.2.1 2005/12/02 03:18:42 travis Exp $
19
19
################################################################################
20
20
from eyeD3 import *;
21
21
 
29
29
      elif minor == 1:
30
30
         return ID3_V1_1;
31
31
   elif major == 2:
 
32
      if minor == 2:
 
33
         return ID3_V2_2;
32
34
      if minor == 3:
33
35
         return ID3_V2_3;
34
36
      elif minor == 4:
44
46
      elif v == ID3_V1:
45
47
         return "v1.x";
46
48
   elif v & ID3_V2:
47
 
      if v == ID3_V2_3:
 
49
      if v == ID3_V2_2:
 
50
         return "v2.2";
 
51
      elif v == ID3_V2_3:
48
52
         return "v2.3";
49
53
      elif v == ID3_V2_4:
50
54
         return "v2.4";
64
68
      elif v == ID3_V1:
65
69
         return [1, 1, 0];
66
70
   elif v & ID3_V2:
67
 
      if v == ID3_V2_3:
 
71
      if v == ID3_V2_2:
 
72
         return [2, 2, 0];
 
73
      elif v == ID3_V2_3:
68
74
         return [2, 3, 0];
69
75
      elif v == ID3_V2_4:
70
76
         return [2, 4, 0];
85
91
STRICT_ID3 = 0;
86
92
def strictID3():
87
93
   return STRICT_ID3;
 
94
################################################################################
 
95
 
 
96
import os;
 
97
 
 
98
class FileHandler:
 
99
    R_CONT = 0;
 
100
    R_HALT = -1;
 
101
 
 
102
    # MUST return R_CONT or R_HALT
 
103
    def handleFile(self, f):
 
104
        pass
 
105
 
 
106
    # MUST for all files processed return 0 for success and a positive int
 
107
    # for error
 
108
    def handleDone(self):
 
109
        pass
 
110
 
 
111
class FileWalker:
 
112
    def __init__(self, handler, root, excludes = []):
 
113
        self._handler = handler;
 
114
        self._root = root;
 
115
        self._excludes = excludes;
 
116
 
 
117
    def go(self):
 
118
        for (root, dirs, files) in os.walk(self._root):
 
119
            for f in files:
 
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();
 
125
 
 
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:
 
130
                return 1;
 
131
        return 0;
88
132