]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
simplaret: converted simplaret_search and simplaret_purge to the new repository format
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Fri, 8 Dec 2006 16:07:30 +0000 (16:07 +0000)
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Fri, 8 Dec 2006 16:07:30 +0000 (16:07 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@42 04377dda-e619-0410-9926-eae83683ac58

src/simplaret

index b7c6216e1957127f512e4c7d4ed5d924bdbcf58e..88f59787938835e7e8967045867d5cc7e1631820 100755 (executable)
@@ -214,11 +214,41 @@ function simplaret_update {
 
 }
 
-function simplaret_search {
+function simplaret_find_package {
+
+  # grep packages in a repository's FILELIST.TXT
+  # usage: simplaret_find_package <package-name> <repository-folder>
+
+  grep $1 $2/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"
+
+}
+
+function simplaret_show_package {
 
-  # TODO: ROOT_PRIORITY
+  # print a package result
+  # usage: simplaret_show_package <package-file-name> [-basename-only|-filename-only]
 
-  local name
+  if [ "$2" == "-basename-only" ]; then
+    echo `basename $1`
+  elif [ "$2" == "-filename-only" ]; then
+    echo $1
+  else 
+    if echo $1 | grep -q "/patches/"; then
+      patch="(patch)"
+    fi
+    if [ "$repos_type" == "noarch" ]; then
+      echo $name repository $repository_name: `basename $1` $patch
+    else
+      echo $name repository $repository_name, arch: $ARCH, version: $VERSION: `basename $1` $patch
+    fi
+  fi
+  unset patch name
+
+}
+
+function simplaret_search {
+
+  local priority
 
   for repos_type in patches root repos noarch; do
 
@@ -241,21 +271,20 @@ function simplaret_search {
           echo please do a simplaret --update
         fi
       else
-        for file in `grep $1 $storage/$repository_name/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do
-          if echo $file | grep -q "/patches/"; then
-            patch="(patch)"
-          fi
-          if [ "$2" == "-silent" ]; then
-            echo `basename $file`
-          else 
-            if [ "$repos_type" == "noarch" ]; then
-              echo $name repository $repository_name: `basename $file` $patch
-            else
-              echo $name repository $repository_name, arch: $ARCH, version: $VERSION: `basename $file` $patch
-            fi
-          fi
-          unset patch
-        done
+
+        if [ "$repost_type" == "root" ]; then
+          # root repositories has ROOT_PRIORITY
+          for priority in $ROOT_PRIORITY; do
+            for file in `simplaret_find_package $1 $storage/$repository_name | grep "/$priority/"`; do
+              simplaret_show_package $file $2
+            done
+          done
+        else
+          for file in `simplaret_find_package $1 $storage/$repository_name`; do
+            simplaret_show_package $file $2
+          done
+        fi
+
       fi
 
     done
@@ -265,35 +294,44 @@ function simplaret_search {
 
 function simplaret_purge {
 
-  # TODO: new repo format
+  local mtime mtime_message
 
   if [ "$2" == "-w" ] && [ ! -z "$3" ]; then
-    if [ -z "$SILENT" ]; then
-      echo purging all packages older than $3 weeks for arch $ARCH and version $VERSION
-    fi
-    mtime="`echo "$3*7" | bc -l`"
-    for file in `find $STORAGE/$ARCH/$VERSION/ -mtime +$mtime`; do
-      for extension in tgz asc meta; do
-        if echo $file | grep -qe ".$extension$"; then
-          rm $file
-        fi
-       done
-    done
+    mtime="-mtime +`echo "$3*7" | bc -l`"
+    mtime_message="older than $3 weeks"
   else
-    if [ -z "$SILENT" ]; then
-      echo purging all packages for arch $ARCH and version $VERSION
+    mtime=""
+    mtime_mesage=""
+  fi
+
+  if [ -z "$SILENT" ]; then
+    echo purging all packages $mtime_message for:
+    echo - arch $ARCH and version $VERSION, including patches
+    echo - noarch folder
+  fi
+
+  for repos_type in patches root repos noarch; do
+
+    storage="$STORAGE/$ARCH/$VERSION/$repos_type"
+    if [ "$repos_type" == "noarch" ]; then
+      storage="$STORAGE/noarch"
+    elif [ "$repos_type" == "patches" ]; then
+      storage="$PATCHES_DIR/$ARCH/$VERSION"
     fi
-    for file in `find $STORAGE/$ARCH/$VERSION/ 2> /dev/null`; do
-      for extension in tgz asc; do
+
+    for file in `find $storage/ $mtime 2> /dev/null`; do
+      for extension in tgz asc meta; do
         if echo $file | grep -qe ".$extension$"; then
           rm $file
         fi
       done
     done
-  fi
+
+  done
 
   if [ -z "$SILENT" ]; then
-    echo done purging simplaret cache, please run simplaret --update to retrieve new package listings on this arch and version
+    echo done purging simplaret cache
+    echo please run simplaret --update to retrieve new package listings on this arch and version
   fi
 
 }
@@ -302,6 +340,8 @@ function simplaret_get {
 
   # TODO: with no parameters, update the existing packages at the local repo?
   #       support to --get package-version-arch-build.tgz or just half the name
+  #       precedence: patches slackware repos noarch
+  #       ROOT_PRIORITY
   #       etc
 
   # search for an already downloaded package
@@ -309,7 +349,7 @@ function simplaret_get {
     candidate="`basename $file`"
     if [ "`package_name $candidate`" == "$1" ]; then
       # check if has the same version and build number, otherwise erase the old one
-      for result in `simplaret_search `basename $file tgz` -silent`; do
+      for result in `simplaret_search `basename $file tgz` -basename-only`; do
         if [ "`package_name $candidate`" == "`package_name $result`" ] &&       \
            [ "`package_version $candidate`" == "`package_version $result`" ] && \
            [ "`package_build $candidate`" == "`package_build $result`" ]; then
@@ -328,7 +368,7 @@ function simplaret_get {
       echo warning: no file list for root repository on arch $ARCH version $VERSION, please do a simplaret --update
     fi
   else
-    for file in `grep $1 $STORAGE/$ARCH/$VERSION/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do
+    for file in `simplaret_find_package $1 $STORAGE/$ARCH/$VERSION`; do
       candidate="`basename $file`"
       if [ "`package_name $candidate`" == "$1" ]; then
         simplaret_root_url
@@ -354,7 +394,7 @@ function simplaret_get {
         echo warning: no file list for $repos_name repository on arch $ARCH version $VERSION, please do a simplaret --update
       fi
     else
-      for file in `grep $1 $STORAGE/$ARCH/$VERSION/$repos_name/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do
+      for file in `simplare_find_package $1 $STORAGE/$ARCH/$VERSION/$repos_name`; do
         candidate="`basename $file`"
         if [ "`package_name $candidate`" == "$1" ]; then
           simplaret_download $repos_url $file $STORAGE/$ARCH/$VERSION/$repos_name
@@ -375,6 +415,8 @@ function simplaret_get {
 
 function simplaret_get_patches {
 
+  # TODO: new format
+
   if [ ! -d "$PATCHES_DIR/$ARCH/$VERSION" ]; then
     mkdir -p $PATCHES_DIR/$ARCH/$VERSION
   fi
@@ -392,7 +434,7 @@ function simplaret_get_patches {
   done
 
   # grab new patches
-  for patch in `simplaret_search patches -silent`; do
+  for patch in `simplaret_search patches -basename_only`; do
     simplaret --get `package_name $patch`
     file="`find $STORAGE/$ARCH/$VERSION/ | grep "$patch" 2> /dev/null`"
     if [ ! -f "$file" ]; then