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

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

Initial release

File size: 4.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.interfaces;
21
22import appstream.Component;
23import glib.KeyFile;
24
25import std.string;
26import std.container;
27public import asgen.datastore;
28
29
30/**
31 * Represents a distribution package in the generator.
32 */
33abstract class Package
34{
35    @property string name () const @safe pure;
36    @property string ver () const @safe pure;
37    @property string arch () const @safe pure;
38    @property string maintainer () const;
39
40    /**
41     * A associative array containing package descriptions.
42     * Key is the language (or locale), value the description.
43     *
44     * E.g.: ["en": "A description.", "de": "Eine Beschreibung"]
45     */
46    @property const(string[string]) description () const;
47
48    /**
49     * Filename of the package. This string is only used for
50     * issue reporting and other information, the file is never
51     * accessed directly (all data is retrieved via getFileData())
52     */
53    @property string filename () const;
54
55    /**
56     * A list payload files this package contains.
57     */
58    @property string[] contents ();
59
60    /**
61     * Obtain data for a specific file in the package.
62     */
63    abstract const(ubyte)[] getFileData (string fname);
64
65    /**
66     * Close the package. This function is called when we will
67     * no longer request any file data from this package.
68     */
69    abstract void close () {};
70
71    /**
72     * Retrieve backend-specific translations.
73     *
74     * (currently only used by the Ubuntu backend)
75     */
76    string[string] getDesktopFileTranslations (KeyFile desktopFile, const string text) { return null; }
77
78    private string pkid;
79    /**
80     * Get the unique identifier for this package.
81     * The ID is supposed to be unique per backend, it should never appear
82     * multiple times in suites/sections.
83     */
84    @property
85    final string id () @safe pure
86    {
87        import std.array : empty;
88        if (pkid.empty)
89            pkid = "%s/%s/%s".format (this.name, this.ver, this.arch);
90        return pkid;
91    }
92
93    /**
94     * Check if the package is valid.
95     * A Package must at least have a name, version and architecture defined.
96     */
97    @safe pure
98    final bool isValid ()
99    {
100        import std.array : empty;
101        return (!name.empty) &&
102               (!ver.empty) &&
103               (!arch.empty);
104    }
105
106    @safe pure override
107    string toString ()
108    {
109        return id;
110    }
111}
112
113/**
114 * An index of information about packages in a distribution.
115 */
116interface PackageIndex
117{
118    /**
119     * Called after a set of operations has completed, which allows the index to
120     * release memory it might have allocated for cached data, or delete temporary
121     * files.
122     **/
123    void release ();
124
125    /**
126     * Get a list of packages for the given suite/section/arch triplet.
127     * The PackageIndex should cache the data if obtaining it is an expensive
128     * operation, since the generator might query the data multiple times.
129     **/
130    Package[] packagesFor (string suite,
131                           string section,
132                           string arch);
133
134    /**
135     * Check if the index for the given suite/section/arch triplet has changed since
136     * the last generator run. The index can use the (get/set)RepoInfo methods on DataCache
137     * to store mtime or checksum data for the given suite.
138     * For the lifetime of the PackagesIndex, this method must return the same result,
139     * which means an internal cache is useful.
140     */
141    bool hasChanges (DataStore dstore,
142                     string suite,
143                     string section,
144                     string arch);
145}
Note: See TracBrowser for help on using the repository browser.