~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- Copyright 2009 Canonical Ltd.  This software is licensed under the
-- GNU Affero General Public License version 3 (see the file LICENSE).

SET client_min_messages=ERROR;

-- Migrate all POFile.path to a safe value if there athey are just using a path + language code.
CREATE OR REPLACE FUNCTION get_right_path(text, text, text, text) RETURNS text AS
$$
import os.path

if args[3] is None:
    locale = args[2]
else:
    locale = '%s@%s' % (args[2], args[3])

path = os.path.dirname(args[0])
templatename = os.path.basename(args[0]).rsplit('.', 1)[0]

return os.path.join(path, '%s-%s.po' % (templatename, locale))
$$ LANGUAGE plpythonu IMMUTABLE;

UPDATE POFile
SET path=(SELECT get_right_path(POTemplate.path, POFile.path, language.code, POFile.variant))
FROM Language, POTemplate
WHERE POFile.language = Language.id AND POFile.potemplate = POTemplate.id AND
    EXISTS (
        SELECT pf.id
        FROM POFile pf, POTemplate pt
        WHERE
            POTemplate.distrorelease = pt.distrorelease AND
            POTemplate.sourcepackagename = pt.sourcepackagename AND
            POTemplate.productseries = pt.productseries AND
            POTemplate.id = pf.potemplate AND
            POFile.language = pf.language AND
            POFile.variant = pf.variant AND
            POFile.id <> pf.id);
DROP FUNCTION get_right_path(text, text, text, text);