[SM-Commit] BZR Change 19 to stage-root sorcery by David Brown <dmlb2000 at dmlb2004>

bzr at mail.sourcemage.org bzr at mail.sourcemage.org
Fri Apr 14 02:50:04 EDT 2006


------------------------------------------------------------
revno: 19
committer: David Brown <dmlb2000 at dmlb2004>
branch nick: stage-root
timestamp: Thu 2006-04-13 23:41:04 -0700
message:
  merged libsorcery from devel
  made libgrimoire rm_source_dir's rm -rf in parallel so stuff can continue with
  out a problem
    ------------------------------------------------------------
    merged: root at courier-20060414040742-0bcc0d5048229ea5
    committer: root <root at courier>
    branch nick: devel
    timestamp: Thu 2006-04-13 21:07:42 -0700
    message:
      fix bug 10282

=== modified file 'ChangeLog'
--- ChangeLog	
+++ ChangeLog	
@@ -1,3 +1,8 @@
+2006-04-13 Andrew Stitt <astitt at sourcemage.org>
+	* libsorcery: consolidate history functions, bug 10282
+	  modified patch from Jaka Kranjc. Also added a long overdue full
+	  explaination changelog parsing awk script.
+
 2006-04-12 Andrew Stitt <astitt at sourcemage.org>
 	* gaze: fix bug 10144, fix viewing of install queue, patch from
 	  Jaka Kranjc

=== modified file 'var/lib/sorcery/modules/libgrimoire'
--- var/lib/sorcery/modules/libgrimoire	
+++ var/lib/sorcery/modules/libgrimoire	
@@ -80,8 +80,9 @@
     # a) $DEAD_DIR being an empty string
     # b) $DEAD_DIR being set to "/" (or anything above /usr/src)
     # c) $DEAD_DIR containing metacharacters (like newline)
-    mv  "$DEAD_DIR"  "$INSTALL_ROOT/usr/src/deaddir"  &&
-    rm  -rf          "$INSTALL_ROOT/usr/src/deaddir"  2>  /dev/null
+    local ddate=$(date +%Y%m%d%H%M%S%N)
+    mv  "$DEAD_DIR"  "$INSTALL_ROOT/usr/src/deaddir-$ddate"  &&
+    (rm  -rf          "$INSTALL_ROOT/usr/src/deaddir-$ddate"  2>  /dev/null) &
 
     popd  2>&1  >  /dev/null
     true

