public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/overlord:master commit in: overlord/
@ 2011-02-07  3:10 Brian Dolbec
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2011-02-07  3:10 UTC (permalink / raw
  To: gentoo-commits

commit:     50fc5d0e88f000b775d2e67c24d5d6728833fdbc
Author:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sun Feb  6 23:34:36 2011 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Feb  6 23:34:36 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/overlord.git;a=commit;h=50fc5d0e

add the ability to plugin repository definition xml files without editing the config file

---
 overlord/config.py |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/overlord/config.py b/overlord/config.py
index 4caf83c..884fc58 100644
--- a/overlord/config.py
+++ b/overlord/config.py
@@ -28,6 +28,7 @@ __version__ = "$Id: config.py 286 2007-01-09 17:48:23Z wrobel $"
 #-------------------------------------------------------------------------------
 
 import sys, ConfigParser
+import os
 
 from   optparse                 import OptionParser, OptionGroup
 from   overlord.debug             import OUT
@@ -44,6 +45,28 @@ _USAGE = """
   overlord -f [-o URL]
   overlord (-l|-L|-S)"""
 
+
+def read_config(config=None, defaults=None):
+    """reads the config file defined in defaults['config']
+    and updates the config
+
+    @param config: ConfigParser.ConfigParser(self.defaults) instance
+    @param defaults: dict
+    @modifies config['MAIN']['overlays']
+    """
+    config.read(defaults['config'])
+    if config.get('MAIN', 'overlay_defs'):
+        filelist = os.listdir(config.get('MAIN', 'overlay_defs'))
+        filelist = [f for f in filelist if f.endswith('.xml')]
+        overlays = set(config.get('MAIN', 'overlays').split('\n'))
+        for _file in filelist:
+            path = os.path.join(config.get('MAIN', 'overlay_defs'), _file)
+            if os.path.isfile(path):
+                overlays.update(["file://" + path])
+        config.set('MAIN', 'overlays', '\n'.join(overlays))
+
+
+
 class BareConfig(object):
     '''Handles the configuration only.'''
 
@@ -68,7 +91,8 @@ class BareConfig(object):
                     'nocheck'   : 'yes',
                     'proxy'     : '',
                     'umask'     : '0022',
-                    'overlays'  :
+                    'overlays'  : '',
+                    'overlay_defs': '/etc/overlord/overlays'
                     'http://www.gentoo.org/proj/en/overlays/repositories.xml',
                     'bzr_command': '/usr/bin/bzr',
                     'cvs_command': '/usr/bin/cvs',
@@ -318,7 +342,7 @@ class ArgsParser(object):
         #-----------------------------------------------------------------
         # Debug Options
 
-        self.output.cli_opts(self.parser)
+        #self.output.cli_opts(self.parser)
 
         # Parse the command line first since we need to get the config
         # file option.
@@ -333,7 +357,7 @@ class ArgsParser(object):
                 % ', '.join(('"%s"' % e) for e in remain_args[1:]))
 
         # handle debugging
-        self.output.cli_handle(self.options)
+        #self.output.cli_handle(self.options)
 
         # add output to the options
         self.options.__dict__['output'] = self.output
@@ -351,7 +375,7 @@ class ArgsParser(object):
         if not self.options.__dict__['config'] is None:
             self.defaults['config'] = self.options.__dict__['config']
 
-            self.output.debug('Got config file at ' + self.defaults['config'], 8)
+            #self.output.debug('Got config file at ' + self.defaults['config'], 8)
 
         # Now parse the config file
         self.config = ConfigParser.ConfigParser(self.defaults)
@@ -366,9 +390,9 @@ class ArgsParser(object):
             self.output.set_info_level(int(self['quietness']))
             self.output.set_warn_level(int(self['quietness']))
 
-        self.output.debug('Reading config file at ' + self.defaults['config'], 8)
+        #self.output.debug('Reading config file at ' + self.defaults['config'], 8)
 
-        self.config.read(self.defaults['config'])
+        read_config(self.config, self.defaults)
 
     def __getitem__(self, key):
 
