Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2320ba5

Browse files
committed
Further simplify sysreqs
Also fix the stuff I just broke.
1 parenta63f0da commit2320ba5

File tree

4 files changed

+534
-23
lines changed

4 files changed

+534
-23
lines changed

‎R/sysreqs2.R‎

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,77 @@ sysreqs2_cmds <- utils::read.table(
1515
name os id distribution version version_match update_command install_command query_command
1616
'Ubuntu Linux' linux ubuntu ubuntu * NA 'apt-get -y update' 'apt-get -y install' dpkg-query
1717
'Debian Linux' linux debian debian * NA 'apt-get -y update' 'apt-get -y install' dpkg-query
18-
'CentOS Linux' linux centos centos *NA NA 'yum install -y' rpm
19-
'Rocky Linux' linux rocky rockylinux *NA NA 'dnf install -y' rpm
20-
'Rocky Linux' linux rockylinux rockylinux *NA NA 'dnf install -y' rpm
21-
'AlmaLinux' linux almalinuxalmalinux*NA NA 'dnf install -y' rpm
18+
'CentOS Linux' linux centos centos *major NA 'yum install -y' rpm
19+
'Rocky Linux' linux rocky rockylinux *major NA 'dnf install -y' rpm
20+
'Rocky Linux' linux rockylinux rockylinux *major NA 'dnf install -y' rpm
21+
'AlmaLinux' linux almalinuxrockylinux *major NA 'dnf install -y' rpm
2222
'Red Hat Enterprise Linux' linux rhel redhat 6 major NA 'yum install -y' rpm
2323
'Red Hat Enterprise Linux' linux rhel redhat 7 major NA 'yum install -y' rpm
24-
'Red Hat Enterprise Linux' linux rhel redhat *NA NA 'dnf install -y' rpm
24+
'Red Hat Enterprise Linux' linux rhel redhat *major NA 'dnf install -y' rpm
2525
'Red Hat Enterprise Linux' linux redhat redhat 6 major NA 'yum install -y' rpm
2626
'Red Hat Enterprise Linux' linux redhat redhat 7 major NA 'yum install -y' rpm
27-
'Red Hat Enterprise Linux' linux redhat redhat *NA NA 'dnf install -y' rpm
27+
'Red Hat Enterprise Linux' linux redhat redhat *major NA 'dnf install -y' rpm
2828
'Fedora Linux' linux fedora fedora * NA NA 'dnf install -y' rpm
2929
'openSUSE Linux' linux opensuse opensuse * NA NA 'zypper --non-interactive install' rpm
3030
'openSUSE Linux' linux opensuse-leap opensuse * NA NA 'zypper --non-interactive install' rpm
3131
'openSUSE Linux' linux opensuse-tumbleweed opensuse * NA NA 'zypper --non-interactive install' rpm
3232
'SUSE Linux Enterprise' linux sles sle * NA NA 'zypper --non-interactive install' rpm
3333
'SUSE Linux Enterprise' linux sle sle * NA NA 'zypper --non-interactive install' rpm
34-
'Alpine Linux' linux alpine alpine *NA NA 'apk add --no-cache' apk
34+
'Alpine Linux' linux alpine alpine *minor NA 'apk add --no-cache' apk
3535
"
3636
)
3737
)
3838

39-
find_sysreqs_platform<-function(sysreqs_platform=NULL) {
40-
sysreqs_platform<-sysreqs_platform %||%
41-
current_config()$get("sysreqs_platform")
42-
plt<- parse_sysreqs_platform(sysreqs_platform)
43-
plt$version_major<- sub("[.].*$","",plt$version)
39+
# do not use package_version, in case the distro is nor semver
40+
get_major_version<-function(x) {
41+
sub("[.].*$","",x)
42+
}
43+
get_minor_version<-function(x) {
44+
sub("([.][^.]+)[.].*$","\\1",x)
45+
}
46+
47+
find_sysreqs_platform<-function(sysreqs_platform=NULL,parsed=NULL) {
48+
plt<-parsed %||%
49+
parse_sysreqs_platform(
50+
sysreqs_platform %||% current_config()$get("sysreqs_platform")
51+
)
52+
plt$version_major<- get_major_version(plt$version)
53+
plt$version_minor<- get_minor_version(plt$version)
4454
which(
4555
sysreqs2_cmds$os==plt$os&
4656
sysreqs2_cmds$id==plt$distribution&
4757
(sysreqs2_cmds$version%in%
4858
c("*",plt$version)|
49-
sysreqs2_cmds$version_match=="major"&
50-
sysreqs2_cmds$version==plt$version_major)
59+
(sysreqs2_cmds$version_match=="major"&
60+
sysreqs2_cmds$version==plt$version_major)|
61+
(sysreqs2_cmds$version_match=="minor"&
62+
sysreqs2_cmds$version==plt$version_minor))
5163
)[1]
5264
}
5365

