Package tlib :: Package base :: Module SearchEngineLoader |
[hide private]
[frames] | no frames]

# Source Code for Module tlib.base.SearchEngineLoader

     1  from fabric.state import env
     2  from fabric.operations import run, put
     3
     4
     5 -class SearchEngineLoader(object):
     6
     7 -    class OperationError(Exception):
     8          pass
     9
    10 -    def __init__(self, host, username, key):
    11          """
    12          Created an instance of this object
    13          @param host: IP address of host of server to connect
    14          @type host: str
    15          @param username: Username used to connect
    16          @type username: str
    17          @param key: Path to the ssh key used for authentication
    18          @type key: str
    19          """
    20          super(SearchEngineLoader, self).__init__()
    21          env.host_string = host
    22          env.user = username
    23          env.key_filename = key
    24
    25          # Dont' exit app when there is an error
    26          def raise_error(msg):
    27              raise self.OperationError(msg)
    28
    29          env.abort_exception = lambda msg: raise_error(msg)
    30
    31 -    def load_xmlgen(self, xmlfile, logger):
    32          """
    33          Loads a xmlgen file to the server and starts a re-index of the search engine
    34          @param xmlfile: XML text to load on the search engine
    35          @type xmlfile: str
    36          """
    37          try:
    38              env.shell_env = {"PROJECT_DIR": '/mnt/solr/indexer',
    39                               "DATA_DIR": "/mnt/solr/datafeed"}
    40
    41              # Upload xmlgen file
    42              logger.debug("Uploading file %s" % xmlfile)
    43              put(xmlfile,
    44                  r"/mnt/solr/datafeed/MainSystem/ypse.ypca.140218.2252.0.xml")
    45
    46              #Start re-index
    47              logger.debug("Start re-index of search engine")
    48              run('${PROJECT_DIR}/bin/execute_merchant.sh ${PROJECT_DIR} ${DATA_DIR}', shell=True)
    49          except Exception as e:
    50              logger.error("Error uploading xmlgen file:\\n%s" % e.message)
    51              raise e
    52