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 os import path
30
31 from translate.storage import factory
32
33
35 """This class represents a directory."""
36
38 self.dir = dir
39 self.filedata = []
40
42 """Iterator over (dir, filename) for all files in this directory."""
43 if not self.filedata:
44 self.scanfiles()
45 for filetuple in self.filedata:
46 yield filetuple
47
49 """Returns a list of (dir, filename) tuples for all the file names in
50 this directory."""
51 return [filetuple for filetuple in self.file_iter()]
52
54 """Iterator over all the units in all the files in this directory."""
55 for dirname, filename in self.file_iter():
56 store = factory.getobject(path.join(dirname, filename))
57
58 for unit in store.unit_iter():
59 yield unit
60
62 """List of all the units in all the files in this directory."""
63 return [unit for unit in self.unit_iter()]
64
66 """Populate the internal file data."""
67 self.filedata = []
68
69 def addfile(arg, dirname, fnames):
70 for fname in fnames:
71 if path.isfile(path.join(dirname, fname)):
72 self.filedata.append((dirname, fname))
73
74 path.walk(self.dir, addfile, None)
75