2 from translate
.storage
import statsdb
3 from translate
.filters
import checks
4 from translate
.misc
.multistring
import multistring
8 def getmodtime(filename
):
9 mtime
, size
= statsdb
.get_mod_info(filename
, errors_return_empty
=True, empty_return
=None)
12 class pootlestatistics
:
13 """this represents the statistics known about a file"""
14 def __init__(self
, basefile
):
15 """constructs statistic object for the given file"""
16 # TODO: try and remove circular references between basefile and this class
17 self
.basefile
= basefile
20 self
._unitstats
= None
21 self
.statscache
= statsdb
.StatsCache(STATS_DB_FILE
)
23 def getquickstats(self
):
24 """returns the quick statistics (totals only)"""
26 self
._totals
= self
.statscache
.filetotals(self
.basefile
.filename
, errors_return_empty
=True)
29 def getstats(self
, checker
=None):
30 """reads the stats if neccessary or returns them from the cache"""
32 checker
= self
.basefile
.checker
34 self
._stats
= self
.statscache
.filestats(self
.basefile
.filename
, checker
, errors_return_empty
=True)
37 def purge_totals(self
):
38 """Temporary helper to clean up where needed. We might be able to remove
39 this after the move to cpo."""
42 self
._unitstats
= None
44 def getunitstats(self
):
45 if not self
._unitstats
:
46 self
._unitstats
= self
.statscache
.unitstats(self
.basefile
.filename
, errors_return_empty
=True)
47 return self
._unitstats
49 def updatequickstats(self
, save
=True):
50 """updates the project's quick stats on this file"""
51 totals
= self
.getquickstats()
52 self
.basefile
.project
.updatequickstats(self
.basefile
.pofilename
,
53 totals
.get("translatedsourcewords", 0), totals
.get("translated", 0),
54 totals
.get("fuzzysourcewords", 0), totals
.get("fuzzy", 0),
55 totals
.get("totalsourcewords", 0), totals
.get("total", 0),
58 def reclassifyunit(self
, item
):
59 """Reclassifies all the information in the database and self._stats about
61 unit
= self
.basefile
.getitem(item
)
62 item
= self
.getstats()["total"][item
]
64 classes
= self
.statscache
.recacheunit(self
.basefile
.filename
, self
.basefile
.checker
, unit
)
65 for classname
, matchingitems
in self
.getstats().items():
66 if (classname
in classes
) != (item
in matchingitems
):
67 if classname
in classes
:
68 self
.getstats()[classname
].append(item
)
70 self
.getstats()[classname
].remove(item
)
71 self
.getstats()[classname
].sort()
72 # We should be doing better, but for now it is easiet to simply force a
73 # reload from the database
76 def getitemslen(self
):
77 """gets the number of items in the file"""
78 return self
.getquickstats()["total"]