Added src/ego
authorkarltk <karltk@gentoo.org>
Sat, 10 Jan 2004 01:43:32 +0000 (01:43 -0000)
committerkarltk <karltk@gentoo.org>
Sat, 10 Jan 2004 01:43:32 +0000 (01:43 -0000)
svn path=/; revision=61

trunk/ChangeLog
trunk/src/ego/AUTHOR [new file with mode: 0644]
trunk/src/ego/ChangeLog [new file with mode: 0644]
trunk/src/ego/README [new file with mode: 0644]
trunk/src/ego/TODO [new file with mode: 0644]
trunk/src/ego/ego [new file with mode: 0644]

index f7f6149a8e0770f73fda62fbed25921c4f368e45..f353b686e5071f7af0bcc8b0bb4dec852b03edce 100644 (file)
@@ -1,5 +1,7 @@
+2004-01-10 Karl Trygve Kalleberg <karltk@gentoo.org>
+       * Added src/ego
 
-2003-01-07 Karl Trygve Kalleberg <karltk@gentoo.org>
+2004-01-07 Karl Trygve Kalleberg <karltk@gentoo.org>
        * Added new build system
        * Added src/old-scripts, the scripts from app-portage/gentoolkit
        * Renamed gentool to equery
diff --git a/trunk/src/ego/AUTHOR b/trunk/src/ego/AUTHOR
new file mode 100644 (file)
index 0000000..36d5bfd
--- /dev/null
@@ -0,0 +1 @@
+Aron Griffis <agriffis@gentoo.org>
diff --git a/trunk/src/ego/ChangeLog b/trunk/src/ego/ChangeLog
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/trunk/src/ego/README b/trunk/src/ego/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/trunk/src/ego/TODO b/trunk/src/ego/TODO
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/trunk/src/ego/ego b/trunk/src/ego/ego
new file mode 100644 (file)
index 0000000..f1691f2
--- /dev/null
@@ -0,0 +1,86 @@
+echo1() { 
+  echo "$1"
+}
+
+ego() {
+  local portdir tmpdir category pkg target
+  
+  # This is WAY faster than portageq:
+  #   portdir=$(portageq portdir)
+  #   tmpdir=$(portageq envvar PORTAGE_TMPDIR)/portage
+  eval $(
+    . /etc/make.globals 
+    . /etc/make.conf
+    export PORTDIR PORTAGE_TMPDIR
+    export | sed -n '
+      s/^declare -x PORTDIR=/portdir=/p
+      s/^declare -x PORTAGE_TMPDIR=\(.*\)/tmpdir=\1\/portage/p'
+  )
+
+  case $1 in
+    *-*/*)
+      pkg=${1##*/}
+      category=${1%/*} 
+      ;;
+
+    ?*)    
+      pkg=$1 
+      # require an ebuild so that we can block deprecated packages
+      # such as dev-libs/rep-gtk
+      category=$(echo1 $portdir/*-*/$pkg/*.ebuild)
+      [[ -f $category ]] || category=$(echo1 $portdir/*-*/$pkg*/*.ebuild)
+      [[ -f $category ]] || category=$(echo1 $portdir/*-*/*$pkg/*.ebuild)
+      [[ -f $category ]] || category=$(echo1 $portdir/*-*/*$pkg*/*.ebuild)
+      if [[ ! -f $category ]]; then
+       echo "Can't find $pkg in $portdir" >&2
+       return 1
+      fi
+      pkg=${category%/*}
+      pkg=${pkg##*/}
+      category=${category#$portdir/}
+      category=${category%%/*}
+      ;;
+
+    *)
+      # Check if we're under $portdir first
+      pkg=${PWD##*/}
+      category=${PWD%/*}
+      category=${category##*/}
+      if [[ ! -d $portdir/$category/$pkg ]]; then
+       # Next check if we're in PORTAGE_TMPDIR
+       if [[ $PWD = $tmpdir/* ]]; then
+         pkg=${PWD#$tmpdir/}
+         pkg=${pkg%%/*}
+         pkg=${pkg%%-[0-9]*}  # not really a valid assumption
+         category=$(echo1 $portdir/*-*/$pkg/*.ebuild)
+         if [[ ! -f $category ]]; then
+           echo "Can't find $pkg in $portdir" >&2
+           return 1
+         fi
+         category=${category#$portdir/}
+         category=${category%%/*}
+       else
+         echo "syntax: ego [pkgname]" >&2
+         echo "or simply ego from a dir under $portdir or $tmpdir" >&2
+         return 1
+       fi
+      fi
+      ;;
+  esac
+
+  # go to tmpdir or portdir?
+  if [[ $PWD/ = */$category/$pkg/* ]]; then
+    [[ -n $tmpdir ]] || tmpdir=$(portageq envvar PORTAGE_TMPDIR)/portage
+    target=$(command ls -1td $tmpdir/$pkg-* 2>/dev/null | head -n 1)
+    if [[ -z $target ]]; then
+      echo "No matches found for $tmpdir/$pkg-*" >&2
+      return 1
+    fi
+    cd $target/work/$pkg* 2>/dev/null ||
+    cd $target/work 2>/dev/null ||
+    cd $target
+  else
+    cd $portdir/$category/$pkg
+  fi
+}
+