66+
canonize_sysreqs_platform<-function(sysreqs_platform) {
67+
parsed<- parse_sysreqs_platform(sysreqs_platform)
68+
known<- find_sysreqs_platform(parsed=parsed)
69+
if (is.na(known)) {
70+
sysreqs_platform
71+
}else {
72+
plt<- sysreqs_platforms()[known, ]
73+
paste0(
74+
plt$distribution,
75+
"-",
76+
if (plt$version!="*") {
77+
plt$version
78+
}elseif (identical(plt$version_match,"major")) {
79+
get_major_version(parsed$version)
80+
}elseif (identical(plt$version_match,"minor")) {
81+
get_minor_version(parsed$version)
82+
}else {
83+
parsed$version
84+
}
85+
)
86+
}
87+
}
88+
5489
sysreqs2_command<-function(
5590
sysreqs_platform=NULL,
5691
cmd= c("install_command","update_command","query_command")
@@ -99,6 +134,7 @@ sysreqs2_async_resolve <- function(sysreqs, sysreqs_platform, config, ...) {
99134
}
100135

101136
sysreqs2_scripts<-function(recs,sysreqs_platform,missing=FALSE) {
137+
sysreqs_platform<- canonize_sysreqs_platform(sysreqs_platform)
102138
plt<- parse_sysreqs_platform(sysreqs_platform)
103139
flatrecs<- unlist(recs,recursive=FALSE)
104140
upd<- sysreqs2_command(sysreqs_platform,"update")
@@ -239,9 +275,9 @@ sysreqs2_match <- function(
239275
todo<-!is.na(sysreqs)&sysreqs!=""
240276

241277
config<-config %||% current_config()
242-
plt<- parse_sysreqs_platform(
278+
plt<- parse_sysreqs_platform(canonize_sysreqs_platform(
243279
sysreqs_platform %||%config$get("sysreqs_platform")
244-
)
280+
))
245281

246282
rsysreqs<-sysreqs[todo]
247283
for (rinrules) {

‎tests/testthat/_snaps/sysreqs.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
99
1 Ubuntu Linux linux ubuntu ubuntu * <NA> apt-get -y update apt-get -y install dpkg-query
1010
2 Debian Linux linux debian debian * <NA> apt-get -y update apt-get -y install dpkg-query
11-
3 CentOS Linux linux centos centos *<NA> <NA> yum install -y rpm
12-
4 Rocky Linux linux rocky rockylinux *<NA> <NA> dnf install -y rpm
13-
5 Rocky Linux linux rockylinux rockylinux *<NA> <NA> dnf install -y rpm
14-
6 AlmaLinux linux almalinuxalmalinux*<NA> <NA> dnf install -y rpm
11+
3 CentOS Linux linux centos centos *major <NA> yum install -y rpm
12+
4 Rocky Linux linux rocky rockylinux *major <NA> dnf install -y rpm
13+
5 Rocky Linux linux rockylinux rockylinux *major <NA> dnf install -y rpm
14+
6 AlmaLinux linux almalinuxrockylinux *major <NA> dnf install -y rpm
1515
7 Red Hat Enterprise Linux linux rhel redhat 6 major <NA> yum install -y rpm
1616
8 Red Hat Enterprise Linux linux rhel redhat 7 major <NA> yum install -y rpm
17-
9 Red Hat Enterprise Linux linux rhel redhat *<NA> <NA> dnf install -y rpm
17+
9 Red Hat Enterprise Linux linux rhel redhat *major <NA> dnf install -y rpm
1818
10 Red Hat Enterprise Linux linux redhat redhat 6 major <NA> yum install -y rpm
1919
11 Red Hat Enterprise Linux linux redhat redhat 7 major <NA> yum install -y rpm
20-
12 Red Hat Enterprise Linux linux redhat redhat *<NA> <NA> dnf install -y rpm
20+
12 Red Hat Enterprise Linux linux redhat redhat *major <NA> dnf install -y rpm
2121
13 Fedora Linux linux fedora fedora * <NA> <NA> dnf install -y rpm
2222
14 openSUSE Linux linux opensuse opensuse * <NA> <NA> zypper --non-interactive install rpm
2323
15 openSUSE Linux linux opensuse-leap opensuse * <NA> <NA> zypper --non-interactive install rpm
2424
16 openSUSE Linux linux opensuse-tumbleweed opensuse * <NA> <NA> zypper --non-interactive install rpm
2525
17 SUSE Linux Enterprise linux sles sle * <NA> <NA> zypper --non-interactive install rpm
2626
18 SUSE Linux Enterprise linux sle sle * <NA> <NA> zypper --non-interactive install rpm
27-
19 Alpine Linux linux alpine alpine *<NA> <NA> apk add --no-cache apk
27+
19 Alpine Linux linux alpine alpine *minor <NA> apk add --no-cache apk
2828

2929
#sysreqs_db_list
3030

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp