From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pmg-api 1/1] apt: use `apt changelog` for changelog fetching
Date: Tue, 4 Jul 2023 11:45:04 +0200 [thread overview]
Message-ID: <20230704094507.92567-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20230704094507.92567-1-f.gruenbichler@proxmox.com>
support for it got added to Proxmox repositories, so there is no need to use
custom logic and manual fetching for this anymore.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
requires versioned depends on proxmox-widget-toolkit.
src/PMG/API2/APT.pm | 108 +++++++-------------------------------------
1 file changed, 16 insertions(+), 92 deletions(-)
diff --git a/src/PMG/API2/APT.pm b/src/PMG/API2/APT.pm
index 7fc7c29..1cd5f3d 100644
--- a/src/PMG/API2/APT.pm
+++ b/src/PMG/API2/APT.pm
@@ -85,32 +85,6 @@ my $get_pkgfile = sub {
return undef;
};
-my $get_changelog_url =sub {
- my ($pkgname, $info, $pkgver, $origin, $component) = @_;
-
- my $changelog_url;
- my $base = dirname($info->{FileName});
- if ($origin && $base) {
- $pkgver =~ s/^\d+://; # strip epoch
- my $srcpkg = $info->{SourcePkg} || $pkgname;
- if ($origin eq 'Debian') {
- $base =~ s!pool/updates/!pool/!; # for security channel
- $changelog_url = "http://packages.debian.org/changelogs/$base/" .
- "${srcpkg}_${pkgver}/changelog";
- } elsif ($origin eq 'Proxmox') {
- if ($component eq 'pmg-enterprise') {
- $changelog_url = "https://enterprise.proxmox.com/debian/pmg/$base/" .
- "${pkgname}_${pkgver}.changelog";
- } else {
- $changelog_url = "http://download.proxmox.com/debian/pmg/$base/" .
- "${pkgname}_${pkgver}.changelog";
- }
- }
- }
-
- return $changelog_url;
-};
-
my $assemble_pkginfo = sub {
my ($pkgname, $info, $current_ver, $candidate_ver) = @_;
@@ -122,10 +96,6 @@ my $assemble_pkginfo = sub {
if (my $pkgfile = &$get_pkgfile($candidate_ver)) {
$data->{Origin} = $pkgfile->{Origin};
- if (my $changelog_url = &$get_changelog_url($pkgname, $info, $candidate_ver->{VerStr},
- $pkgfile->{Origin}, $pkgfile->{Component})) {
- $data->{ChangeLogUrl} = $changelog_url;
- }
}
if (my $desc = $info->{LongDesc}) {
@@ -402,74 +372,28 @@ __PACKAGE__->register_method({
my $pkgname = $param->{name};
- my $cache = &$get_apt_cache();
- my $policy = $cache->policy;
- my $p = $cache->{$pkgname} || die "no such package '$pkgname'\n";
- my $pkgrecords = $cache->packages();
-
- my $ver;
- if ($param->{version}) {
- if (my $available = $p->{VersionList}) {
- for my $v (@$available) {
- if ($v->{VerStr} eq $param->{version}) {
- $ver = $v;
- last;
- }
- }
- }
- die "package '$pkgname' version '$param->{version}' is not available\n" if !$ver;
+ my $cmd = ['apt-get', 'changelog', '-qq'];
+ if (my $version = $param->{version}) {
+ push @$cmd, "$pkgname=$version";
} else {
- $ver = $policy->candidate($p) || die "no installation candidate for package '$pkgname'\n";
+ push @$cmd, "$pkgname";
}
- my $info = $pkgrecords->lookup($pkgname);
+ my $output = "";
- my $pkgfile = &$get_pkgfile($ver);
- my $url;
-
- die "changelog for '${pkgname}_$ver->{VerStr}' not available\n"
- if !($pkgfile && ($url = &$get_changelog_url($pkgname, $info, $ver->{VerStr}, $pkgfile->{Origin}, $pkgfile->{Component})));
-
- my $data = "";
-
- my $pmg_cfg = PMG::Config->new();
- my $proxy = $pmg_cfg->get('admin', 'http_proxy');
-
- my $ua = LWP::UserAgent->new;
- $ua->agent("PMG/1.0");
- $ua->timeout(10);
- $ua->max_size(1024*1024);
- $ua->ssl_opts(verify_hostname => 0); # don't care for changelogs
-
- if ($proxy) {
- $ua->proxy(['http', 'https'], $proxy);
- } else {
- $ua->env_proxy;
- }
-
- my $username;
- my $pw;
-
- if ($pkgfile->{Origin} eq 'Proxmox' && $pkgfile->{Component} eq 'pmg-enterprise') {
- my $info = PMG::API2::Subscription::read_etc_subscription();
- if ($info->{status} eq 'active') {
- $username = $info->{key};
- $pw = PMG::Utils::get_hwaddress();
- $ua->credentials("enterprise.proxmox.com:443", 'pmg-enterprise-repository',
- $username, $pw);
- }
- }
-
- syslog('info', "GET $url\n");
- my $response = $ua->get($url);
+ my $rc = PVE::Tools::run_command(
+ $cmd,
+ timeout => 10,
+ logfunc => sub {
+ my $line = shift;
+ $output .= "$line\n";
+ },
+ noerr => 1,
+ );
- if ($response->is_success) {
- $data = $response->decoded_content;
- } else {
- PVE::Exception::raise($response->message, code => $response->code);
- }
+ $output .= "RC: $rc" if $rc != 0;
- return $data;
+ return $output;
}});
__PACKAGE__->register_method({
--
2.39.2
next prev parent reply other threads:[~2023-07-04 9:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 9:45 [pve-devel] [PATCH pve-manager/pmg-api/proxmox-backup/pwt 0/4] APT changelog switch-over Fabian Grünbichler
2023-07-04 9:45 ` Fabian Grünbichler [this message]
2023-07-04 9:45 ` [pve-devel] [PATCH proxmox-backup 1/1] apt: use `apt changelog` for changelog fetching Fabian Grünbichler
2023-07-04 9:45 ` [pve-devel] [PATCH proxmox-widget-toolkit 1/1] apt: drop ChangeLogUrl Fabian Grünbichler
2023-11-13 17:18 ` [pve-devel] applied: " Thomas Lamprecht
2023-11-14 7:04 ` Fabian Grünbichler
2023-07-04 9:45 ` [pve-devel] [PATCH manager 1/1] apt: use `apt changelog` for changelog fetching Fabian Grünbichler
2023-11-14 8:30 ` [pve-devel] applied-series: [PATCH pve-manager/pmg-api/proxmox-backup/pwt 0/4] APT changelog switch-over Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230704094507.92567-2-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.