Subversion Repositories SmartDukaan

Rev

Rev 19686 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 25-Oct-2011

@author: Chandranshu
'''
import logging
import subprocess

from shop2020.config.client.ConfigClient import ConfigClient
from shop2020.thriftpy.content.ttypes import ContentServiceException, BulkContentUploadResult
from shop2020.utils import ContentUploadUtil
logging.basicConfig(level=logging.DEBUG)

class ContentHandler:
    '''
    classdocs
    '''
    
    def __init__(self):
        try:
            config_client = ConfigClient()
            self.scriptPath = config_client.get_property('PUSH_PRICES_TO_PROD_SCRIPT_PATH')
        except:
            logging.error("Error while connecting to the config server")
            self.scriptPath = "/root/code/trunk/runutils/push-content-to-production.sh"
    
    def pushContentToProduction(self, entityId):
        """
        Push the content of one entity to production
        Parameters:
         - entityId
        """
        retval = False
        if retval:
            raise ContentServiceException(id=1, message="Pushing content to production failed")
        return True
    
    def uploadContent(self,bulkContentList):
        notUpdated = []
        for bulkContentUpload in bulkContentList:
            result = ContentUploadUtil.migrate_content(bulkContentUpload)
            try:
                if not result['updatedExisting'] or result['n']==0:
                    obj = BulkContentUploadResult()
                    obj.entity_id = bulkContentUpload.new_entity_id
                    obj.message = "Not updated, probably due to error in cloning"
                    notUpdated.append(obj)
            except:
                obj = BulkContentUploadResult()
                obj.entity_id = bulkContentUpload.new_entity_id
                obj.message = "Not updated, probably due to error in cloning"
                notUpdated.append(obj)
        return notUpdated
    
    def close_session(self):
        pass
    
    def isAlive(self, ):
        """
        For checking weather service is active alive or not. It also checks connectivity with database
        """
        try:
            return True
        except:
            return False
        finally:
            self.close_session()