swarmlib/hive.py
author Sam Hart <criswellious@gmail.com>
Sat Apr 05 21:13:51 2008 -0400 (4 years ago)
changeset 263 0e321cc07c49
parent 2629347ae6dab3b
child 2648505e3c3428e
permissions -rw-r--r--
_config should be an alternative config file
     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, 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._logger = log.get_logger("Hive")
    60 
    61     def init(self, force=False, ):
    62         """
    63         Called when a new Hive is to be initialized
    64         """
    65 
    66     def connect(self):
    67         """
    68         Connects to the Hive.
    69 
    70         Returns nothing on success, otherwise raises an exception.
    71         """
    72         try:
    73             self.connection = connect.get_connection(self._parsed, self._log)
    74         except:
    75             pass
    76 
    77         self.connected = True