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