Exemplo n.º 1
0
 def rollback_transation(self):
     try:
         self.__dbConnection.rollback()
          
     except psycopg2.Error as e:
         raise ASFBugScraperError("Erro ao realizar o rollback da transição: Error code {0}. Descrição do erro: {1}".format(e.pgcode, e.pgerror)) 
     except Exception as ex:
         raise ASFBugScraperError("Erro desconhecido. Destalhes: {0}".format(ex.message))
Exemplo n.º 2
0
 def get_cursor(self):
     try:
         return_cursor = self.__dbConnection.cursor()
     except psycopg2.Error as e:
         raise ASFBugScraperError("Erro ao obter um cursor do banco: Error code {0}. Descrição do erro: {1}".format(e.pgcode, e.pgerror))
     except Exception as ex:
         raise ASFBugScraperError("Erro desconhecido. Destalhes: {0}".format(ex.message))
     return return_cursor
Exemplo n.º 3
0
 def close_cursor(self, a_cursor):
     try:
         a_cursor.close()
     except psycopg2.Error as e:
         raise ASFBugScraperError("Erro ao fechar um cursor do banco: Error code {0}. Descrição do erro: {1}".format(e.pgcode, e.pgerror))   
     except Exception as ex:
         raise ASFBugScraperError("Erro desconhecido. Destalhes: {0}".format(ex.message))
             
Exemplo n.º 4
0
 def connect(self):
     
     try:
         if( not self.__connected):
             self.__dbConnection = psycopg2.connect(database=self.__DATABASE, user=self.__USER, password=self.__PASSWORD, host=self.__HOST, port=self.__PORT)
             self.__connected = True
     except psycopg2.Error as e:
         raise ASFBugScraperError("Erro ao conectar o banco de dados: Error code {0}. Descrição do erro: {1}".format(e.pgcode, e.pgerror))
     except Exception as ex:
         raise ASFBugScraperError("Erro desconhecido. Destalhes: {0}".format(ex.message))
Exemplo n.º 5
0
 def close_connection(self):
     
     if self.__dbConnection == None:
         raise ASFBugScraperError("Erro ao fechar a conexão. Conexão não estabelecida")
     try:
         self.__dbConnection.close()
     except psycopg2.Error as e:
         raise ASFBugScraperError("Erro ao fechar a conexão com o banco de dados: Error code {0}. Descrição do erro: {1}".format(e.pgcode, e.pgerror))
     except Exception as ex:
         raise ASFBugScraperError("Erro desconhecido. Destalhes: {0}".format(ex.message))
Exemplo n.º 6
0
 def __init__(self):
     '''
     Constructor
     '''
     try:
         __dbConnection = None
         __connected = False
         
     except Exception as e:
         raise ASFBugScraperError("Erro no construtor da classe. Detalhes: {0}".format(e.message))
Exemplo n.º 7
0
    def __connect(self, url):

        tentativas = 0

        while tentativas < self.__MAX_TENTIVAS:
            try:
                asfResponse = requests.get(url)
                break
            except ConnectionError as e:
                print('Ocorreu um erro de conexão. Detalhes: {0}'.format(e))
                tentativas = tentativas + 1
            except HTTPError as e:
                print('Ocorreu um erro de HTTP. Detalhes: {0}'.format(e))
                tentativas = tentativas + 1
            except URLRequired as e:
                print('A URL informada {0} não é válida. Detalhes: {1}'.format(
                    url, e))
                tentativas = tentativas + 1
            except Timeout as e:
                print('Timeout da conexão. Detalhes: {0}'.format(e))
                tentativas = tentativas + 1
            except RequestException as e:
                print(
                    'There was an ambiguous exception that occurred while handling your request.Vide erro: {0}'
                    .format(e))
                tentativas = tentativas + 1

        if tentativas == self.__MAX_TENTIVAS:
            raise ASFBugScraperError(
                "Erro ao conectar com a url {0}. Status Code: {1}".format(url))
        '''----------------------------------------
                    Verificando se a conexao ocorreu
                    corretamente.
        ------------------------------------'''
        status_code = asfResponse.status_code

        if status_code == self.__SUCESS_CODE:
            self.__parsedHTML = html.fromstring(asfResponse.text)
        else:
            raise ASFBugScraperError(
                "Erro ao conectar com a url {0}. Status Code: {1}".format(
                    url, status_code))
Exemplo n.º 8
0
 def __retrieveComponet(self):
     componentList = self.__parsedHTML.xpath(self.__COMPONENT_XPATH)
     if len(componentList) == 1:
         componentString = componentList[0]
         componentString = componentString.strip()
         return componentString.encode('utf-8')
     else:
         ASFBugScraperError(
             "Erro em recuperar o atributo 'component'. Detalhes: numero de argumentos retornados é invalido"
         )
         return None
Exemplo n.º 9
0
 def __retrieveProduct(self):
     productList = self.__parsedHTML.xpath(self.__PRODUCT_XPATH)
     if len(productList) == 1:
         retString = productList[0]
         retString = retString.strip()
         return retString.encode('utf-8')
     else:
         ASFBugScraperError(
             "Erro em recuperar o atributo 'product'. Detalhes: numero de argumentos retornados é invalido"
         )
         return None
Exemplo n.º 10
0
    def __init__(self):
        '''
        Constructor
        '''
        try:
            __bugListModel = BugListModel()

        except Exception as e:
            raise ASFBugScraperError(
                "Erro ao criar o objeto BugList. Detalhes: {0}".format(
                    e.message))
Exemplo n.º 11
0
 def __retrieveHardware(self):
     hardwareList = self.__parsedHTML.xpath(self.__HARDWARE_XPATH)
     try:
         hardwareString = hardwareList[0]
         hardwareString = hardwareString.replace('\n', '')
         hardwareString = " ".join(hardwareString.split())
         return hardwareString.encode('utf-8')
     except IndexError as ie:
         ASFBugScraperError(
             "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
             .format(ie.message))
         return None
