2 # -*- coding: utf-8 -*-
4 # Copyright 2005, 2006 Zuza Software Foundation
6 # This file is part of Pootle.
8 # Pootle is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # Pootle is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Pootle; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 """processes conflicts from msgmerge and turns them into Pootle suggestions"""
24 from Pootle
import pootlefile
25 from Pootle
import projects
28 conflictmarker
= "#-#-#-#-#"
30 def processfile(filename
):
31 dummyproject
= projects
.DummyProject(os
.path
.dirname(filename
), None)
32 pofile
= pootlefile
.pootlefile(dummyproject
, os
.path
.basename(filename
))
35 for item
in pofile
.statistics
.getstats()["total"]:
36 poentry
= pofile
.units
[item
]
37 if poentry
.hasplural():
38 targets
= poentry
.target
.strings
40 targets
= [poentry
.target
]
41 for target
in targets
:
42 if conflictmarker
in target
:
43 conflictitems
.append((item
, targets
))
45 for item
, targets
in conflictitems
:
47 for target
in targets
:
48 if conflictmarker
not in target
:
49 replacetargets
.append(target
)
51 lines
= target
.split("\n")
55 if line
.startswith(conflictmarker
) and line
.endswith(conflictmarker
):
57 parts
.append((marker
, part
))
58 marker
= line
[len(conflictmarker
):-len(conflictmarker
)]
63 parts
.append((marker
, part
))
64 for marker
, part
in parts
:
65 pofile
.addsuggestion(item
, part
, marker
.strip())
66 replacetargets
.append("")
68 newvalues
= {"target": replacetargets
}
69 pofile
.updateunit(item
, newvalues
, None, None)
71 def processdir(dirname
):
72 for filename
in os
.listdir(dirname
):
73 pathname
= os
.path
.join(dirname
, filename
)
74 if os
.path
.isdir(pathname
):
76 elif filename
.endswith(os
.extsep
+ "po"):
79 if __name__
== "__main__":
81 for filename
in sys
.argv
[1:]:
82 if os
.path
.isdir(filename
):
84 elif os
.path
.isfile(filename
):
87 print >>sys
.stderr
, "cannot process", filename