1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """This module provides functionality to work with directories."""
23
24
25
26
27
28
29 from translate.storage import factory
30 from os import path
31
33 """This class represents a directory."""
35 self.dir = dir
36 self.filedata = []
37
39 """Iterator over (dir, filename) for all files in this directory."""
40 if not self.filedata:
41 self.scanfiles()
42 for filetuple in self.filedata:
43 yield filetuple
44
46 """Returns a list of (dir, filename) tuples for all the file names in
47 this directory."""
48 return [filetuple for filetuple in self.file_iter()]
49
51 """Iterator over all the units in all the files in this directory."""
52 for dirname, filename in self.file_iter():
53 store = factory.getobject(path.join(dirname, filename))
54
55 for unit in store.unit_iter():
56 yield unit
57
59 """List of all the units in all the files in this directory."""
60 return [unit for unit in self.unit_iter()]
61
63 """Populate the internal file data."""
64 self.filedata = []
65 def addfile(arg, dirname, fnames):
66 for fname in fnames:
67 if path.isfile(path.join(dirname, fname)):
68 self.filedata.append((dirname, fname))
69
70 path.walk(self.dir, addfile, None)
71