Skip to content

Commit

Permalink
Add /app/package (#534)
Browse files Browse the repository at this point in the history
* Add /app/package

* Add more archs to OBSMediaVersion.pm

* Update OBSMediaVersion.pm
  • Loading branch information
andrii-suse authored Nov 21, 2024
1 parent 04af526 commit 1ebff13
Show file tree
Hide file tree
Showing 23 changed files with 1,267 additions and 5 deletions.
1 change: 1 addition & 0 deletions assets/assetpack.def
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
< javascripts/admin_user.js
< javascripts/audit_log.js
< javascripts/server.js
< javascripts/package.js
< javascripts/project.js
< https://raw.githubusercontent.com/bootstrapthemesco/bootstrap-4-multi-dropdown-navbar/beta2.0/js/bootstrap-4-navbar.js
< https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.js
Expand Down
218 changes: 218 additions & 0 deletions assets/javascripts/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@

var pkg_param_pkg;
var pkg_param_arch;
var pkg_param_official;
var pkg_param_os;
var pkg_param_os_ver;
var pkg_param_repo;

function initPackageParams() {

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);


pkg_param_pkg = urlParams.get('pkg');
pkg_param_arch = urlParams.get('arch');
pkg_param_official = urlParams.get('official');
pkg_param_os = urlParams.get('os');
pkg_param_os_ver = urlParams.get('os_ver');
pkg_param_repo = urlParams.get('repo');

if (pkg_param_pkg) {
( document.getElementById("packag") || {} ).value = pkg_param_pkg;
}
if (pkg_param_arch) {
document.getElementById("arch").value = pkg_param_arch;
}
if (pkg_param_official) {
document.getElementById("official").checked = pkg_param_official ? 1 : 0;
}
if (pkg_param_os) {
document.getElementById("os").value = pkg_param_os;
}
if (pkg_param_os_ver) {
document.getElementById("os_ver").value = pkg_param_os_ver;
}
if (pkg_param_repo) {
document.getElementById("repo").value = pkg_param_repo;
}

}

function setupPackages() {
var table = $('#packages');


if (typeof table.data !== 'undefined') {
table.DataTable().destroy();
}

pkg_param_pkg = document.getElementById("packag").value;
pkg_param_arch = document.getElementById("arch").value;
pkg_param_official = document.getElementById("official").checked ? 1 : '';
pkg_param_os = document.getElementById("os").value;
pkg_param_os_ver = document.getElementById("os_ver").value;
pkg_param_repo = document.getElementById("repo").value;

var dataTable = table.DataTable({
ajax: {
url: '/rest/search/packages',
data: {
"package": pkg_param_pkg,
"arch": pkg_param_arch,
"official": pkg_param_official,
"os": pkg_param_os,
"os_ver": pkg_param_os_ver,
"repo": pkg_param_repo
},
},
deferRender: true,
columns: [{
data: 'name',
render: function(data, type, row) {
if (type !== 'display') {
return data ? data : '';
}
if (data) {
var get = [];
if (pkg_param_arch) {
get.push(['arch', htmlEscape(pkg_param_arch)]);
}
if (pkg_param_official) {
get.push(['official', htmlEscape(pkg_param_official)]);
}
if (pkg_param_os) {
get.push(['os', htmlEscape(pkg_param_os)]);
}
if (pkg_param_os_ver) {
get.push(['os_ver', htmlEscape(pkg_param_os_ver)]);
}
if (pkg_param_repo) {
get.push(['repo', htmlEscape(pkg_param_repo)]);
}
var getstr = '';
for (var i = 0; i < get.length; i++) {
if (getstr) {
getstr = getstr.concat('&');
}
getstr = getstr.concat(get[i][0], "=", get[i][1]);
}
data = htmlEscape(data);

if (getstr) {
getstr = '?' + getstr;
}
return '<a href="/app/package/'+ data + getstr + '">' + data + '</>';
}
return '';
}
}, // { data: 'dt' }
],
lengthMenu: [
            [100, 1000, 10, -1],
            [100, 1000, 10, 'All'],
]
});
}

