aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-07-20 23:44:40 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-07-20 23:44:40 -0300
commit37c44c8ca04fa447ca5a6a97dc2533106612b27d (patch)
tree2ab7169c433969930bfc754830fcbb6804929399
parentadded a test to verify if the selected package manager is currently (diff)
downloadg-octave-37c44c8ca04fa447ca5a6a97dc2533106612b27d.tar.gz
g-octave-37c44c8ca04fa447ca5a6a97dc2533106612b27d.tar.bz2
g-octave-37c44c8ca04fa447ca5a6a97dc2533106612b27d.zip
added the search of packages
-rw-r--r--README.rst3
-rw-r--r--docs/userguide.rst13
-rw-r--r--g-octave.1.rst1
-rw-r--r--g_octave/description_tree.py27
-rwxr-xr-xscripts/g-octave34
5 files changed, 77 insertions, 1 deletions
diff --git a/README.rst b/README.rst
index f2a855c..16067a5 100644
--- a/README.rst
+++ b/README.rst
@@ -133,6 +133,9 @@ CLI options
*-u, --update*
try to update a package or all the installed packages
+*-s, --search*
+ search for packages with some term on the name (regular expressions allowed)
+
*-C, --unmerge*
try to unmerge a package instead of merge
diff --git a/docs/userguide.rst b/docs/userguide.rst
index f97d175..252818b 100644
--- a/docs/userguide.rst
+++ b/docs/userguide.rst
@@ -206,6 +206,19 @@ or ::
The options ``--ask`` and ``--verbose`` are also supported.
+Searching packages
+------------------
+
+You can do searches on the package names if you use the option ``-s`` or
+``--search``. Regular expressions are allowed. ::
+
+ # g-octave --search anything
+
+or ::
+
+ # g-octave -s ^con
+
+
Uninstalling packages
---------------------
diff --git a/g-octave.1.rst b/g-octave.1.rst
index 8029e4c..cfb9fca 100644
--- a/g-octave.1.rst
+++ b/g-octave.1.rst
@@ -45,6 +45,7 @@ OPTIONS
-a, --ask ask to confirmation before perform (un)merges
-v, --verbose Portage makes a lot of noise.
-u, --update try to update a package or all the installed packages
+-s, --search search for packages with some term on the name (regular expressions allowed)
-C, --unmerge try to unmerge a package instead of merge
-f, --force forces the recreation of the ebuilds
--force-all forces the recreation of the overlay and of the ebuilds
diff --git a/g_octave/description_tree.py b/g_octave/description_tree.py
index 4bf789a..3851b18 100644
--- a/g_octave/description_tree.py
+++ b/g_octave/description_tree.py
@@ -17,11 +17,18 @@ from __future__ import absolute_import
__all__ = ['DescriptionTree']
import os
+import re
from .config import Config
from .description import *
from .exception import ConfigException, DescriptionTreeException
+has_svn = True
+try:
+ from .svn import *
+except ImportError:
+ has_svn = False
+
from .log import Log
log = Log('g_octave.description_tree')
@@ -136,3 +143,23 @@ class DescriptionTree(object):
packages.append(pkg['name'] + '-' + pkg['version'])
return packages
+
+
+ def search(self, term):
+
+ # term can be a regular expression
+ re_term = re.compile(r'%s' % term)
+ packages = {}
+
+ for cat in self.pkg_list:
+ for pkg in self.pkg_list[cat]:
+ if re_term.search(pkg['name']) is not None:
+ if pkg['name'] not in packages:
+ packages[pkg['name']] = [pkg['version']]
+ if has_svn:
+ packages[pkg['name']].append('9999')
+ else:
+ packages[pkg['name']].insert(-1, pkg['version'])
+
+ return packages
+
diff --git a/scripts/g-octave b/scripts/g-octave
index 7241431..7d0d782 100755
--- a/scripts/g-octave
+++ b/scripts/g-octave
@@ -111,6 +111,14 @@ def main():
)
parser.add_option(
+ '-s', '--search',
+ action = 'store_true',
+ dest = 'search',
+ default = False,
+ help = 'search for packages with some term on the name (regular expressions allowed)'
+ )
+
+ parser.add_option(
'-C', '--unmerge',
action = 'store_true',
dest = 'unmerge',
@@ -273,7 +281,7 @@ def main():
print('\t%s-%s' % (pkg['name'], pkg['version']))
print()
return os.EX_OK
- if options.update:
+ elif options.update:
pass
elif len(args) == 0:
log.error('You need provide an argument.')
@@ -285,10 +293,34 @@ def main():
return os.EX_USAGE
# if we're alive yet, we have a package to install! :D
+ # or a search to do! :P
create_overlay(options.force_all)
if len(args) > 0:
+
+ if options.search:
+ log.info('Searching for packages: %s' % args[0])
+ tree = DescriptionTree()
+ print(
+ portage.output.blue('Search results for '),
+ portage.output.white(args[0]),
+ portage.output.blue(':\n'),
+ sep = ''
+ )
+ packages = tree.search(args[0])
+ for pkg in packages:
+ print(
+ portage.output.green('Package:'),
+ portage.output.white(pkg)
+ )
+ print(
+ portage.output.green('Available versions:'),
+ portage.output.red(', '.join(packages[pkg]))
+ )
+ print()
+ return os.EX_OK
+
log.info('Processing a package: %s' % args[0])
try:
ebuild = Ebuild(args[0], options.force or options.force_all, pkg_manager=pkg_manager)