swarmlib/hive.py
author Sam Hart <criswellious@gmail.com>
Sun Apr 06 22:40:23 2008 -0400 (4 years ago)
changeset 267 f6e82d635465
parent 2648505e3c3428e
child 2686ceb8700106f
permissions -rw-r--r--
Make BaseScheme logger name determined by self.scheme_name, remove unneeded __init__ rewrite in local, and change Hive.init to match current documentation
     1 # Copyright 2007 Sam Hart
     2 #
     3 # This program is free software; you can redistribute it and/or modify
     4 # it under the terms of the GNU General Public License as published by
     5 # the Free Software Foundation; either version 2 of the License, or
     6 # (at your option) any later version.
     7 #
     8 # This program is distributed in the hope that it will be useful,
     9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11 # GNU General Public License for more details.
    12 #
    13 # You should have received a copy of the GNU General Public License
    14 # along with this program; if not, write to the Free Software
    15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    16 #
    17 # Author: Sam Hart
    18 
    19 """
    20 The Swarm Hive "super" class
    21 
    22 This class houses the most common Swarm Hive interactions.
    23 """
    24 
    25 import urlparse
    26 
    27 class Hive(object):
    28     def __init__(self, url, log, Force=False, config=None):
    29         """
    30         Basic URL parsing wrapper class
    31         Accessable members:
    32          .scheme = The scheme in use
    33          .netloc = The network location
    34          .path = The path
    35          .params = Parameters for path element
    36          .query = Query component
    37          .fragment = fragment identifier
    38          .username = username to use (if authentication is needed)
    39          .password = password to use (if authentication is needed)
    40          .hostname = hostname
    41          .port = port
    42         """
    43         self.url = url
    44         self._parsed = urlparse(url)
    45         self.scheme = self._parsed.scheme.lower()
    46         self.netloc = self._parsed.netloc
    47         self.path = self._parsed.path
    48         self.params = self._parsed.params
    49         self.query = self._parsed.query
    50         self.fragment = self._parsed.fragment
    51         self.username = self._parsed.username
    52         self.password = self._parsed.password
    53         self.hostname = self._parsed.hostname
    54         self.port = self._parsed.port
    55         self.connected = False
    56         self.connection = None
    57         self._log = log
    58         self._alt_config_file = config
    59         self.config = None
    60         self.force = force
    61         self._logger = log.get_logger("Hive")
    62 
    63     def init_hive(self, force=False, ):
    64         """
    65         Called when a new Hive is to be initialized
    66         """
    67 
    68     def connect(self):
    69         """
    70         Connects to the Hive.
    71 
    72         Returns nothing on success, otherwise raises an exception.
    73         """
    74         try:
    75             self.connection = connect.get_connection(self._parsed, self._log,
    76                                                      self.force)
    77         except:
    78             pass
    79 
    80         self.config = self.connection.get_config()
    81 
    82         self.connected = True