alterator-alternatives-3.0/000075500000000000000000000000001127726400600160535ustar00rootroot00000000000000alterator-alternatives-3.0/Makefile000064400000000000000000000002601127726400600175110ustar00rootroot00000000000000NAME=alternatives INSTALL=/usr/bin/install TEST_REQUIRES=alternatives all: clean: install: install-module check: check-module include /usr/share/alterator/build/module.mak alterator-alternatives-3.0/applications/000075500000000000000000000000001127726400600205415ustar00rootroot00000000000000alterator-alternatives-3.0/applications/alternatives.desktop000064400000000000000000000004411127726400600246340ustar00rootroot00000000000000[Desktop Entry] Encoding=UTF-8 Type=Application Categories=X-Alterator-System Icon=alternatives Terminal=false Name=Alternatives subsystem X-Alterator-URI=/alternatives X-Alterator-Weight=10 X-Alterator-Help=alternatives Name[ru]=Альтернативы Name[uk]=Альтернативи alterator-alternatives-3.0/backend3/000075500000000000000000000000001127726400600175255ustar00rootroot00000000000000alterator-alternatives-3.0/backend3/alternatives000075500000000000000000000020651127726400600221570ustar00rootroot00000000000000#!/bin/sh alterator_api_version=1 . alterator-sh-functions . /usr/share/alternatives/functions list_alternative() { alternatives-list| sed -ne 's,^\(.*\) points to.*,\1,p'| sort| write_enum } list_candidate() { [ -n "$in_name" ] || return grep -h "^$in_name[[:space:]]" "$package_dir"/* | sed 's,[[:space:]]\+,\t,g' | cut -f2| write_enum } read_alternative() { [ -n "$in_name" ] || return write_string_param name "$in_name" local alternative="/$in__objects" ! grep -qs "^$in_name[[:space:]].*manual$" "$manual_file" write_bool_param manual "$?" write_string_param current "$(alternatives-list "$in_name" | sed -ne 's,^.* points to \(.*\)$,\1,p')" } write_alternative() { if test_bool "$in_manual"; then alternatives-manual "$in_name" "$in_current" else alternatives-auto "$in_name" fi >/dev/null 2>/dev/null alternatives-update } alterator_export_proc read_alternative alterator_export_proc write_alternative alterator_export_proc list_candidate alterator_export_proc list_alternative message_loop alterator-alternatives-3.0/runtests000075500000000000000000000005251127726400600176720ustar00rootroot00000000000000#!/bin/sh -u . shell-unittest . alterator-unittest-functions datadir=test-data unitdir=test ### initialize special testing facility install -Dpm644 $datadir/qa /etc/alternatives/packages.d/qa for i in qa1-1 qa1-2 qa2-1 qa2-2; do touch /usr/bin/$i chmod +x /usr/bin/$i done ### runtests for i in "$unitdir"/*; do . $i;done runUnitTests alterator-alternatives-3.0/test-data/000075500000000000000000000000001127726400600177415ustar00rootroot00000000000000alterator-alternatives-3.0/test-data/qa000064400000000000000000000001701127726400600202630ustar00rootroot00000000000000/usr/bin/qa1 /usr/bin/qa1-1 1 /usr/bin/qa1 /usr/bin/qa1-2 2 /usr/bin/qa2 /usr/bin/qa2-1 1 /usr/bin/qa2 /usr/bin/qa2-2 2 alterator-alternatives-3.0/test/000075500000000000000000000000001127726400600170325ustar00rootroot00000000000000alterator-alternatives-3.0/test/alternatives000064400000000000000000000034121127726400600214560ustar00rootroot00000000000000#!/bin/sh appendTests \ test_alternatives_read \ test_alternatives_write \ test_alternatives_list test_alternatives_read() { alternatives-manual /usr/bin/qa1 /usr/bin/qa1-1 >/dev/null 2>/dev/null assertRead "manual state" current /usr/bin/qa1-1 /alternatives name /usr/bin/qa1 assertRead "manual mode" manual '#t' /alternatives name /usr/bin/qa1 alternatives-auto /usr/bin/qa1 >/dev/null 2>/dev/null assertRead "default state" current /usr/bin/qa1-2 /alternatives name /usr/bin/qa1 assertRead "default mode" manual '#f' /alternatives name /usr/bin/qa1 } test_alternatives_write() { local rc= alterator-cmdline -l /alternatives action write name /usr/bin/qa2 manual '#t' current /usr/bin/qa2-1 grep -qs '^/usr/bin/qa2[[:space:]].*manual$' /etc/alternatives/manual && rc=0 || rc=1 assertEquals "turn on manual mode" "$rc" "0" alterator-cmdline -l /alternatives action write name /usr/bin/qa2 manual '#f' grep -qs '^/usr/bin/qa2[[:space:]].*manual$' /etc/alternatives/manual && rc=0 || rc=1 assertEquals "turn off manual mode" "$rc" "1" } alternatives_list() { alterator-cmdline -l "$@" action list -k name| LANG=C sort } test_alternatives_list() { local backend_list= expected_list= backend_list="$(alternatives_list /alternatives | grep /usr/bin/qa)" expected_list='/usr/bin/qa1 /usr/bin/qa2' assertEquals 'alternatives list' "$backend_list" "$expected_list" backend_list="$(alternatives_list /alternatives/avail_candidate name /usr/bin/qa1)" expected_list='/usr/bin/qa1-1 /usr/bin/qa1-2' assertEquals 'candidates list' "$backend_list" "$expected_list" assertEnumref "avail alternatives" /alternatives assertEnumref "avail candidates" /alternatives/avail_candidate name /usr/bin/qa1 } alterator-alternatives-3.0/ui/000075500000000000000000000000001127726400600164705ustar00rootroot00000000000000alterator-alternatives-3.0/ui/alternatives/000075500000000000000000000000001127726400600211715ustar00rootroot00000000000000alterator-alternatives-3.0/ui/alternatives/ajax.scm000064400000000000000000000025121127726400600226200ustar00rootroot00000000000000(define-module (ui alternatives ajax) :use-module (alterator ajax) :use-module (alterator algo) :use-module (alterator woo) :export (on-load)) ;;; Functions (define (ui-list) (catch/message (lambda() (let ((data (woo-call "/alternatives/list_alternative"))) (form-update-enum "name" data) (if (pair? data) (let ((name (woo-get-option (car data) 'name))) (form-update-value "name" name) (ui-read name))))))) (define (ui-manual . manual) (let ((manual (if (pair? manual) (car manual) (form-value "manual")))) (form-update-activity "current" manual))) (define (ui-read . name) (let ((name (if (pair? name) (car name) (form-value "name")))) (catch/message (lambda() (let ((data (cond-car (woo-call "/alternatives/read_alternative" 'name name)))) (form-update-enum "current" (woo-call "/alternatives/list_candidate" 'name name)) (form-update-value-list '("current" "manual") data) (ui-manual (woo-get-option data 'manual))))))) (define (ui-write) (catch/message (lambda() (apply woo-call "/alternatives/write_alternative" (form-value-list '("name" "current" "manual"))) (ui-read (form-value "name"))))) (define (on-load) (ui-list) (form-bind "name" "change" ui-read) (form-bind "manual" "change" ui-manual) (form-bind "apply" "click" ui-write)) alterator-alternatives-3.0/ui/alternatives/index.html000064400000000000000000000017541127726400600231750ustar00rootroot00000000000000
Alternatives:

Choose candidate manually

In most cases candidates selection works well automatically using weight written in their config file, but you can choose variant manually

alterator-alternatives-3.0/ui/alternatives/index.scm000064400000000000000000000010651127726400600230060ustar00rootroot00000000000000(document:surround "/std/frame") (gridbox columns "100" margin "30" (label text (_ "Alternatives:")) (listbox name "name") (label) (separator) (label text (_ "Candidates:") nameref "current") (listbox name "current") (checkbox text (_ "Choose candidate manually") name "manual") (label text (small (_ "In most cases candidates selection works well automatically using weight written in their config file, but you can choose variant manually")) text-wrap #t) (label) (spacer) (button text (_ "Apply") align "left" name "apply"))