[debian-edu-commits] debian-edu/ 43/183: Get number of needed temporary files down to 2 (saves a whopping 0.020s of the script execution :O)

Alexander Alemayhu ccscanf-guest at moszumanska.debian.org
Wed Jun 11 16:48:32 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 04d743f4388ef1a20212fbe47c297828bf4d9613
Author: Bart Cornelis <cobaco at linux.be>
Date:   Tue Jan 18 20:50:45 2005 +0000

    Get number of needed temporary files down to 2 (saves a whopping 0.020s of
    the script execution :O)
---
 20desktop-profiles_activateDesktopProfiles | 54 +++++++++++++++++-------------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/20desktop-profiles_activateDesktopProfiles b/20desktop-profiles_activateDesktopProfiles
index c4717dc..3b28571 100644
--- a/20desktop-profiles_activateDesktopProfiles
+++ b/20desktop-profiles_activateDesktopProfiles
@@ -25,29 +25,41 @@ fi;
 # (result for each $KIND are saved in the file pointed to by $KIND_FILE)
 #########################################################################
 sort_profiles(){
+
+  #make sure we start with empty variables
+  KDEDIRS='';XDG_CONFIG_DIRS='';XDG_DATA_DIRS='';CHOICESPATH='';GNUSTEP_PATHLIST='';UDEDIRS=''
+ 
+  # get profiles that are have fulfilled requirements, and save result on file descriptor 3
+  # FIXME: can we avoid the tempfile here?
+  PROFILES=`tempfile`;
   (# get profiles that are have fulfilled requirements
      cat $(list_listings) | grep -v -e "^[[:space:]]*#" -e "^[[:space:]]*$" | while read PROFILE; do
       if (test_profile_requirements "$PROFILE"); then
-        echo $PROFILE;      
-      fi;  
+        echo $PROFILE;
+      fi;
     done;
-   #and sort them by preference
-  ) | sort --reverse --general-numeric-sort --field-separator=";" --key 3 | \
-  while read PROFILE; do
+   #and sort them by preference 
+  ) | sort --reverse --general-numeric-sort --field-separator=";" --key 3 > $PROFILES;
+  exec 3<> $PROFILES;
+  rm $PROFILES;
+
+  # read from file descriptor 3 
+  # (don't use pipe, because then variables being changed are in a subshell)
+  while read PROFILE <&3; do
   # sort per profile kind
     KIND=`echo "$PROFILE" | cut --fields 5 --delimiter ";"`;
     if (test "$KIND" = "KDE"); then 
-      echo -n "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $KDE_FILE;
+      KDEDIRS="$KDEDIRS $(echo "$PROFILE" | cut --fields 2 --delimiter ";")";
     elif (test "$KIND" = "XDG_CONFIG"); then 
-      echo -n "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $XDG_CONFIG_FILE;
+      XDG_CONFIG_DIRS="$XDG_CONFIG_DIRS $(echo "$PROFILE" | cut --fields 2 --delimiter ";")";
     elif (test "$KIND" = "XDG_DATA"); then 
-      echo -n "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $XDG_DATA_FILE;
+      XDG_DATA_DIRS="$XDG_DATA_DIRS $(echo "$PROFILE" | cut --fields 2 --delimiter ";")";
     elif (test "$KIND" = "ROX"); then 
-      echo -n "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $ROX_FILE;
+      CHOICESPATH="$CHOICESPATH $(echo "$PROFILE" | cut --fields 2 --delimiter ";")";
     elif (test "$KIND" = "GNUSTEP"); then 
-      echo -n "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $GNUSTEP_FILE;
+      GNUSTEP_PATHLIST="$GNUSTEP_PATHLIST $(echo "$PROFILE" | cut --fields 2 --delimiter ";")";
     elif (test "$KIND" = "UDE"); then 
-      echo -n "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $UDE_FILE;
+      UDEDIRS="$UDEDIRS $(echo "$PROFILE" | cut --fields 2 --delimiter ";")";
     elif (test "$KIND" = "GCONF"); then 
       echo "`echo "$PROFILE" | cut --fields 2 --delimiter ";"` " >> $GCONF_FILE;
     fi;	
