File download_assets of Package obs-git
#!/usr/bin/perl
################################################################
#
# Copyright (c) 2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
BEGIN {
if (!$::ENV{'BUILD_DIR'} && $0 ne '-' && $0 ne '-e' && -e $0 && ! -e '/etc/build.conf') {
use Cwd ();
my $p = Cwd::abs_path($0);
$::ENV{'BUILD_DIR'} = $p if $p =~ s/\/[^\/]+$// && $p ne '/usr/lib/build' && -d "$p/PBuild";
}
unshift @INC, ($::ENV{'BUILD_DIR'} && ! -e '/etc/build.conf' ? $::ENV{'BUILD_DIR'} : '/usr/lib/build');
}
use strict;
use Data::Dumper;
use POSIX;
use Cwd ();
use Build;
use PBuild::Source;
use PBuild::Recipe;
use PBuild::AssetMgr;
use PBuild::RepoMgr;
use PBuild::LocalRepo;
use PBuild::RemoteAssets;
use PBuild::Multibuild;
use PBuild::Link;
use PBuild::Checker;
use PBuild::Options;
use PBuild::Result;
use PBuild::Download;
use PBuild::Preset;
use PBuild::Repoquery;
my $arch = 'x86_64';
my $global_asset_dir;
for my $dir (@ARGV) {
my ($files, $asset_files) = PBuild::Source::list_package($dir);
my @assets;
my $assetdir = $global_asset_dir || "$dir/.assets";
my $p = {
'pkg' => "_me",
'dir' => $dir,
'files' => $files,
'srcmd5' => PBuild::Source::calc_srcmd5($files),
};
$p->{'asset_files'} = $asset_files if %{$asset_files || {}};
# spec takes also care of kiwi type
# no support for fedpkg yet
for my $type ('spec', 'arch') {
PBuild::Recipe::parse(undef, $p, $type, 'x86_64', undef, undef);
push @assets, PBuild::RemoteAssets::fedpkg_parse($p) if $type eq 'fedpkg';
push @assets, PBuild::RemoteAssets::archlinux_parse($p, $arch) if $type eq 'arch';
push @assets, PBuild::RemoteAssets::recipe_parse($p, 'x86_64') if $type eq 'spec';
}
for my $asset (@assets) {
$asset->{'assetid'} = PBuild::AssetMgr::get_assetid($asset->{'file'}, $asset);
$p->{'asset_files'}->{$asset->{'file'}} = $asset;
print Dumper($asset);
}
# download missing assets
if (grep {($_->{'type'} || '') eq 'ipfs'} @assets) {
my $assetid = $_->{'assetid'};
next if -e "$assetdir/".substr($assetid, 0, 2)."/$assetid";
PBuild::RemoteAssets::ipfs_fetch($p, $assetdir, \@assets);
}
if (grep {($_->{'type'} || '') eq 'url'} @assets) {
my $assetid = $_->{'assetid'};
next if -e "$assetdir/".substr($assetid, 0, 2)."/$assetid";
PBuild::RemoteAssets::url_fetch($p, $assetdir, \@assets);
}
my $asset_files = $p->{'asset_files'};
for my $file (sort keys %{$asset_files || {}}) {
my $asset = $asset_files->{$file};
my $assetid = $asset->{'assetid'};
my $adir = "$assetdir/".substr($assetid, 0, 2);
PBuild::Util::cp("$adir/$assetid", $asset->{'isdir'} ? "$dir/$file.obscpio" : "$dir/$file");
}
}