Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/fports @ 796:e48d173534ec
fports: Implement "fports detail" to print the status of all given packages in the most detail possible
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 31 Oct 2024 14:42:51 +0100 |
| parents | 7ca4a36e9e8d |
| children | 7f64b4420703 |
comparison
equal
deleted
inserted
replaced
| 795:77da00746485 | 796:e48d173534ec |
|---|---|
| 22 # shellcheck disable=SC2016 # no expansion | 22 # shellcheck disable=SC2016 # no expansion |
| 23 USAGE=' | 23 USAGE=' |
| 24 USAGE: fports -h | 24 USAGE: fports -h |
| 25 fports -V | 25 fports -V |
| 26 fports deptree [-l maxlevel] [-r] [-t] package... | 26 fports deptree [-l maxlevel] [-r] [-t] package... |
| 27 fports detail package... | |
| 27 | 28 |
| 28 GLOBAL OPTIONS: | 29 GLOBAL OPTIONS: |
| 29 | 30 |
| 30 -V Print the program name and version number to stdout and exit | 31 -V Print the program name and version number to stdout and exit |
| 31 | 32 |
| 303 pkgdeps="${2}" | 304 pkgdeps="${2}" |
| 304 rootpkg="${3}" | 305 rootpkg="${3}" |
| 305 | 306 |
| 306 falist_contains pkgdeps "${rootpkg}" || fatal "${EX_SOFTWARE}" "given package \`${rootpkg}' not in the given package dependency map" | 307 falist_contains pkgdeps "${rootpkg}" || fatal "${EX_SOFTWARE}" "given package \`${rootpkg}' not in the given package dependency map" |
| 307 | 308 |
| 308 # shellcheck disable=SC2034 # appears unused | |
| 309 queue='' | 309 queue='' |
| 310 farray_create queue # array with package names to be flattened | 310 farray_create queue # array with package names to be flattened |
| 311 | 311 |
| 312 farray_append queue "${rootpkg}" | 312 farray_append queue "${rootpkg}" |
| 313 | 313 |
| 329 done | 329 done |
| 330 farray_release curdeps | 330 farray_release curdeps |
| 331 fi | 331 fi |
| 332 done | 332 done |
| 333 | 333 |
| 334 farray_release queue | 334 farray_release "${queue}" |
| 335 | 335 |
| 336 setvar "${1}" "${alldeps}" | 336 setvar "${1}" "${alldeps}" |
| 337 } | |
| 338 | |
| 339 | |
| 340 #: | |
| 341 #: Implementation of the "detail" command. | |
| 342 #: | |
| 343 command_detail() { | |
| 344 # $@ | |
| 345 | |
| 346 local package \ | |
| 347 repositories packagemapping instver instrepo \ | |
| 348 repo title_printed indexfile _dummy \ | |
| 349 pkglabel pkgdescr pkgversion mapped_package | |
| 350 | |
| 351 repositories='' | |
| 352 get_active_repositories repositories | |
| 353 packagemapping='' | |
| 354 init_package_mapping packagemapping | |
| 355 indexfile="$(get_local_index_file)" | |
| 356 | |
| 357 for package in "$@"; do | |
| 358 # shellcheck disable=SC2034 # appears unused | |
| 359 title_printed=no | |
| 360 IFS='|' read -r instver instrepo <<EOF_e9bd7819-b4c5-4a86-b984-f5226db58cb1 | |
| 361 $(LC_ALL=C.UTF-8 "${PKG}" query '%v|%R' "${package}") | |
| 362 EOF_e9bd7819-b4c5-4a86-b984-f5226db58cb1 | |
| 363 print_title title_printed "${package}" "${instver}" "${instrepo}" | |
| 364 if [ -n "${indexfile}" ]; then | |
| 365 read -r _dummy pkglabel pkgdescr <<EOF_b1f225bd-d234-4a23-8a2a-40c2e5b7ff3c | |
| 366 $(LC_ALL=C.UTF-8 "${PKG}" version -U -I -n "${package}" -v "${indexfile}") | |
| 367 EOF_b1f225bd-d234-4a23-8a2a-40c2e5b7ff3c | |
| 368 pkgversion="$(parse_index_file_for_package_version "${indexfile}" "${package}")" | |
| 369 print_detail_item "INDEX" "${pkgversion}" "${pkglabel}" "${pkgdescr}" | |
| 370 fi | |
| 371 farray_for_each repositories _command_package_repository_detail "${package}" 0 | |
| 372 mapped_package="$(get_package_mapping "${packagemapping}" "${package}")" | |
| 373 if [ -z "${mapped_package}" ]; then | |
| 374 printf '%18s %s\n' "--------------->" "${mapped_package}" | |
| 375 if [ -n "${indexfile}" ]; then | |
| 376 pkgversion="$(parse_index_file_for_package_version "${indexfile}" "${mapped_package}")" | |
| 377 pkglabel="$(LC_ALL=C.UTF-8 "${PKG}" version --test-version "${instver}" "${pkgversion}")" | |
| 378 print_detail_item "INDEX" "${pkgversion}" "${pkglabel}" '' 19 | |
| 379 fi | |
| 380 farray_for_each repositories _command_mapped_package_repository_detail "${mapped_package}" "{instver}" 19 | |
| 381 fi | |
| 382 done | |
| 383 | |
| 384 falist_release "${packagemapping}" | |
| 385 farray_release "${repositories}" | |
| 386 } | |
| 387 | |
| 388 | |
| 389 #: | |
| 390 #: Array callback to print package details with regard to a repository. | |
| 391 #: | |
| 392 #: Args: | |
| 393 #: $1 (str): The repositories array | |
| 394 #: $2 (int): The current index | |
| 395 #: $3: The element value (i.e. repository name) | |
| 396 #: $4 (str): The (master) package name | |
| 397 #: $5 (int): The extra indent value to forward to called functions | |
| 398 #: | |
| 399 _command_package_repository_detail() { | |
| 400 local repositories idx reponame package extraindent | |
| 401 | |
| 402 local _dummy \ | |
| 403 pkglabel pkgdescr pkgversion | |
| 404 | |
| 405 repositories="${1}" | |
| 406 # shellcheck disable=SC2034 # appears unused (yes, accept it) | |
| 407 idx="${2}" | |
| 408 reponame="${3}" | |
| 409 package="${4}" | |
| 410 extraindent="${5:-0}" | |
| 411 | |
| 412 read -r _dummy pkglabel pkgdescr <<EOF_19cf2d80-4eb9-4cda-bd4d-96b04e769206 | |
| 413 $(LC_ALL=C.UTF-8 "${PKG}" version -U -R -r "${reponame}" -n "${package}" -v) | |
| 414 EOF_19cf2d80-4eb9-4cda-bd4d-96b04e769206 | |
| 415 pkgversion="$(LC_ALL=C.UTF-8 "${PKG}" rquery -U -r "${reponame}" '%v' "${package}")" | |
| 416 print_detail_item "${reponame}" "${pkgversion}" "${pkglabel}" "${pkgdescr}" "${extraindent}" | |
| 417 } | |
| 418 | |
| 419 | |
| 420 #: | |
| 421 #: Array callback to print package details for a mapped package with regard | |
| 422 #: to a repository. | |
| 423 #: | |
| 424 #: Args: | |
| 425 #: $1 (str): The repositories array | |
| 426 #: $2 (int): The current index | |
| 427 #: $3: The element value (i.e. repository name) | |
| 428 #: $4 (str): The mapped package name | |
| 429 #: $5 (str): The parent package version | |
| 430 #: $6 (int): The extra indent value to forward to called functions | |
| 431 #: | |
| 432 _command_mapped_package_repository_detail() { | |
| 433 local repositories idx reponame package parent_pkgversion extraindent | |
| 434 | |
| 435 local _dummy \ | |
| 436 pkglabel pkgversion | |
| 437 | |
| 438 repositories="${1}" | |
| 439 # shellcheck disable=SC2034 # appears unused (yes, accept it) | |
| 440 idx="${2}" | |
| 441 reponame="${3}" | |
| 442 package="${4}" | |
| 443 parent_pkgversion="${5}" | |
| 444 extraindent="${6:-0}" | |
| 445 | |
| 446 pkgversion="$(LC_ALL=C.UTF-8 "${PKG}" rquery -U -r "${reponame}" '%v' "${package}")" | |
| 447 pkglabel="$(LC_ALL=C.UTF-8 "${PKG}" version --test-version "${parent_pkgversion}" "${pkgversion}")" | |
| 448 print_detail_item "${reponame}" "${pkgversion}" "${pkglabel}" '' "${extraindent}" | |
| 449 } | |
| 450 | |
| 451 | |
| 452 #: | |
| 453 #: Print the output title line for a package. | |
| 454 #: | |
| 455 #: Args: | |
| 456 #: $1 (str): The name of the variable where to get or store the flag | |
| 457 #: whether the title for the package in `$2` has already been | |
| 458 #: printed. | |
| 459 #: $2 (str): The package name | |
| 460 #: $3 (str): The package version | |
| 461 #: $4 (str): The repository name from which the package has been installed | |
| 462 #: | |
| 463 #: Output (stdout): | |
| 464 #: The formatted title line | |
| 465 #: | |
| 466 print_title() { | |
| 467 local varname_title_printed package version repo | |
| 468 | |
| 469 varname_title_printed="${1}" | |
| 470 package="${2}" | |
| 471 version="${3}" | |
| 472 repo="${4}" | |
| 473 | |
| 474 if ! checkyes "${varname_title_printed}"; then | |
| 475 if [ -n "${version}" ]; then | |
| 476 # The package is installed | |
| 477 printf '%-36s %-17s (%s)\n' "${package}" "${version}" "${repo}" | |
| 478 else | |
| 479 # The package is not installed | |
| 480 printf '%-36s NOT INSTALLED\n' "${package}" | |
| 481 fi | |
| 482 setvar "${varname_title_printed}" 'yes' | |
| 483 fi | |
| 484 } | |
| 485 | |
| 486 | |
| 487 #: | |
| 488 #: Print a detail item to stdout. | |
| 489 #: | |
| 490 #: The description `_descr` will not be printed if the label `_label` | |
| 491 #: is ``?``. | |
| 492 #: | |
| 493 #: Args: | |
| 494 #: $1 (str): The repository name | |
| 495 #: $2 (str): The version number to print to | |
| 496 #: $3 (str): The label (aka comparison character) to print to | |
| 497 #: $4 (str): The description to print to | |
| 498 #: $5 (int, optional): The extra indentation to use. (Default 0) | |
| 499 #: | |
| 500 #: Output (stdout): | |
| 501 #: The formatted detail line | |
| 502 #: | |
| 503 print_detail_item() { | |
| 504 local repo version label descr indent | |
| 505 | |
| 506 local real_descr | |
| 507 | |
| 508 repo="${1}" | |
| 509 version="${2}" | |
| 510 label="${3}" | |
| 511 descr="${4}" | |
| 512 indent="${5:-0}" | |
| 513 | |
| 514 if [ "${label}" = '?' ]; then | |
| 515 real_descr='' | |
| 516 else | |
| 517 real_descr="${descr}" | |
| 518 fi | |
| 519 | |
| 520 printf '%-*s %-15s: %-17s %s %s\n' $((indent)) '' "${repo}" "${version}" "${label}" "${real_descr}" | |
| 337 } | 521 } |
| 338 | 522 |
| 339 | 523 |
| 340 # | 524 # |
| 341 # Global option handling | 525 # Global option handling |
| 371 | 555 |
| 372 case "${command}" in | 556 case "${command}" in |
| 373 '') fatal 2 "no command given";; | 557 '') fatal 2 "no command given";; |
| 374 deptree) | 558 deptree) |
| 375 command_deptree "$@";; | 559 command_deptree "$@";; |
| 560 detail) | |
| 561 command_detail "$@";; | |
| 376 *) | 562 *) |
| 377 fatal 2 "unknown command \`${command}'";; | 563 fatal 2 "unknown command \`${command}'";; |
| 378 esac | 564 esac |
