[debian-edu-commits] debian-edu/ 26/183: D'oh, don't forget to cvs add new files

Alexander Alemayhu ccscanf-guest at moszumanska.debian.org
Wed Jun 11 16:48:30 UTC 2014


This is an automated email from the git hooks/post-receive script.

ccscanf-guest pushed a commit to branch master
in repository desktop-profiles.

commit 435a4cf37e483b94a2163ac66803ed3206597333
Author: Bart Cornelis <cobaco at linux.be>
Date:   Thu Nov 4 20:39:29 2004 +0000

    D'oh, don't forget to cvs add new files
---
 list-desktop-profiles | 143 +++++++++++++++++++++++++++++++
 listingmodule         | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 372 insertions(+)

diff --git a/list-desktop-profiles b/list-desktop-profiles
new file mode 100644
index 0000000..5b72953
--- /dev/null
+++ b/list-desktop-profiles
@@ -0,0 +1,143 @@
+#! /bin/sh
+#
+# This script implements a tool to filter the profiles listed in .listing files
+# used by the desktop-profiles package. Output format kan be specified using a
+# format string.
+#
+# See desktop-profiles (7) for more information about using profiles through
+# desktop-profiles and the format of the .listing files
+#
+# (c) 2004 Bart Cornelis <cobaco AT skolelinux no>
+###############################################################################
+
+print_help () {
+cat <<EOF
+Usage: manage-desktop-profiles [OPTIONS]
+ Debconf interface for managing the contents of the .listing files used by the
+ desktop-profiles package.
+
+Options controlling the used .listing files:
+  -d | --directory: directory where to look for .listing files
+                    (default=/etc/desktop-profiles)
+  -f | --file     : profiles in the .listing file that is the next argument 
+                    will also be taken into account (may appear more then once)
+  
+Options for filtering the shown profiles:
+  -c, --comment | --description: 
+     profile description matches the regexp that is the next argument
+  -k, --kind:
+     profile kind matches the regexp that is the next argument 
+     (profile kind is one of [KDE, GCONF, XDG_DATA, XDG_CONFIG, ROX, UDE])
+  -l, --location:
+     profile location matches the regexp that is the next argument
+  -n, --name:
+     profile name matches the regexp that is the next argument
+  -p, --precedence:
+     next argument gives the comparison to be done with the profiles precedence
+     value. Use 'gt' for 'greater then', 'lt' for 'less then', 'ge' for
+     'greater then or equal to', 'le' for 'less then or equal to', 'eq' for 
+     'equal to', and 'ne' for 'not equal to'
+  -r, --requirement:
+     profile requirements field matches the regexp that is the next argument
+  -u, --user:
+     profile requirements are met for the user given in the next argument	
+
+Other Options:  
+  -e. --entry-format: format string for list entries,
+                  May use the variables NAME, LOCATION, PRECEDENCE,KIND,
+		  REQUIREMENTS, DESCRIPTION, and FILE. First 6 of which refer
+		  to the respective field for that profile, while FILE refers
+		  to the .listing file the profile is in.
+		  Parentheses, &, and characters interpreted specially by the
+		  shell should be escaped.
+		  (by default it just outputs the profile line)
+  -h, --help    : display this helpmessage
+  -s, --sort-key: fieldname of the profile field to sort on, one of
+                  [name, location, precedence, requirements, kind, description]
+		  this defaults to 'name'
+		  (Note: you may also use upper case if you want :)
+  
+EOF
+}
+
+#################################
+# Check if user set any defaults
+#################################
+if test -r /etc/default/desktop-profiles; then
+  . /etc/default/desktop-profiles
+fi;  
+
+####################
+# Parse Commandline
+####################
+while test $# -ge 1; do
+    # if not help, there should be at least one more argument
+    if (test "$1" = "-h") || (test "$1" = "--help") || (test $# -lt 2); then
+      print_help;
+      exit;
+    fi;
+    
+    case $1 in
+	-d | --directory) LISTINGS_DIR="$2" ;;
+	
+	-f | --file) EXTRA_LISTINGS="$2 $EXTRA_LISTINGS" ;;
+
+	-c | --comment | --description) DESCRIPTION_FILTER="$2"	;;
+	
+	-k | --kind) KIND_FILTER="$2" ;;
+	
+	-l | --location) LOCATION_FILTER="$2" ;;
+	
+	-n | --name) NAME_FILTER="$2" ;;
+	
+	-p | --precedence) PRECEDENCE_FILTER="-$2" ;;
+	
+	-r | --requirement) REQUIREMENT_FILTER="$2" ;;
+        
+	-u | --user) OUR_USER="$2" ;;
+
+	-s | --sort-key)
+	  case $2 in
+	    NAME | name) SORT_KEY=1 ;;
+	    LOCATION | location) SORT_KEY=2 ;;
+	    REQUIREMENTS | requirements) SORT_KEY=4 ;;
+	    KIND | kind) SORT_KEY=5 ;;
+	    DESCRIPTION | description) SORT_KEY=6 ;;
+	    PRECEDENCE| precedence) 
+	      SORT_KEY=3 
+	      SORT_ARGS='--general-numeric-sort --reverse';
+	    ;;
+         
+	    *)
+	      print_help;
+	      exit;
+	    ;;  
+	  esac;  
+	;;
+
+       -e | --entry-format) FORMAT="$2" ;;
+       
+	*)
+          print_help;
+	  exit;
+	;;
+  esac;	
+  
+  # All options take an argument so we should always shift twice
+  # except help, but then we don't get here
+  shift 2; 
+done;
+
+# get utility functions for working with .listing files
+LIB=/usr/share/desktop-profiles/listingmodule;
+if (test -r $LIB); then
+  . $LIB;
+else
+  echo "Shell library $LIB is missing! Aborting.";
+  exit 1;
+fi;
+
+# use utility function to give user what he wants (we set up the environment
+# variables to control the function output in the commandline parsing)
+filter_listings;
+
diff --git a/listingmodule b/listingmodule
new file mode 100644
index 0000000..de97683
--- /dev/null
+++ b/listingmodule
@@ -0,0 +1,229 @@
+#! /bin/sh
+# 
+# This is a shell library containing utility functions the scripts in the 
+# desktop-profiles package. This library currently contains the following 
+# functions (see the comments with each function for more info):
+#    - test_requirement: takes a requirement and (optionally) a username
+#    - test_profile_requirements: takes a profile's line (from the .listing
+#                                 file), and (optionally) a username
+#    - filter_listings: returns matching profiles from the available listing
+#                       files (output influenced by a number of environment
+#                       variables)
+# 
+# See desktop-profiles (7) for more information about using profiles through
+# desktop-profiles and the format of the .listing files
+#
+# (c) 2004 Bart Cornelis <cobaco AT skolelinux no>
+###############################################################################
+
+###############################################################################
+# test_requirement () - test wether the given requirement is fulfilled for a
+#                       given user
+#
+#     Note: won't work for not-current-user when command-requirments depend on
+#           the user's environment settings.
+#
+# $1 = requirement
+# $2 = username (defaults to current user if absent)
+#
+# Each requirement is of one of the following forms:
+#   requirement |  meaning
+#   --------------------------
+#   <group>     | $USER is a member of <group>
+#   !<group>    | $USER must not be member of group
+#   !           | always false (i.e. deactivate profile)
+#   $(command)  | (shell) command exits succesfully
+#
+# returns succesfully ($?=0) if requirement is met
+# returns 1 otherwise
+###############################################################################
+test_requirement(){
+  # if no requirement (given) -> then it's met
+  if (test "$1"x = x); then
+    exit;
+  fi;
+  
+  # initialize needed variables
+  OUR_USER=${2:-$USER}
+  OUR_GROUPS=`groups $OUR_USER | sed "s/^\$OUR_USER : //"`
+  
+  # !... requirement
+  if (echo "$1" | grep '^!' > /dev/null) ; then
+    GROUP=`echo "$1" | sed 's/^!//'`;
+    
+    # deactivated profile
+    if (test "$GROUP"x = x); then
+      exit 1;
+    fi;  
+    
+    # user is not a member of given group
+    if (echo $OUR_GROUPS | grep -v $GROUP > /dev/null); then
+      exit;# success
+    fi;
+
+  # given command must exit succesfully
+  elif (echo "$1" | grep '^\$(.*)' > /dev/null); then
+    COMMAND="`echo "$1" | sed -e 's/^\$(//' -e 's/)$//'`";
+    
+    sh -c "$COMMAND" > /dev/null;
+    exit $?;    
+
+  # user is a member of given group
+  else
+    if (echo $OUR_GROUPS | grep $1 > /dev/null); then
+      exit;# success
+    fi;
+  fi;  
+
+  # if we get here the requirement was not met
+  exit 1;
+}
+
+###############################################################################
+# test_profile_requirements() - test wether the given profile's requirements
+#                               are met for a given user.
+#
+#     Note: won't work for not-current-user when command-requirments depend on
+#           the user's environment settings.
+#
+# $1 = the profile line from the listing file
+# $2 = username (defaults to current user if absent)
+#
+# returns succesfully ($?=0) if requirement is met
+# returns 1 otherwise
+###############################################################################
+test_profile_requirements() {
+  PROFILE_REQUIREMENTS="`echo $@ | cut --fields 4 --delimiter ";"`";
+
+  # no requirements -> met
+  if (test "$PROFILE_REQUIREMENTS"x = x); then
+    exit;      
+  fi;
+    
+  # requirements -> check one by one
+  while (test "$PROFILE_REQUIREMENTS"x != x); do
+    # attempt to get first (remaining) REQUIREMENT 
+    declare -i C=1;
+    REQUIREMENT=`echo $PROFILE_REQUIREMENTS | cut --fields 1 --delimiter " "`;
+
+    # if command requirement
+    if (echo "$REQUIREMENT" | grep "^\$(" > /dev/null); then 
+      #make sure we have the whole command (with params)
+      while (echo "$REQUIREMENT" | grep -v ')$' > /dev/null); do
+        C=C+1;
+        REQUIREMENT=`echo $PROFILE_REQUIREMENTS | cut --fields -$C --delimiter " "`;
+      done;	
+
+      # prepare loop for next iteration 
+      C=C+1;
+      PROFILE_REQUIREMENTS=`echo $PROFILE_REQUIREMENTS | cut --fields $C- --delimiter " " `;
+    else
+      # prepare loop for next iteration 
+      PROFILE_REQUIREMENTS=`echo $PROFILE_REQUIREMENTS | sed -e "s/^$REQUIREMENT//" -e "s/^ *//"`;
+    fi;
+      
+    # test current requirement 
+    # -> if unmet there's no need to keep testing, so exit indicating failure
+    if !(test_requirement "$REQUIREMENT" $2); then
+      exit 1;
+    fi
+  done;
+    
+  # all requirements are met (or we wouldn't get here)
+  exit;      
+}
+
+###############################################################################
+# filter_listings() - filters the profiles in the .listing files 
+#                     (criteria and output-format are set through a number of
+#                      environment variables, as listed below)
+#
+# The following environment variables _may_ be used: 
+# - NAME_FILTER, LOCATION_FILTER, REQUIREMENT_FILTER, 
+#   KIND_FILTER, and DESCRIPTION_FILTER: contain the regexp filter to be used
+#   on the corresponding field of the profile-line
+# - PRECEDENCE_FILTER contains the second half of an expression to be passed to 
+#   the test program (e.g. '-gt 0', '-ge 0', or '-lt 50')
+# - OUR_USER: requirements need to be met for this user
+# - FORMAT: don't just echo the profile-line from the .listing file, but use
+#   the specified format (may use the variables NAME, LOCATION, PRECEDENCE, 
+#   REQUIREMENT, KIND, DESCRIPTION, FILE variables. First 6 refer to the 
+#   the respective fields for that profile, FILE refers to the file the profile
+#   is listed in.
+#	NOTE: characters interpreted specially by the shell (such as ';') need
+#             to be escaped.
+# - SORT_KEY: sort on field (NOTE: numeric)
+# - SORT_ARGS: extra arguments to be given to the sort command (e.g. when
+#   sorting on the precedence field (3) you probably want to set this to
+#   '--general-numeric-sort --reverse')
+# - EXTRA_LISTINGS: may contain a comma-separated list of extra (outside the 
+#   $LISTINGS_DIR) .listing files to be taken into account.
+# - LISTINGS_DIR: the directory containing the .listing files to include 
+#   (defaults to '/etc/desktop-profiles', probably shouldn't be changed ever)
+#
+# In absence of any set variables it will just output all available profiles
+# sorted by name.
+#
+# The lisst-desktop-profile script from the desktop-profiles package offers an
+# example of how to use this function.
+###############################################################################
+filter_listings () {
+  # Make sure the variable we need are initialized
+  LISTINGS_DIR=${LISTINGS_DIR:-'/etc/desktop-profiles'}
+  EXTRA_LISTINGS=${EXTRA_LISTINGS:-''}
+
+  SORT_KEY=${SORT_KEY:-1}
+  SORT_ARGS=${SORT_ARGS:-''}
+  
+  NAME_FILTER=${NAME_FILTER:-''}
+  LOCATION_FILTER=${LOCATION_FILTER:-''}
+  PRECEDENCE_FILTER=${PRECEDENCE_FILTER:-''}
+  REQUIREMENT_FILTER=${REQUIREMENT_FILTER:-''}
+  KIND_FILTER=${KIND_FILTER:-''}
+  DESCRIPTION_FILTER=${DESCRIPTION_FILTER:-''}
+
+  OUR_USER=${OUR_USER:-''}
+
+  FORMAT=${FORMAT:-'$NAME\;$DESCRIPTION\;$PRECEDENCE\;$REQUIREMENTS\;$KIND\;$DESCRIPTION'};
+
+  # do the filtering
+  cat $(ls $LISTINGS_DIR/*.listing) $EXTRA_LISTINGS |  grep -v -e "^#" -e "^ *$" | sort $SORT_ARGS --key="$SORT_KEY" --field-separator=';' | \
+  while read PROFILE; do
+    # split fields
+    export NAME="`echo $PROFILE | cut --delimiter ';' --fields 1`";
+    export LOCATION="`echo $PROFILE | cut --delimiter ';' --fields 2`";
+    export PRECEDENCE="`echo $PROFILE | cut --delimiter ';' --fields 3`";
+    export REQUIREMENTS="`echo $PROFILE | cut --delimiter ';' --fields 4`";
+    export KIND="`echo $PROFILE | cut --delimiter ';' --fields 5`";
+    export DESCRIPTION="`echo $PROFILE | cut --delimiter ';' --fields 6`";
+
+    export FILE=`grep -l "^$NAME;" $LISTINGS_DIR/*.listing $EXTRA_LISTINGS`;
+
+    if (test "$PRECEDENCE"x = x); then 
+      #unset = lower then anything, so set to insanely low value
+      NORM_PRECEDENCE='-999999999999999999';
+    else 
+      NORM_PRECEDENCE=$PRECEDENCE;
+    fi;
+    
+    # if filters don't match -> go to next profile
+    if ( (test "${NAME_FILTER:-''}" != '') && (echo "$NAME" | grep -v "$NAME_FILTER" > /dev/null) ) ||
+       ( (test "${LOCATION_FILTER:-''}" != '') && (echo "$LOCATION" | grep -v "$LOCATION_FILTER" > /dev/null) ) ||
+       ( (test "${PRECEDENCE_FILTER:-''}" != '') && !(test "$NORM_PRECEDENCE" $PRECEDENCE_FILTER) ) ||
+       ( (test "${REQUIREMENTS_FILTER:-''}" != '') && (echo "$REQUIREMENTS" | grep -v "$REQUIREMENTS_FILTER" > /dev/null) ) ||
+       ( (test "${KIND_FILTER:-''}" != '') && (echo "$KIND" | grep -v "$KIND_FILTER" > /dev/null) ) ||
+       ( (test "${DESCRIPTION_FILTER:-''}" != '') && (echo "$DESCRIPTION" | grep -v "$DESCRIPTION_FILTER" > /dev/null) ); then
+      continue;
+    fi;  
+
+    # if we have a username to match for, and requirements are not met
+    if (test "$OUR_USER" != '') && 
+       !(test_profile_requirements "$PROFILE" "$OUR_USER"); then
+       # -> go to next profile
+       continue;
+    fi;  
+
+    # if we get here output the profile's information in the requested format
+    echo $(sh -c "echo $FORMAT");
+  done;
+}  

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-edu/pkg-team/desktop-profiles.git



More information about the debian-edu-commits mailing list