@@ -58,7 +70,7 @@ sort_profiles(){
 # Functions for activating the different kinds of profile
 ##########################################################
 activate_KDE () {
-  KDEDIRS=`cat $KDE_FILE | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  KDEDIRS=`echo "$KDEDIRS" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   if (test "$KDEDIRS"x != x) &&
      (test "$KDEDIRS" != "`cat $DEFAULT_LISTING | grep "^kde-prefix" | cut --fields 2 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`"); then
     KDEDIRS=$(sh -c "echo $KDEDIRS");# FORCE expansion of variables in KDEDIRS if any
@@ -67,7 +79,7 @@ activate_KDE () {
 }
 
 activate_XDG_CONFIG () {
-  XDG_CONFIG_DIRS=`cat $XDG_CONFIG_FILE | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  XDG_CONFIG_DIRS=`echo "$XDG_CONFIG_DIRS" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   if (test "$XDG_CONFIG_DIRS"x != x) &&
      (test "$XDG_CONFIG_DIRS" != "`cat $DEFAULT_LISTING | grep "^default-xdg_config_dirs" | cut --fields 2 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`"); then
     XDG_CONFIG_DIRS=$(sh -c "echo $XDG_CONFIG_DIRS");# FORCE expansion of variables in XDG_CONFIG_DIRS if any
@@ -76,7 +88,7 @@ activate_XDG_CONFIG () {
 }
 
 activate_XDG_DATA () {
-  XDG_DATA_DIRS=`cat $XDG_DATA_FILE | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  XDG_DATA_DIRS=`echo "$XDG_DATA_DIRS" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   if (test "$XDG_DATA_DIRS"x != x) &&
      (test "$XDG_DATA_DIRS" != "`cat $DEFAULT_LISTING | grep "^default-xdg_data_dirs" | cut --fields 2 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`"); then
     XDG_DATA_DIRS=$(sh -c "echo $XDG_DATA_DIRS");# FORCE expansion of variables in XDG_DATA_DIRS if any
@@ -85,7 +97,7 @@ activate_XDG_DATA () {
 }
 
 activate_ROX () {
-  CHOICESPATH=`cat $ROX_FILE | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  CHOICESPATH=`echo "$CHOICESPATH" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   DEFAULT_CHOICES=$(cat $DEFAULT_LISTING | grep '^default-rox-system;' | cut --field 2 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g")
   DEFAULT_CHOICES="$(cat $DEFAULT_LISTING | grep '^default-rox-user;' | cut --field 2 --delimiter ";" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"):$DEFAULT_CHOICES"
   if (test "$CHOICESPATH"x != x) &&
@@ -97,7 +109,7 @@ activate_ROX () {
 
 activate_UDE () {
   # don't s/ /:g/ in next line, UDE doesn't currently support combining profile dirs
-  UDEDIRS=`cat $UDE_FILE | sed -e "s/^ *//" -e "s/ *$//"`
+  UDEDIRS=`echo "$UDEDIRS" | sed -e "s/^ *//" -e "s/ *$//"`
   if (test "$UDEDIRS"x != x) &&
      (test "$UDEDIRS" != "`cat $DEFAULT_LISTING | grep "^ude-install-dir" | cut --fields 2 --delimiter ";"`"); then
     # Take first dir and break, as UDE currently only supports one dir
@@ -117,7 +129,7 @@ activate_GNUSTEP () {
   export GNUSTEP_SYSTEM_ROOT=${GNUSTEP_SYSTEM_ROOT:-/usr/lib/GNUstep/System};
 
   #should be in GNUSTEP_PATHLIST (see /usr/lib/GNUstep/System/Library/Makefiles/GNUstep.sh)
-  GNUSTEP_PATHLIST=`cat $GNUSTEP_FILE | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
+  GNUSTEP_PATHLIST=`echo "$GNUSTEP_PATHLIST" | sed -e "s/^ *//" -e "s/ *$//" -e "s/ /:/g"`
   
   # get default domains
   DEFAULT_DOMAINS=$(cat $DEFAULT_LISTING | grep "^gnustep-user-domain" | cut --fields 2 --delimiter ";" | sed -e  "s/^ *//" -e "s/ *$//" -e "s/ /:/g")
@@ -198,12 +210,6 @@ activate_GCONF () {
   ############################################################
   if (test "$ACTIVE_PROFILE_KINDS"x != "x"); then
     # get temp file names
-    KDE_FILE=`tempfile`;
-    XDG_CONFIG_FILE=`tempfile`;
-    XDG_DATA_FILE=`tempfile`;
-    ROX_FILE=`tempfile`;
-    GNUSTEP_FILE=`tempfile`;
-    UDE_FILE=`tempfile`;
     GCONF_FILE=`tempfile`;
 
     # sort the profile into the temp files
@@ -217,5 +223,5 @@ activate_GCONF () {
     done;
 
     # cleanup the tempfiles
-    rm $KDE_FILE $XDG_DATA_FILE $XDG_CONFIG_FILE $ROX_FILE $GNUSTEP_FILE $UDE_FILE $GCONF_FILE 
+    rm $GCONF_FILE 
   fi;  

-- 
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