tazbug diff web/plugins/textmode/textmode.cgi @ rev 126

Add textmode plugin, rewrite tazbug cmdline tool
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 21 03:44:35 2017 +0100 (2017-02-21)
parents
children 7bf28563c0f6
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/web/plugins/textmode/textmode.cgi	Tue Feb 21 03:44:35 2017 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# TazBug Plugin - Textmode will output plain data to be used by remote client
     1.7 +#
     1.8 +
     1.9 +if [ "$(GET textmode)" ]; then
    1.10 +	header "Content-type: text/plain; charset=UTF-8"
    1.11 +	
    1.12 +	separator() {
    1.13 +		echo "-------------------------------------------------------------------------------"
    1.14 +	}
    1.15 +	
    1.16 +	case " $(GET) " in
    1.17 +		
    1.18 +	*\ stats\ *)
    1.19 +		echo "Bugs count     : $(ls $bugdir | wc -l)" 
    1.20 +		echo "Database size  : $(du -sh $bugdir | awk '{print $1}')" ;;
    1.21 +	
    1.22 +	*\ search\ *)
    1.23 +		for bug in $(ls $bugdir)
    1.24 +		do
    1.25 +			result=$(fgrep -i -h "$(GET search)" $bugdir/$bug/*)
    1.26 +			if [ "$result" ]; then
    1.27 +				found=$(($found + 1))
    1.28 +				. ${bugdir}/${bug}/bug.conf
    1.29 +				echo "Bug: $bug - $BUG"
    1.30 +			fi
    1.31 +		done
    1.32 +		if [ "$found" == "" ]; then
    1.33 +			echo "No result found for: $(GET search)"
    1.34 +		else
    1.35 +			separator && echo "$found result(s) found"
    1.36 +		fi ;;
    1.37 +	
    1.38 +	*\ id\ *)
    1.39 +		# Show bug information and description
    1.40 +		id=$(GET id)
    1.41 +		if [ -f "$bugdir/$id/bug.conf" ]; then
    1.42 +			. ${bugdir}/${id}/bug.conf
    1.43 +			cat << EOT
    1.44 +Bug      : $id - $STATUS - $PRIORITY
    1.45 +Title    : $BUG
    1.46 +Info     : $DATE - Creator: $CREATOR
    1.47 +$(separator)
    1.48 +$(cat $bugdir/$id/desc.txt)
    1.49 +EOT
    1.50 +		else
    1.51 +			echo "Can't found bug ID: $id" && exit 0
    1.52 +		fi ;;
    1.53 +	
    1.54 +	*)
    1.55 +		cat << EOT
    1.56 +Tazbug Textmode plugin
    1.57 +$(separator)
    1.58 +$(date)
    1.59 +
    1.60 +Functions: 
    1.61 +  &stats      Display bug tracker stats
    1.62 +  &search=    Search for bugs by pattern
    1.63 +  &id=        Show bug info and description
    1.64 +EOT
    1.65 +		;;
    1.66 +	esac
    1.67 +	exit 0
    1.68 +fi