import logging
import time
-from selenium.firefox.webdriver import WebDriver
+try:
+ from selenium.firefox.webdriver import WebDriver
+except ImportError, e:
+ WebDriver = e # allow some functionality without selenium
+
+def get_logger(verbose=0)
+ verbosities = [ # in order of decreasing severity
+ logging.CRITICAL,
+ logging.ERROR,
+ logging.WARN,
+ logging.INFO,
+ logging.DEBUG,
+ ]
+ logger = logging.getLogger('sitecore')
+ if verbose >= len(verbosities):
+ verbose = -1
+ logger.setLevel(verbosities[verbose])
+ # create console handler and set the same level
+ ch = logging.StreamHandler()
+ ch.setLevel(verbosities[verbose])
+ # create formatter
+ formatter = logging.Formatter(
+ '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+ # add formatter to ch
+ ch.setFormatter(formatter)
+ # add ch to logger
+ logger.addHandler(ch)
+ return logger
class SiteCoreConnection (object):
- def __init__(self, url, verbose):
+ def __init__(self, url, verbose=0):
+ if isinstance(WebDriver, ImportError):
+ raise WebDriver # *now* require sitecore
self.url = url
- self.setup_logger(verbose)
+ self.logger = get_logger(verbose)
self.wait_time = 5
- def setup_logger(self, verbose):
- verbosities = [ # in order of decreasing severity
- logging.CRITICAL,
- logging.ERROR,
- logging.WARN,
- logging.INFO,
- logging.DEBUG,
- ]
- self.logger = logging.getLogger('sitecore')
- if verbose >= len(verbosities):
- verbose = -1
- self.logger.setLevel(verbosities[verbose])
- # create console handler and set the same level
- ch = logging.StreamHandler()
- ch.setLevel(verbosities[verbose])
- # create formatter
- formatter = logging.Formatter(
- '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
- # add formatter to ch
- ch.setFormatter(formatter)
- # add ch to logger
- self.logger.addHandler(ch)
-
def start(self):
'Start a single Firefox instance'
self.logger.info('starting Firefox')