Exemplo n.º 12
0
    def __retrieveVersion(self):

        versionList = self.__parsedHTML.xpath(self.__VERSION_XPATH)
        try:
            versionString = versionList[0]
            versionString = versionString.replace('\n', '')
            versionString = versionString.strip()
            return versionString.encode('utf-8')
        except IndexError as ie:
            ASFBugScraperError(
                "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
                .format(ie.message))
            return None
Exemplo n.º 13
0
    def __retrieveImportance(self):

        importanceList = self.__parsedHTML.xpath(self.__IMPORTANCE_XPATH)
        try:
            importanceString = importanceList[0]
            importanceString = importanceString.replace('\n', '')
            importanceString = " ".join(importanceString.split())
            return importanceString.encode('utf-8')
        except IndexError as ie:
            ASFBugScraperError(
                "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
                .format(ie.message))
            return None
Exemplo n.º 14
0
    def getNextBugID(self):
        '''
            Retorna o proximo ID de bug  da lista
        '''
        if (not self.__isEmpty):

            nextVal = self.__buglist[self.__nextItem]
            self.__nextItem = self.__nextItem + 1
            return nextVal

        else:

            raise ASFBugScraperError("Erro: a lista está vazia")
Exemplo n.º 15
0
 def __retrieveTargetMilestone(self):
     targetMilestoneList = self.__parsedHTML.xpath(
         self.__TARretrieve_MILESTONE_XPATH)
     try:
         targetMilestoneString = targetMilestoneList[0]
         targetMilestoneString = targetMilestoneString.replace('\n', '')
         targetMilestoneString = targetMilestoneString.strip()
         return targetMilestoneString.encode('utf-8')
     except IndexError as ie:
         ASFBugScraperError(
             "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
             .format(ie.message))
         return None
Exemplo n.º 16
0
    def __retrieveAssignedTo(self):

        assignToList = self.__parsedHTML.xpath(self.__ASSIGNED_TO_XPATH)
        assignToString = self.__parsedHTML.xpath(self.__HARDWARE_XPATH)
        try:
            assignToString = assignToList[0]
            assignToString = assignToString.replace('\n', '')
            assignToString = assignToString.strip()
            return assignToString.encode('utf-8')
        except IndexError as ie:
            ASFBugScraperError(
                "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
                .format(ie.message))
            return None
Exemplo n.º 17
0
 def __retrieveBugStatus(self):
     retString = ""
     bugStatusList = self.__parsedHTML.xpath(self.__BUG_STATUS_XPATH)
     if len(bugStatusList) >= 1:
         retString = bugStatusList[0].replace("of", "")
         retString = retString.replace("\n", "")
         #Removendo espaços adicionados
         retString = " ".join(retString.split())
         return retString.encode('utf-8')
     else:
         ASFBugScraperError(
             "Erro em recuperar o atributo 'bug_status'. Detalhes: numero de argumentos retornados é invalido"
         )
         return None
Exemplo n.º 18
0
 def __retrieveBugDescription(self):
     commentsList = self.__parsedHTML.xpath(self.__BUG_DESCRIPTION_XPATH)
     if len(commentsList) == 0:
         return None
     else:
         try:
             comments = commentsList[0]
             comments = comments.replace('\n', '')
             comments = comments.strip()
             return comments.encode('utf-8')
         except IndexError as ie:
             ASFBugScraperError(
                 "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
                 .format(ie.message))
             return None
Exemplo n.º 19
0
    def __retrieveReportedBy(self):

        reportedByList = self.__parsedHTML.xpath(self.__REPORTED_BY_XPATH)
        if len(reportedByList) == 0:
            return None
        else:
            try:
                reportedByString = reportedByList[0]
                reportedByString = reportedByString.replace('\n', '')
                reportedByString = reportedByString.strip()
                return reportedByString.encode('utf-8')
            except IndexError as ie:
                ASFBugScraperError(
                    "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
                    .format(ie.message))
                return None
Exemplo n.º 20
0
    def __retrieveLastModificationDate(self):

        lastModificationList = self.__parsedHTML.xpath(
            self.__LAST_MODIFICATION_XPATH)
        if len(lastModificationList) == 0:
            return None
        else:
            try:
                lastModification = lastModificationList[0]
                lastModification = lastModification.replace('\n', '')
                lastModification = lastModification.replace('by', '')
                lastModification = lastModification.replace('(', '')
                lastModification = lastModification.replace('UTC', '')
                lastModification = lastModification.strip()
                return lastModification
            except IndexError as ie:
                ASFBugScraperError(
                    "Erro em recuperar o atributo 'version'. O número de atributos é invalido. Detalhes: { }"
                    .format(ie.message))
                return None
Exemplo n.º 21
0
 def retrieveAllIDS(self,startBugID):
     try:
         self.__connection = ConnetionManager()
         self.__connection.connect()
     
         listRetVal = []
     
         SQL_GET_SQ = '''SELECT BL.BUG_ID
                         FROM SQM.BUG_LIST BL
                         WHERE BL.BUG_ID >= %s
                         AND BL.PRODUCT <> 'Apache httpd-2'
                         ORDER BY BL.BUG_ID;
                      '''           
         cur =  self.__connection.get_cursor()
         cur.execute(SQL_GET_SQ,(startBugID,))
         for record in cur:
             listRetVal.append(record[0])
         self.__connection.close_cursor(cur)
         #self.__connection.close_connection()
         return listRetVal
     except Exception as e:
         print(e.message)
         raise ASFBugScraperError(e.message)