@@ -407,6 +431,7 @@ class ArgsParser(object):
 
         return None
 
+
     def keys(self):
         '''Special handler for the configuration keys.'''
 



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/overlord:master commit in: overlord/
@ 2011-02-07  3:10 Brian Dolbec
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2011-02-07  3:10 UTC (permalink / raw
  To: gentoo-commits

commit:     7d079e5058a83b809814a6585cf6bb876955c5f5
Author:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sun Feb  6 23:37:58 2011 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Feb  6 23:37:58 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/overlord.git;a=commit;h=7d079e50

fix the incorrect command

---
 overlord/db.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/overlord/db.py b/overlord/db.py
index d54efa5..a65fe8c 100644
--- a/overlord/db.py
+++ b/overlord/db.py
@@ -247,7 +247,7 @@ class RemoteDB(DbBase):
 
     # overrider
     def _broken_catalog_hint(self):
-        return 'Try running "sudo overlord -f" to re-fetch that file'
+        return 'Try running "sudo lord -f" to re-fetch that file'
 
     def cache(self):
         '''



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/overlord:master commit in: overlord/
@ 2011-02-07  3:10 Brian Dolbec
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2011-02-07  3:10 UTC (permalink / raw
  To: gentoo-commits

commit:     c2778e03b73bde4cbc3e1de60872fb02560192b6
Author:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sun Feb  6 23:38:49 2011 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Feb  6 23:38:49 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/overlord.git;a=commit;h=c2778e03

new simplified message class

---
 overlord/output.py |  183 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 183 insertions(+), 0 deletions(-)

diff --git a/overlord/output.py b/overlord/output.py
new file mode 100644
index 0000000..80a1ca0
--- /dev/null
+++ b/overlord/output.py
@@ -0,0 +1,183 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+""" Copyright 2005 - 2008 Gunnar Wrobel
+              2011 - Brian Dolbec
+ Distributed under the terms of the GNU General Public License v2
+"""
+
+
+__version__ = "0.1"
+
+
+import sys, inspect, types
+
+from   optparse      import OptionGroup
+
+from   overlord.constants  import codes
+
+
+
+class Message:
+    #FIXME: Think about some simple doctests before you modify this class the
+    #       next time.
+
+    def __init__(self,
+                 out = sys.stdout,
+                 err = sys.stderr,
+                 info_level = 4,
+                 warn_level = 4,
+                 col = True
+                 ):
+
+        # Where should the error output go? This can also be a file
+        self.error_out = err
+
+        # Where should the normal output go? This can also be a file
+        self.std_out = out
+
+        # The higher the level the more information you will get
+        self.warn_lev = warn_level
+
+        # The higher the level the more information you will get
+        self.info_lev = info_level
+
+        # Should the output be colored?
+        self.set_colorize(col)
+
+        self.has_error = False
+
+
+    def color (self, col, text):
+        return codes[col] + text + codes['reset']
+
+
+    def no_color (self, col, text):
+        return text
+
+
+    def set_colorize(self, state):
+        if state:
+            self.color_func = self.color
+        else:
+            self.color_func = self.no_color
+
+
+    def set_info_level(self, info_level = 4):
+        self.info_lev = info_level
+
+
+    def info_off(self):
+        self.set_info_level(0)
+
+
+    def info_on(self, info_level = 4):
+        self.set_info_level(info_level)
+
+
+    def set_warn_level(self, warn_level = 4):
+        self.warn_lev = warn_level
+
+
+    def warn_off(self):
+        self.set_warn_level(0)
+
+
+    def warn_on(self, warn_level = 4):
+        self.set_warn_level(warn_level)
+
+
+
+
+    ## Output Functions
+
+    def notice (self, note):
+        print >> self.std_out, note
+
+
+    def info (self, info, level = 4):
+
+        #print "info =", info
+
+        if type(info) not in types.StringTypes:
+            info = str(info)
+
+        if level > self.info_lev:
+            return
+
+        for i in info.split('\n'):
+            print  >> self.std_out, self.set_colorize('green', '* ') + i
+
+
+    def status (self, message, status, info = 'ignored'):
+
+        if type(message) not in types.StringTypes:
+            message = str(message)
+
+        lines = message.split('\n')
+
+        if not lines:
+            return
+
+        for i in lines[0:-1]:
+            print  >> self.std_out, self.set_colorize('green', '* ') + i
+
+        i = lines[-1]
+
+        if len(i) > 58:
+            i = i[0:57]
+
+        if status == 1:
+            result = '[' + self.set_colorize('green', 'ok') + ']'
+        elif status == 0:
+            result = '[' + self.set_colorize('red', 'failed') + ']'
+        else:
+            result = '[' + self.set_colorize('yellow', info) + ']'
+
+        print  >> self.std_out, self.set_colorize('green', '* ') + i + ' ' + \
+            '.' * (58 - len(i)) + ' ' + result
+
+
+    def warn (self, warn, level = 4):
+
+        #print "DEBUG.warn()"
+
+        if type(warn) not in types.StringTypes:
+            warn = str(warn)
+
+        if level > self.warn_lev:
+            return
+
+        for i in warn.split('\n'):
+            print  >> self.std_out, self.set_colorize('yellow', '* ') + i
+
+
+    def error (self, error):
+
+        if type(error) not in types.StringTypes:
+            error = str(error)
+
+        for i in error.split('\n'):
+            # NOTE: Forced flushing ensures that stdout and stderr
+            # stay in nice order.  This is a workaround for calls like
+            # "overlord -L |& less".
+            sys.stdout.flush()
+            print >> self.error_out, self.set_colorize('red', '* ') + i
+            self.error_out.flush()
+        self.has_error = True
+
+
+    def die (self, error):
+
+        if type(error) not in types.StringTypes:
+            error = str(error)
+
+        for i in error.split('\n'):
+            self.error(self.set_colorize('red', 'Fatal error: ') + i)
+        self.error(self.set_colorize('red', 'Fatal error(s) - aborting'))
+        sys.exit(1)
+
+
+
+## gloabal message handler
+OUT = Message()



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/overlord:master commit in: overlord/
@ 2011-02-07  3:10 Brian Dolbec
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Dolbec @ 2011-02-07  3:10 UTC (permalink / raw
  To: gentoo-commits

commit:     5d8d00d735d80308d3a2b973ee5de80dcb78c84e
Author:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sun Feb  6 23:40:15 2011 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Feb  6 23:40:15 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/overlord.git;a=commit;h=5d8d00d7

use the new message class and fix the error recording and output

---
 overlord/api.py |   43 +++++++++++++++++++++----------------------
 overlord/cli.py |    3 ++-
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/overlord/api.py b/overlord/api.py
index 0fe9362..4aee39e 100644
--- a/overlord/api.py
+++ b/overlord/api.py
@@ -20,10 +20,11 @@ import os
 from overlord.config import BareConfig
 #from overlord.action import Sync
 
-from overlord.dbbase import UnknownOverlayException
+from overlord.dbbase import UnknownOverlayException, UnknownOverlayMessage
 from overlord.db import DB, RemoteDB
 #from overlord.utils import path, delete_empty_directory
-from overlord.debug import OUT
+#from overlord.debug import OUT
+from overlord.output import OUT
 
 # give them some values for now, these are from the packagekit backend
 # TODO  establish some proper errors for the api.
@@ -114,11 +115,7 @@ class OverlordAPI(object):
         for ovl in repos:
             if not self.is_installed(ovl):
                 results.append(True)
-                break
-            if not self.is_repo(ovl):
-                self._error(1, UNKNOWN_REPO_ID %ovl)
-                results.append(False)
-                break
+                continue
             try:
                 self._get_installed_db().delete(self._get_installed_db().select(ovl))
                 results.append(True)
@@ -145,11 +142,11 @@ class OverlordAPI(object):
         for ovl in repos:
             if self.is_installed(ovl):
                 results.append(True)
-                break
+                continue
             if not self.is_repo(ovl):
-                self._error(1, UNKNOWN_REPO_ID %ovl)
+                self._error(UnknownOverlayMessage(ovl))
                 results.append(False)
-                break
+                continue
             try:
                 self._get_installed_db().add(self._get_remote_db().select(ovl), quiet=True)
                 results.append(True)
@@ -199,12 +196,13 @@ class OverlordAPI(object):
 
         for ovl in repos:
             if not self.is_repo(ovl):
-                self._error(1, UNKNOWN_REPO_ID %ovl)
+                self._error(UnknownOverlayMessage(ovl))
                 result[ovl] = ('', False, False)
+                continue
             try:
                 overlay = db.select(ovl)
             except UnknownOverlayException, error:
-                self._error(2, "Error: %s" %str(error))
+                self._error(error)
                 result[ovl] = ('', False, False)
             else:
                 result[ovl] = {
@@ -247,20 +245,21 @@ class OverlordAPI(object):
 
         for ovl in repos:
             if not self.is_repo(ovl):
-                self._error(1, UNKNOWN_REPO_ID % ovl)
+                self._error(UnknownOverlayMessage(ovl))
                 result[ovl] = ('', False, False)
+                continue
             try:
                 overlay = db.select(ovl)
                 #print "overlay = ", ovl
-                #print overlay
+                #print "!!!", overlay
             except UnknownOverlayException, error:
                 #print "ERRORS", str(error)
-                self._error(2, "Error: %s" %str(error))
+                self._error(error)
                 result[ovl] = ('', False, False)
             else:
                 # Is the overlay supported?
                 if verbose:
-                    info = overlay.__str__()
+                    info = overlay.get_infostr()
                 else:
                     info = overlay.short_list(width)
                 official = overlay.is_official()
@@ -271,7 +270,7 @@ class OverlordAPI(object):
 
     def get_info_list(self, local=True, verbose=False, width=0):
         """retrieves the string representation of the recorded information
-        about the repo(s) specified by ovl
+        about the repo(s)
 
         @param local: bool (defaults to True)
         @param verbose: bool(defaults to False)
@@ -303,7 +302,7 @@ class OverlordAPI(object):
             try:
                 odb = db.select(ovl)
             except UnknownOverlayException, error:
-                self._error(1,"Sync(), failed to select %s overlay.  Original error was: %s" %(ovl, str(error)))
+                self._error(UnknownOverlayException(error))
                 continue
 
             try:
@@ -376,7 +375,7 @@ class OverlordAPI(object):
         try:
             self._get_remote_db().cache()
         except Exception, error:
-            self._error(-1,'Failed to fetch overlay list!\n Original Error was: '
+            self._error('Failed to fetch overlay list!\n Original Error was: '
                     + str(error))
             return False
         self.get_available(reload=True)
@@ -417,13 +416,13 @@ class OverlordAPI(object):
         result = self.get_installed(reload=True)
 
 
-    def _error(self, num, message):
+    def _error(self, message):
         """outputs the error to the pre-determined output
         defaults to stderr.  This method may be removed, is here for now
         due to code taken from the packagekit backend.
         """
-        msg = "Error: %d," % num, message
-        self._error_messages.append(msg)
+        #msg = "Error: %d," % num, message
+        self._error_messages.append(message)
         if self.report_errors:
             print >>stderr, msg
 

diff --git a/overlord/cli.py b/overlord/cli.py
index 501dd65..0953de1 100644
--- a/overlord/cli.py
+++ b/overlord/cli.py
@@ -171,7 +171,8 @@ class Main(object):
                 try:
                     result += getattr(self, action[1])()
                 except Exception, error:
-                    self.output.error(self.api.get_errors())
+                    for _error in self.api.get_errors():
+                        self.output.error(_error)
                     result = -1  # So it cannot remain 0, i.e. success
                     break
 



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-07  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-07  3:10 [gentoo-commits] proj/overlord:master commit in: overlord/ Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2011-02-07  3:10 Brian Dolbec
2011-02-07  3:10 Brian Dolbec
2011-02-07  3:10 Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox