source: appstream-generator/src/asgen/backends/ubuntu/ubupkgindex.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 2.2 KB
Line 
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 * Author: Iain Lane <iain.lane@canonical.com>
4 *
5 * Licensed under the GNU Lesser General Public License Version 3
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the license, or
10 * (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21module asgen.backends.ubuntu.ubupkgindex;
22
23import std.container : Array, make;
24import std.array : appender;
25
26import asgen.backends.debian;
27import asgen.backends.interfaces;
28import asgen.backends.ubuntu.ubupkg;
29
30final class UbuntuPackageIndex : DebianPackageIndex
31{
32
33private:
34    Array!Package langpacks;
35
36public:
37    this (string dir)
38    {
39        /*
40         * UbuntuPackage needs to extract the langpacks, so we give it an array
41         * of langpacks. There is a small overhead when computing this array
42         * which might be unnecessary if no processed packages are using
43         * langpacks, but otherwise we need to keep a reference to all packages
44         * around, which is very expensive.
45         */
46        langpacks = make!(Array!Package);
47        super (dir);
48    }
49
50    override
51    DebPackage newPackage (string name, string ver, string arch)
52    {
53        return new UbuntuPackage (name, ver, arch, tmpDir, langpacks);
54    }
55
56    override
57    Package[] packagesFor (string suite, string section, string arch)
58    {
59        import std.string : startsWith;
60
61        auto pkgs = super.packagesFor (suite, section, arch);
62        auto pkgslangpacks = appender!(Package[]);
63
64        foreach (ref pkg; pkgs) {
65                if (pkg.name.startsWith ("language-pack-"))
66                    pkgslangpacks ~= pkg;
67        }
68
69        langpacks ~= pkgslangpacks.data;
70
71        return pkgs;
72    }
73}
Note: See TracBrowser for help on using the repository browser.