[Lunar-commits] r25694 - in moonbase/trunk/devel/bzr: . plugin.d

Samuel Verstraete elangelo at lunar-linux.org
Mon Sep 3 10:23:59 CEST 2007


Author: elangelo
Date: 2007-09-03 10:23:59 +0200 (Mon, 03 Sep 2007)
New Revision: 25694

Added:
   moonbase/trunk/devel/bzr/plugin.d/
   moonbase/trunk/devel/bzr/plugin.d/download-bzr.plugin
Log:
no feedback so i'm just gonna do something...


Added: moonbase/trunk/devel/bzr/plugin.d/download-bzr.plugin
===================================================================
--- moonbase/trunk/devel/bzr/plugin.d/download-bzr.plugin	                        (rev 0)
+++ moonbase/trunk/devel/bzr/plugin.d/download-bzr.plugin	2007-09-03 08:23:59 UTC (rev 25694)
@@ -0,0 +1,124 @@
+#!/bin/bash
+############################################################
+#                                                          #
+# download-bzr.plugin - download BZR urls                  #
+#                                                          #
+############################################################
+#                                                          #
+# Copyright 2005 by Auke Kok under GPLv2                   #
+#                                                          #
+# Parts Copyrighted Samuel Verstraete 2007 under GPLv2     #
+#                                                          #
+############################################################
+
+# valid BZR urls are:
+# bzr://
+# bzr+http:// (will be transformed to http://)
+# bzr+https:// (will be transformed to https://)
+# bzr+ssh://
+
+plugin_source_download_bzr() {
+  # check if we can handle this URL format
+  if [ "${1:0:6}" != "bzr://" -a "${1:0:11}" != "bzr+http://" -a "${1:0:12}" != "bzr+https://" -a "${1:0:10}" != "bzr+ssh://" ] ; then
+    return 2
+  fi
+  debug_msg "plugin_source_needrefresh_bzr($@)"
+
+  if ! module_installed bzr ; then
+    # full stop: we need to make sure the user sees this error:
+    message "${PROBLEM_COLOR}! Cannot fetch BZR sources without \"bzr\" installed${DEFAULT_COLOR}"
+    exit 1
+  fi
+
+  BZR_URL=$(echo $1 | cut -d: -f1-2)
+  # translate bzr+http(s) urls:
+  if [ "${BZR_URL:0:8}" == "bzr+http" ]; then
+    BZR_URL="${BZR_URL:4}"
+  fi
+
+  message  "${MESSAGE_COLOR}Downloading BZR module for" \
+ 	   "module ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
+
+  SBASE=$(source_basename $2)
+  mk_source_dir $TMPDIR/$MODULE-$VERSION
+  cd $TMPDIR/$MODULE-$VERSION
+
+  if [ -f "$3/$2" ] ; then
+    verbose_msg "Extracting local BZR copy"
+    CD=$(pwd -P)
+    if ! unpack $2 ; then
+      message "${PROBLEM_COLOR}Warning: bad local BZR copy, checking out fresh BZR copy${DEFAULT_COLOR}"
+
+      rm_source_dir $TMPDIR/$MODULE-$VERSION
+      mk_source_dir $TMPDIR/$MODULE-$VERSION
+    fi
+    cd $CD
+  fi
+
+  NUM_RETRY=${NUM_RETRY:-5}
+  if [ "$NUM_RETRY" -eq 0 ]; then
+      NUM_RETRY=1000
+  fi
+
+  for (( TRY=1 ; $TRY<$NUM_RETRY+1 ; TRY++ )) ; do
+    if [ -d "$SBASE/.bzr" ] ; then
+      cd $SBASE
+      verbose_msg "[${TRY}] bzr up"
+      svn up && GOT_BZR="yes" 
+      cd ${CD}
+    else
+      verbose_msg "[${TRY}] bzr co $BZR_URL $SBASE"
+      svn co $BZR_URL $SBASE && GOT_BZR="yes"
+    fi
+
+    if [ "$?" == "0" ] ; then
+      break
+    fi
+
+    sleep 2
+  done
+
+  if [ "$GOT_BZR" == "yes" ] ; then
+    message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$2${DEFAULT_COLOR}"
+    tar cjf $3/$2 $SBASE
+  else
+    activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not fetch \"$1\""
+  fi
+
+  cd $TMPDIR
+  rm_source_dir $TMPDIR/$MODULE-$VERSION
+
+}
+
+
+plugin_source_needrefresh_bzr() {
+  # check if we can handle this URL format
+  if [ "${1:0:6}" != "bzr://" -a "${1:0:11}" != "bzr+http://" -a "${1:0:12}" != "bzr+https://" -a "${1:0:10}" != "bzr+ssh://" ] ; then
+    return 2
+  fi
+  debug_msg "plugin_source_needrefresh_bzr($@)"
+
+  if [ ! -f $3/$2 ]; then
+    return 0
+  fi
+
+  BZR_THRESHOLD=${SVN_THRESHOLD:-10}
+  if (( "BZR_THRESHOLD" > 0 )) ; then
+	if [ "$(find $3/$2 -amin +$BZR_THRESHOLD)" == "$3/$2" ] ; then
+      # it is older:
+	  return 0
+	else
+      message "${MESSAGE_COLOR}BZR update not required for \"${FILE_COLOR}$(basename $2)${DEFAULT_COLOR}${CYAN}\" (less than $BZR_THRESHOLD minutes old)${DEFAULT_COLOR}"
+      # now we can send a FAIL so the next plugins are skipped:
+	  return 1
+    fi
+  else
+    # always return true if threshhold is zero
+    return 0
+  fi
+}
+
+
+plugin_register SOURCE_DOWNLOAD plugin_source_download_bzr
+plugin_register SOURCE_NEEDREFRESH plugin_source_needrefresh_bzr
+



More information about the Lunar-commits mailing list