mirror of
https://github.com/ukui/apt.git
synced 2026-03-09 09:35:45 -07:00
json: Add origins fields to version
Provide access to the origins of a package, such that tools can display information about them; for example, you can write a hook counting security upgrades.
This commit is contained in:
@@ -198,6 +198,33 @@ class APT_HIDDEN JsonWriter
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Write a VerFileIterator to a JsonWriter
|
||||
*/
|
||||
static void verFiletoJson(JsonWriter &writer, CacheFile &, pkgCache::VerFileIterator const &vf)
|
||||
{
|
||||
auto pf = vf.File(); // Packages file
|
||||
auto rf = pf.ReleaseFile(); // release file
|
||||
|
||||
writer.beginObject();
|
||||
if (not rf.end()) {
|
||||
if (rf->Archive != 0)
|
||||
writer.name("archive").value(rf.Archive());
|
||||
if (rf->Codename != 0)
|
||||
writer.name("codename").value(rf.Codename());
|
||||
if (rf->Version != 0)
|
||||
writer.name("version").value(rf.Version());
|
||||
if (rf->Origin != 0)
|
||||
writer.name("origin").value(rf.Origin());
|
||||
if (rf->Label != 0)
|
||||
writer.name("label").value(rf.Label());
|
||||
if (rf->Site != 0)
|
||||
writer.name("site").value(rf.Site());
|
||||
}
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a VerIterator to a JsonWriter
|
||||
*/
|
||||
@@ -208,6 +235,14 @@ static void verIterToJson(JsonWriter &writer, CacheFile &Cache, pkgCache::VerIte
|
||||
writer.name("version").value(Ver.VerStr());
|
||||
writer.name("architecture").value(Ver.Arch());
|
||||
writer.name("pin").value(Cache->GetPolicy().GetPriority(Ver));
|
||||
|
||||
writer.name("origins");
|
||||
writer.beginArray();
|
||||
for (auto vf = Ver.FileList(); !vf.end(); vf++)
|
||||
if ((vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
|
||||
verFiletoJson(writer, Cache, vf);
|
||||
writer.endArray();
|
||||
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,16 @@ install. Each package has the following attributes:
|
||||
- *version*: The version as a string
|
||||
- *architecture*: Architecture of the version
|
||||
- *pin*: The pin priority (optional)
|
||||
- *origins*: Sources from which the package is retrieved (optional, not in older versions)
|
||||
|
||||
Each origin is represented as an object with the following fields:
|
||||
|
||||
- *archive*: string (optional)
|
||||
- *codename*: string (optional)
|
||||
- *version*: string (optional)
|
||||
- *origin*: string (optional)
|
||||
- *label*: string (optional)
|
||||
- *site*: string, empty for local repositories or when using mirror+file:/ method (optional)
|
||||
|
||||
#### Example
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@ set -e
|
||||
TESTDIR="$(readlink -f "$(dirname "$0")")"
|
||||
. "$TESTDIR/framework"
|
||||
|
||||
getoriginfromsuite() { echo 'Oranges'; }
|
||||
getlabelfromsuite() { echo 'Lemons'; }
|
||||
getversionfromsuite() { echo 'Volkamer'; }
|
||||
|
||||
setupenvironment
|
||||
configarchitecture "i386"
|
||||
|
||||
@@ -107,18 +111,18 @@ Building dependency tree...
|
||||
HOOK: HELLO
|
||||
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
|
||||
HOOK: empty
|
||||
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.pre-prompt","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":1,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"1.0","architecture":"all","pin":500},"install":{"id":1,"version":"1.0","architecture":"all","pin":500}}}]}}
|
||||
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.pre-prompt","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":1,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]},"install":{"id":1,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]}}}]}}
|
||||
HOOK: empty
|
||||
HOOK: BYE
|
||||
The following NEW packages will be installed:
|
||||
foo
|
||||
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
|
||||
Inst foo (1.0 unstable [all])
|
||||
Conf foo (1.0 unstable [all])
|
||||
Inst foo (1.0 Lemons:unstable [all])
|
||||
Conf foo (1.0 Lemons:unstable [all])
|
||||
HOOK: HELLO
|
||||
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.hello","id":0,"params":{"versions":["0.1"]}}
|
||||
HOOK: empty
|
||||
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.post","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":1,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"1.0","architecture":"all","pin":500},"install":{"id":1,"version":"1.0","architecture":"all","pin":500}}}]}}
|
||||
HOOK: request {"jsonrpc":"2.0","method":"org.debian.apt.hooks.install.post","params":{"command":"install","search-terms":["foo"],"unknown-packages":[],"packages":[{"id":1,"name":"foo","architecture":"i386","mode":"install","automatic":false,"versions":{"candidate":{"id":1,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]},"install":{"id":1,"version":"1.0","architecture":"all","pin":500,"origins":[{"archive":"unstable","codename":"sid","origin":"Oranges","label":"Lemons","site":""}]}}}]}}
|
||||
HOOK: empty
|
||||
HOOK: BYE' apt install foo -s
|
||||
|
||||
@@ -203,8 +207,8 @@ Building dependency tree...
|
||||
The following NEW packages will be installed:
|
||||
foo
|
||||
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
|
||||
Inst foo (1.0 unstable [all])
|
||||
Conf foo (1.0 unstable [all])' apt install foo -s
|
||||
Inst foo (1.0 Lemons:unstable [all])
|
||||
Conf foo (1.0 Lemons:unstable [all])' apt install foo -s
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user