[debian-edu-commits] debian-edu/ 128/183: Add a cache of the profile assignments in the simple case where we're unconditionally activating a bunch of profiles (i.e. when no profiles have group or command requirements, everyone gets the same profiles)

Alexander Alemayhu ccscanf-guest at moszumanska.debian.org
Wed Jun 11 16:48:40 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 057dc44c1ea95836e36bf3f360918814b9440ccb
Author: Bart Cornelis <cobaco at linux.be>
Date:   Tue Dec 12 22:11:10 2006 +0000

    Add a cache of the profile assignments in the simple case where we're
    unconditionally activating a bunch of profiles
    (i.e. when no profiles have group or command requirements, everyone gets the
    same profiles)
---
 20desktop-profiles_activateDesktopProfiles | 11 ++++--
 desktop-profiles                           |  4 +++
 update-profile-cache                       | 55 ++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/20desktop-profiles_activateDesktopProfiles b/20desktop-profiles_activateDesktopProfiles
index ba695c0..ff1738d 100644
--- a/20desktop-profiles_activateDesktopProfiles
+++ b/20desktop-profiles_activateDesktopProfiles
@@ -286,15 +286,20 @@ if (test $INSTALLED = true); then
   # Make sure the variable we need are initialized
   #################################################
   LISTINGS_DIRS=${LISTINGS_DIRS:-'/etc/desktop-profiles'}
+  CACHE_FILE=${CACHE_FILE:-'/var/cache/desktop-profiles'}
   ACTIVE_PROFILE_KINDS=${ACTIVE_PROFILE_KINDS:-''}
   DEFAULT_LISTING=/etc/desktop-profiles/desktop-profiles.listing
   PROFILE_PATH_FILES_DIR=${PROFILE_PATH_FILES_DIR:-'/var/cache/desktop-profiles/'}
 
   ############################################################
   # Actual activation of profiles
-  # don't test requirements if no profile kinds are activated
   ############################################################
-  if (test "$ACTIVE_PROFILE_KINDS"x != "x"); then
+  if (test -r $CACHE_FILE); then 
+  # if we have a cache then use it
+    export $(cat $CACHE_FILE);
+  elif (test "$ACTIVE_PROFILE_KINDS"x != "x"); then
+  # else if we have any profile kinds we're interested in, then go 
+  # calculate the profile assignments
     # add trap to ensure we don't leave any tempfiles behind 
     trap general_trap HUP INT TERM;
     # get temp file
@@ -311,5 +316,5 @@ if (test $INSTALLED = true); then
       # which can happen e.g. due to typo's in the config file.
       activate_$KIND || true;
     done;
-  fi;  
+  fi; # end dynamic profile assignment
 fi;  
diff --git a/desktop-profiles b/desktop-profiles
index a8943c4..42304fc 100644
--- a/desktop-profiles
+++ b/desktop-profiles
@@ -13,6 +13,10 @@
 # default.
 LISTINGS_DIRS="/etc/desktop-profiles"
 
+# File containing the cache of profile assignments 
+# (cache is only generated when that makes sense)
+CACHE_FILE="/var/cache/desktop-profiles"
+
 #################################
 # SETTINGS FOR xsession.d script
 #################################
diff --git a/update-profile-cache b/update-profile-cache
new file mode 100755
index 0000000..5a0c6cd
--- /dev/null
+++ b/update-profile-cache
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# This script checks whether generating a cache of the wanted profile 
+# assignment makes sense, and if so (re)generate the cache if it's out of date
+# 
+# Supported CACHE_TYPES:
+# - static: used when profiles are either activated machine-wide or not at all
+# - none: used when we either don't want or don't support a cache
+# TODO: caching in the non-static case
+###############################################################################
+
+#################
+# initialization
+#################
+  # get user preferences
+  if (test -r /etc/default/desktop-profiles); then
+    . /etc/default/desktop-profiles;
+  fi;  
+
+  #failsave in case default file is deleted
+  LISTINGS_DIRS=${LISTINGS_DIRS:-'/etc/desktop-profiles'}
+  CACHE_FILE=${CACHE_FILE:-'/var/cache/desktop-profiles'}
+
+##################  
+# set $CACHE_TYPE  
+##################
+  # if we have at least 1 group or command requirement then there will be at 
+  # least 1 character in the requirement that's neither whitespace nor '!'
+  if(test $(list-desktop-profiles -r '[^[:space:]!]' | wc -l) -ne 0); then
+    CACHE_TYPE=none;
+  else 
+    CACHE_TYPE=static
+  fi;
+
+#######################
+# generate $CACHE_FILE
+#######################
+  if (test $CACHE_TYPE = static); then
+    #if:
+    # - cache doesn't exist yet
+    # - last modification time of any metadata file is newer then of the cache
+    if !(test -e $CACHE_FILE) ||
+       !(test $(ls -t -1 /etc/desktop-profiles/*.listing $CACHE_FILE | head -1) = "$CACHE_FILE"); then
+
+      # delete old cache (otherwise activateDesktopProfiles reuses it)
+      rm -f $CACHE_FILE;
+
+      # regenerate the cache
+      . /etc/X11/Xsession.d/20desktop-profiles_activateDesktopProfiles;
+      env | grep 'KDEDIRS\|XDG_CONFIG_DIRS\|XDG_DATA_DIRS\|CHOICESPATH\|UDEdir\|GNUSTEP_PATHLIST\|MANDATORY_PATH\|DEFAULTS_PATH' > $CACHE_FILE;
+    fi;  
+  else
+    # we don't want to use the cache so make sure no old one is left behind  
+    rm -f $CACHE_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