source: appstream-generator/src/asgen/backends/rpmmd/rpmpkgindex.d @ 4841

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

Initial release

File size: 2.3 KB
Line 
1/*
2 * Copyright (C) 2016 Matthias Klumpp <matthias@tenstral.net>
3 *
4 * Licensed under the GNU Lesser General Public License Version 3
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the license, or
9 * (at your option) any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20module asgen.backends.rpmmd.rpmpkgindex;
21
22import std.stdio;
23import std.path;
24import std.string;
25import std.algorithm : canFind;
26static import std.file;
27
28import asgen.logging;
29import asgen.backends.interfaces;
30import asgen.backends.rpmmd.rpmpkg;
31
32
33final class RPMPackageIndex : PackageIndex
34{
35
36private:
37    string rootDir;
38    Package[][string] pkgCache;
39
40public:
41
42    this (string dir)
43    {
44        this.rootDir = dir;
45        if (!std.file.exists (dir))
46            throw new Exception ("Directory '%s' does not exist.", dir);
47    }
48
49    void release ()
50    {
51        pkgCache = null;
52    }
53
54    private void setPkgDescription (RPMPackage pkg, string pkgDesc)
55    {
56        if (pkgDesc is null)
57            return;
58
59        auto desc = "<p>%s</p>".format (pkgDesc);
60        pkg.setDescription (desc, "C");
61    }
62
63    private Package[] loadPackages (string suite, string section, string arch)
64    {
65        auto metadataRoot = buildPath (rootDir, "distrib", suite, arch, "media", section, "release", "repodata");
66
67        // read repomd.xml
68
69        Package[] pkgs;
70        return pkgs;
71    }
72
73    Package[] packagesFor (string suite, string section, string arch)
74    {
75        immutable id = "%s-%s-%s".format (suite, section, arch);
76        if (id !in pkgCache) {
77            auto pkgs = loadPackages (suite, section, arch);
78            synchronized (this) pkgCache[id] = pkgs;
79        }
80
81        return pkgCache[id];
82    }
83
84    bool hasChanges (DataStore dstore, string suite, string section, string arch)
85    {
86        return true;
87    }
88}
Note: See TracBrowser for help on using the repository browser.