Exemplo n.º 1
0
    def __generateCachedLink(self, cacheId, originalLink):
        """
            desc:   generate cached url by config-file's cache_url_pattern
            args:   cacheId - string
                    originalLink - string
            return: generated cached url
        """
        if not cacheId or len(cacheId) is 0:
            raise BaseException, 'cachedId can not be none or empty'

        if not originalLink or len(originalLink) is 0:
            raise BaseException, 'original can not be none or empty'

        cachedLink = cacheId

        matchingDict = dict()
        matchingDict['cacheId'] = cacheId
        matchingDict['originalUrl'] = originalLink

        url_pattern = configManager().getConfigVal('api_request', 'cache_url_pattern')
        matchedList = re.findall(Cache_Url_Reg_PATTERN, url_pattern)
        if url_pattern and matchedList and len(matchedList) != 0:
            cachedLink = url_pattern
            for matchedItem in matchedList:
                tmp_key = matchedItem[1:-1]
                cachedLink = cachedLink.replace(matchedItem, str(matchingDict[tmp_key]))

        return cachedLink
Exemplo n.º 2
0
 def __init__(self):
     configManager = configUtility.configManager()
     self.encoder = 'utf8'
     self.host = configManager.getConfigVal('data_access', 'host')
     portStr = configManager.getConfigVal('data_access', 'port')
     self.user = configManager.getConfigVal('data_access', 'user')
     if portStr:
         self.port = string.atoi(portStr)
     else:
         self.port = 3306
     self.passwd = configManager.getConfigVal('data_access', 'passwd')
     if not self.passwd or len(self.passwd) is 0:
         self.passwd = '123456'
     self.db = configManager.getConfigVal('data_access', 'db')
Exemplo n.º 3
0
    def getPDFOperater(self):
        """
            desc:   get the operator of the pdf
            args:   None
            return: None
        """
        if self.__pdfOperator:
            return self.__pdfOperator
        filePath = configManager().getConfigVal('report', 'pdf_filePath')

        if not filePath or len(filePath) == 0:
            raise BaseException, 'the config-key:pdf_filePath can not be empty'

        fileName = self.__generateFileName()

        if filePath[-1] != '/' and fileName[0] != '/':
            filePath = '%s/' % filePath

        fileFullPath = filePath + '' + fileName
        print(fileFullPath)
        self.__pdfOperator = reportlabLibs.canvas.Canvas(fileFullPath, pagesize=reportlabLibs.A4)
        return self.__pdfOperator
Exemplo n.º 4
0
    def __generateFileName(self):
        """
            desc:   generate pdf's file name by config-file pdf_fileNamePattern
        """
        timePartSet = time.localtime(time.time())
        timeDict = dict()
        timeDict['month'] = timePartSet[1]
        timeDict['day'] = timePartSet[2]
        timeDict['hour'] = timePartSet[3]
        timeDict['minute'] = timePartSet[4]
        timeDict['second'] = timePartSet[5]

        fileName = 'cseResult.pdf'

        fileName_pattern = configManager().getConfigVal('report', 'pdf_fileNamePattern')
        matchedList = re.findall(PDF_FileName_REG_PATTERN, fileName_pattern)
        if matchedList:
            fileName = fileName_pattern
            for matchedItem in matchedList:
                tmp_key = matchedItem[1:-1]
                fileName = fileName.replace(matchedItem, str(timeDict[tmp_key]))

        return fileName
Exemplo n.º 5
0
 def __init__(self):
     self.CSEResultList = []
     self.requestUrl = ""
     self.configManager = configUtility.configManager()
     pass