function setupPackageLocations(name) {
var table = $('#package_locations');


if (typeof table.data !== 'undefined') {
table.DataTable().destroy();
}

pkg_param_arch = document.getElementById("arch").value;
pkg_param_official = document.getElementById("official").checked ? 1 : '';
pkg_param_os = document.getElementById("os").value;
pkg_param_os_ver = document.getElementById("os_ver").value;
pkg_param_repo = document.getElementById("repo").value;

var dataTable = table.DataTable({
ajax: {
url: '/rest/search/package_locations',
data: {
"package": pkg_name,
"arch": pkg_param_arch,
"official": pkg_param_official,
"os": pkg_param_os,
"os_ver": pkg_param_os_ver,
"repo": pkg_param_repo
},
},
deferRender: true,
columns: [
{
data: 'path',
render: function(data, type, row) {
if (type !== 'display') {
return data ? data : '';
}
data = data? htmlEscape(data) : '';
return data? '<a href="' + data + '/">' + data + '</>' : '';
}
}, {
data: 'file',
defaultContent: "",
type: "version-string",
render: function (data, type, row, meta) {
if(type === 'display'){
path = row['path'] + '/';
var d = data;
var t = '';
if(row['name'].slice(-1) === '/') {
d = data.slice(0,-1);
t = '/';
}
data = '<a href="' + path + encodeComponentExceptColon(d) + t + '">' + data + '</a>';
}
return data;
}
}, {
data: 'time',
className: 'mtime',
defaultContent: "",
render: function (data, type, row, meta) {
if(type === 'display' && data > 0){
path = row['path'] + '/';
data = new Date(data * 1000).toLocaleString().replace(/.\d+$/, "").replace(/:\d\d (AM|PM)$/, " $1");
if(row['name'].slice(-1) != '/') {
data = '<a href="' + path + encodeComponentExceptColon(row['file']) + '.mirrorlist">' + data + '</a>';
} else {
data = '<a href="' + path + encodeComponentExceptColon(row['file'].slice(0,-1)) + '/">' + data + '</a>';
}
}
return data;
}
}, {
data: 'size',
className: 'size',
defaultContent: "",
render: function (data, type, row, meta) {
if(type === 'display') {
path = row['path'] + '/';
if (data === null) {
data = '...';
} else if (Math.abs(data) > 1024) {
const units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let u = -1;

do {
data /= 1024;
++u;
} while (Math.round(Math.abs(data) * 10) >= 1024 && u < units.length - 1);
data = data.toFixed(1) + ' ' + units[u];
}
data = '<a href="' + path + encodeComponentExceptColon(row['file']) + '.mirrorlist">' + data + '</a>';
}
return data;
}
}],
lengthMenu: [
            [100, 1000, 10, -1],
            [100, 1000, 10, 'All'],
        ],
});
}
27 changes: 27 additions & 0 deletions lib/Directory/Scanner/OBSMediaVersion.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,31 @@ sub parse_version($filename) {
return $1
}


# return name, version, build, arch, ext
sub parse_pkg($filename) {
return undef unless $filename;
my $fil = Mojo::File->new($filename);
my $f = $fil->basename;
my $ext = $fil->extname;
if ($ext eq "rpm") {
my @res = parse_pkg_rpm( $fil->basename($ext) );
return ( @res, "rpm" );
} elsif ($ext eq "deb") {
my @res = parse_pkg_deb( $fil->basename($ext) );
return ( @res, "deb" );
}
return undef;
}

# return name, version, build, arch
sub parse_pkg_rpm($basename) {
return undef unless ($basename =~ m/(.*)-([^-]+)-([^-]+)\.(x86_64|noarch|i[3-6]86|ppc64|aarch64|arm64|amd64|s390|src)/);
return ($1, $2, $3, $4);
}

sub parse_pkg_deb($basename) {
return undef;
}

1;
32 changes: 32 additions & 0 deletions lib/MirrorCache/Schema/Result/Metapkg.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use utf8;
package MirrorCache::Schema::Result::Metapkg;

use base 'DBIx::Class::Core';

use DBIx::Class::Timestamps;

__PACKAGE__->table("metapkg");


__PACKAGE__->add_columns(
"id",
{
data_type => "bigint",
is_auto_increment => 1,
is_nullable => 0,
sequence => "pkg_id_seq",
},
"name",
{ data_type => "varchar", is_nullable => 0, size => 512 },
"t_created",
{
data_type => 'timestamp',
dynamic_default_on_create => 'DBIx::Class::Timestamps::now',
is_nullable => 0
}
);


__PACKAGE__->set_primary_key("id");

1;
33 changes: 33 additions & 0 deletions lib/MirrorCache/Schema/Result/Pkg.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use utf8;
package MirrorCache::Schema::Result::Pkg;

use base 'DBIx::Class::Core';

use DBIx::Class::Timestamps;

__PACKAGE__->table("pkg");

__PACKAGE__->add_columns(
"id",
{
data_type => "bigint",
is_auto_increment => 1,
is_nullable => 0,
sequence => "pkg_id_seq",
},
"folder_id",
{ data_type => "bigint", is_foreign_key => 1, is_nullable => 0 },
"metapkg_id",
{ data_type => "bigint", is_nullable => 0 },
"t_created",
{
data_type => 'timestamp',
dynamic_default_on_create => 'DBIx::Class::Timestamps::now',
is_nullable => 0
}
);


__PACKAGE__->set_primary_key("id");

1;
19 changes: 19 additions & 0 deletions lib/MirrorCache/Schema/ResultSet/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ END_SQL
return $dbh->selectall_hashref($sql, 'id', {}, $folder_id, $dt);
}

sub find_pkgs {
my ($self, $folder_id) = @_;

my $rsource = $self->result_source;
my $schema = $rsource->schema;
my $dbh = $schema->storage->dbh;

my $sql = <<'END_SQL';
select file.id, file.name as basename, metapkg.name as pkg_name, pkg.id as pkg_id, metapkg_id, pkg.arch_id
from file
left join pkg on file.folder_id = pkg.folder_id
left join metapkg on metapkg.id = metapkg_id and file.name like concat (metapkg.name, '-%')
where file.folder_id = ?
and (file.name like '%.rpm' or file.name like '%.deb')
END_SQL

return $dbh->selectall_hashref($sql, 'id', {}, $folder_id);
}

# returns pair (bool, max_dt)
sub need_hashes {
my ($self, $folder_id) = @_;
Expand Down
Loading

0 comments on commit 1ebff13

Please sign in to comment.