=== modified file 'var/lib/sorcery/modules/libsorcery'
--- var/lib/sorcery/modules/libsorcery	
+++ var/lib/sorcery/modules/libsorcery	
@@ -903,19 +903,13 @@
 ##
 #---------------------------------------------------------------------
 function install_queue_history() {
-  local PAGER2
-  if [ "$PAGER" == "less" ] ; then PAGER2="more"; else PAGER2="$PAGER"; fi
-  local spell=
+  local spell
   for spell in `cat $INSTALL_QUEUE`; do
     local date="`grep "^${spell}:" $SPELL_STATUS | cut -d':' -f2`"
-    local datedash="`echo "$date" | cut -c1-4`-`echo "$date" | cut -c5-6`-`echo "$date" | cut -c7-8`"
-    (
-      echo -e "Viewing history since last update ($datedash) for spell --  ${spell}  -- :" && 
-      echo                 &&
-      gaze history $spell
-    ) |
-      awk -v date="$date" '{ d = (strtonum(substr($0,1,4) substr($0,6,2) substr($0,9,2)) < date && strtonum(substr($0,1,4)) > 0) }; NR == 1, d { if (!d) print }' | 
-      $PAGER2
+    local datedash="`echo "$date" | sed 's,^\(....\)\(..\)\(..\)$,\1-\2-\3,'`"
+
+    get_new_changes "Viewing history since last update ($datedash) for spell --  ${spell}  -- :" "$date" "$(codex_find_spell_by_name $spell)/HISTORY"
+
     query "Would you like to ${RED} remove ${QUERY_COLOR} spell ${SPELL_COLOR} $spell ${QUERY_COLOR} from the install queue?" n &&
       sedit "s/^$spell$//" $INSTALL_QUEUE &&
       echo -e "${QUERY_COLOR} The spell ${SPELL_COLOR} $spell ${QUERY_COLOR} removed from $INSTALL_QUEUE.${DEFAULT_COLOR}"
@@ -929,30 +923,18 @@
 #---------------------------------------------------------------------
 function grimoire_history() {
 
-  if [ -e $grimoire/ChangeLog ] ; then 
-    local PAGER2
-    if [ "$PAGER" == "less" ] ; then 
-      PAGER2="more" 
-    else 
-      PAGER2="$PAGER" 
-    fi
-    local grimoire="$1"
+  local grimoire="$1"
+  if [ -e $grimoire/ChangeLog ] ; then
     local grimoirename="${grimoire##*/}"
     local date="`cat "$STATE_DIRECTORY/$grimoirename.lastupdate" 2> /dev/null`"
     [ -z "$date" ] && date="20030818"
-    local datedash="`echo "$date" | cut -c1-4`-`echo "$date" | cut -c5-6`-`echo "$date" | cut -c7-8`"
-    (
-      echo -e "Viewing history since last update ($datedash) for grimoire --  ${grimoirename}  -- :" && 
-      echo                 &&
-      cat "$grimoire/ChangeLog" 2> /dev/null
-    ) |
-    awk -v date="$date" '{ d = (strtonum(substr($0,1,4) substr($0,6,2) substr($0,9,2)) < date && strtonum(substr($0,1,4)) > 0) }; NR == 1, d { if (!d) print }' | 
-    $PAGER2
+    local datedash=$(echo "$date" | sed 's,^\(....\)\(..\)\(..\)$,\1-\2-\3,')
+    get_new_changes "Viewing history since last update ($datedash) for grimoire --  ${grimoirename}  -- :" "$date" "$grimoire/ChangeLog"
   else
     echo  "No ChangeLog in the $grimoire Grimoire, skipping viewing..."
     echo  ""
   fi
-  echo "`date +%Y%m%d`" > "$STATE_DIRECTORY/$grimoirename.lastupdate"
+  date +%Y%m%d > "$STATE_DIRECTORY/$grimoirename.lastupdate"
 }
 
 
@@ -962,21 +944,64 @@
 ##
 #---------------------------------------------------------------------
 function sorcery_history() {
-  local PAGER2
-  if [ "$PAGER" == "less" ] ; then PAGER2="more"; else PAGER2="$PAGER"; fi
   local date="`cat "$STATE_DIRECTORY/sorcery.lastupdate" 2> /dev/null`"
   [ -z "$date" ] && date="20030818"
-  local datedash="`echo "$date" | cut -c1-4`-`echo "$date" | cut -c5-6`-`echo "$date" | cut -c7-8`"
-  (
-    echo -e "Viewing history since last update ($datedash) for sorcery :" && 
-    echo                 &&
-    cat "/usr/share/doc/sorcery/ChangeLog"
-  ) |
-    awk -v date="$date" '{ d = (strtonum(substr($0,1,4) substr($0,6,2) substr($0,9,2)) < date && strtonum(substr($0,1,4)) > 0) }; NR == 1, d { if (!d) print }' | 
-    $PAGER2
-  echo "`date +%Y%m%d`" > "$STATE_DIRECTORY/sorcery.lastupdate"
-}
-
+  local datedash="`echo "$date" | sed 's,^\(....\)\(..\)\(..\)$,\1-\2-\3,'`"
+
+  get_new_changes "Viewing history since last update ($datedash) for sorcery :"  "$date" /usr/share/doc/sorcery/ChangeLog
+
+  date +%Y%m%d > "$STATE_DIRECTORY/sorcery.lastupdate"
+}
+
+#---------------------------------------------------------------------
+##@param old date
+##@param changelog
+## Get the new changes from passed changelog argument
+##
+#---------------------------------------------------------------------
+function get_new_changes() {
+    local PAGER2="$(override_pager)"
+    local msg="$1"
+    local date="$2"
+    # This needs some explaination:
+    # The first item in {}'s extracts the date, assuming the format yyyy-mm-dd
+    # then checks if its less than the last-update date ($date). The second
+    # part ensures that we're actually looking at a date and not a line
+    # of changelog. If both those are true, set 'd' to 1, otherwise d is '0'.
+    #
+    # In other words, d is 0 until it encounters a starting changelog entry
+    # from before the given $date. Then d is 1 for each starting entry. Its
+    # always 0 for bulleted changelog lines and blank lines.
+    #
+    # The second portion begins "NR==1,d". This is special awk syntax
+    # that says to run the stuff to the right in {}'s starting once the
+    # first statement is true, up through when the second one is true.
+    # For example, NR==1,NR==8 would run the right-hand block for lines 1
+    # through 8.
+    #
+    # NR is the line number, so its true on the first line. d is true once the
+    # the dates are from before the last update. The if(!d) is necessary
+    # to skip the first line where the changelog date is less than $date.
+    #
+    local changelog="$( awk -v date="$date" '{ d = (strtonum(substr($0,1,4) substr($0,6,2) substr($0,9,2)) < date && strtonum(substr($0,1,4)) > 0); }; NR == 1, d { if (!d) print }' "$3" )"
+
+    if [[ "$changelog" ]] ; then
+      {
+        echo "$msg"
+        echo
+        echo "$changelog"
+      } | $PAGER2
+    else
+      echo "$msg"
+      echo
+      echo "Nothing new."
+    fi
+}
+
+function override_pager() {
+  #placeholder for a proper fix for http://bugs.sourcemage.org/show_bug.cgi?id=8070
+  if [ "$PAGER" == "less" ]; then echo "more"; else echo "$PAGER"; fi
+}
 
 #---------------------------------------------------------------------
 ##




More information about the SM-Commit mailing list