def extrair(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: build = argumentos.get('build') xp.parser(arquivo_xml) ambientes = xp.content( '//hudson.plugins.ambiente.PromoteAmbienteAction/listaAmbienteVo/hudson.plugins.ambiente.AmbienteVo' ).items() for selo_ambiente in ambientes: timestamp = selo_ambiente.get('timestamp') numero_rs = selo_ambiente.get('numeroRs') try: ambiente = Ambiente.objects.get(build=build, timestamp=timestamp, numero_rs=numero_rs) except: ambiente = Ambiente() ambiente.build = build ambiente.numero_rs = numero_rs ambiente.timestamp = timestamp ambiente.mensagem = selo_ambiente.get('mensagem') ambiente.level = selo_ambiente.get('level') ambiente.level_value = selo_ambiente.get('levelValue') ambiente.user = util.Text().format_login( selo_ambiente.get('user')) ambiente.datetime = util.DateTime().timestamp_to_datetime( ambiente.timestamp) ambiente.save() except Exception, e: log(identifier=__name__, filename=arquivo_xml, message=e)
def extrair(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: build = argumentos.get('build') xp.parser(arquivo_xml) lista = xp.content('//annotation-array/bug').items() for item in lista: key = item.get('key') try: checklist = Checklist.objects.get(build=build, key=key) except: checklist = Checklist() checklist.build = build checklist.message = item.get('message') checklist.priority = item.get('priority') checklist.key = key checklist.primary_line_number = item.get('primaryLineNumber') checklist.filename = item.get('fileName') checklist.module = item.get('moduleName') checklist.package = item.get('packageName') checklist.category = item.get('category') checklist.type_warning = item.get('type') checklist.save() except Exception, e: log(identifier=__name__, filename=arquivo_xml, message=e)
def test_get_children_content_from_node_list(self): """ <project> <hudson.tasks.Maven> <targets>String 1</targets> <mavenName>String 2</mavenName> <pom>String 3</pom> <usePrivateRepository>String 4</usePrivateRepository> </hudson.tasks.Maven> <hudson.tasks.Maven> <targets>String 1</targets> <mavenName>String 2</mavenName> <pom>String 3</pom> <usePrivateRepository>String 4</usePrivateRepository> </hudson.tasks.Maven> </project> """ parser = XpathParser().parser(self.file) nodes = parser.content('//hudson.tasks.Maven').nodes self.assertEqual(6, len(nodes)) result = parser.items() node1 = result[0] self.assertEqual('-e -U clean', node1.get('targets')) self.assertEqual('maven2.2.1', node1.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-pom/pom.xml', node1.get('pom')) self.assertEqual('false', node1.get('usePrivateRepository')) node2 = result[1] self.assertEqual('-e -U clean install', node2.get('targets')) self.assertEqual('maven2.2.1', node2.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-util/pom.xml', node2.get('pom')) self.assertEqual('false', node2.get('usePrivateRepository')) node3 = result[2] self.assertEqual('-e -U clean install', node3.get('targets')) self.assertEqual('maven2.2.1', node3.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-ejbClient/pom.xml', node3.get('pom')) self.assertEqual('false', node3.get('usePrivateRepository')) node4 = result[3] self.assertEqual('-e -U clean install', node4.get('targets')) self.assertEqual('maven2.2.1', node4.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-ejb/pom.xml', node4.get('pom')) self.assertEqual('false', node4.get('usePrivateRepository')) node5 = result[4] self.assertEqual('-e -U -DskipTests=true install org.codehaus.mojo:was6-maven-plugin:1.2-SNAPSHOT:ejbdeploy -Dwas6.skip=true', node5.get('targets')) self.assertEqual('maven2.2.1', node5.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-pom/pom.xml', node5.get('pom')) self.assertEqual('false', node5.get('usePrivateRepository')) node6 = result[5] self.assertEqual('-e install -Pqualidade org.codehaus.mojo:was6-maven-plugin:1.2-SNAPSHOT:ejbdeploy -Dwas6.skip=true org.apache.maven.plugins:maven-javadoc-plugin:2.7:javadoc -Dmaven.javadoc.skip=true', node6.get('targets')) self.assertEqual('maven2.2.1', node6.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-pom/pom.xml', node6.get('pom')) self.assertEqual('false', node6.get('usePrivateRepository'))
def test_get_content_from_one_node(self): """ <project><disabled>boolean</disabled></project> """ parser = XpathParser().parser(self.file) result = parser.content('//project/disabled').text() self.assertEqual('false', result)
def extrair(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: nome_do_job = argumentos.get('nome') xp.parser(arquivo_xml) job, criado = Job.objects.get_or_create(name=nome_do_job) job.disabled = xp.content('//project/disabled').text() job.jdk = xp.content('//project/jdk').text() job.save() usuarios = xp.content('//hudson.security.AuthorizationMatrixProperty/permission').list() job = self._job_com_usuarios(job, usuarios) return job except Exception, e: log(identifier=__name__, filename=arquivo_xml, message='Erro ao extrair dados do Job: %s' % e)
def obter_vertical(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: job = argumentos.get('job') xp.parser(arquivo_xml) xpath_str = '//listView/name[following-sibling::jobNames[descendant::string="%s"]]' % job.name views = xp.content(xpath_str).list() for v in views: if not v.strip()[0:4] == 'BSAD': return v except Exception, e: log(identifier=__name__, filename=arquivo_xml, message=e) return None
def _extrair_dados_bsra_services(self, build, arquivo_xml): xp = XpathParser() try: xp.parser(arquivo_xml) content = xp.content('//bsra/service').attributes() for data in content: bsra = Bsra() bsra.build = build bsra.nome = data.get('name') bsra.identificador = data.get('identify') bsra.tipo = data.get('type') bsra.reusabilidade = data.get('reusability') bsra.modulo = data.get('moduleName') bsra.registrado = data.get('registered') == 'true' bsra.save() except Exception, e: log(identifier=__name__, filename=arquivo_xml, message='Erro ao extrair dados do BSRA Services: %s' % e)
def test_get_children_content_from_one_node(self): """ <project> <hudson.security.AuthorizationMatrixProperty> <permission>String 1</permission> <permission>String 2</permission> <permission>String 3</permission> </hudson.security.AuthorizationMatrixProperty> </project> """ parser = XpathParser().parser(self.file) result = parser.content('//hudson.security.AuthorizationMatrixProperty/permission').list() self.assertEqual(46, len(result)) self.assertEqual('hudson.model.Item.Read:L897286', result[0]) self.assertEqual('hudson.model.Item.Read:L806229', result[1]) self.assertEqual('hudson.model.Item.Read:L838756', result[2])
def _extrair_dados_bsra_warnings(self, build, arquivo_xml): xp = XpathParser() try: xp.parser(arquivo_xml) content = xp.content('//hudson.plugins.bsra.parser.Warning[descendant::message]').items() for item in content: data = util.Text().get_data_from_string(item.get('message')) bsra = Bsra() bsra.build = build bsra.nome = data.get('Nome') bsra.identificador = data.get('Identificador') bsra.tipo = data.get('Tipo') bsra.reusabilidade = data.get('Reusabilidade').replace('.', '') bsra.modulo = item.get('moduleName') bsra.registrado = False bsra.save() except Exception, e: log(identifier=__name__, filename=arquivo_xml, message='Erro ao extrair dados do BSRA Warnings: %s' % e)
def test_get_children_content_from_one_node(self): """ <project> <hudson.security.AuthorizationMatrixProperty> <permission>String 1</permission> <permission>String 2</permission> <permission>String 3</permission> </hudson.security.AuthorizationMatrixProperty> </project> """ parser = XpathParser().parser(self.file) result = parser.content( '//hudson.security.AuthorizationMatrixProperty/permission').list() self.assertEqual(46, len(result)) self.assertEqual('hudson.model.Item.Read:L897286', result[0]) self.assertEqual('hudson.model.Item.Read:L806229', result[1]) self.assertEqual('hudson.model.Item.Read:L838756', result[2])
def extrair(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: build = argumentos.get('build') xp.parser(arquivo_xml) data = xp.content('//hudson.plugins.javancss.JavaNCSSBuildIndividualReport/totals').items()[0] ncss = Ncss() ncss.build = build ncss.ncss = data.get('ncss') ncss.classes = data.get('classes') ncss.functions = data.get('functions') ncss.javadocs = data.get('javadocs') ncss.javadocs_lines = data.get('javadocLines') ncss.single_comments_line = data.get('singleCommentLines') ncss.multi_comments_line = data.get('multiCommentLines') ncss.save() except Exception, e: log(identifier=__name__, filename=arquivo_xml, message=e)
def obter_framework(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: job = argumentos.get('job') xp.parser(arquivo_xml) xpath_str = '//listView[descendant::name=" BSAD %s"]/jobNames/string' bsad1_jobs = xp.content(xpath_str % '1').list() bsad2_jobs = xp.content(xpath_str % '2').list() framework = 'BSAD 3' if job.name in bsad1_jobs: framework = 'BSAD 1' if job.name in bsad2_jobs: framework = 'BSAD 2' return framework except Exception, e: log(identifier=__name__, filename=arquivo_xml, message=e) return None
def test_convert_attributes_to_dict(self): """ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <bsra> <service identify="DigiclassWsService" moduleName="LEXW-BsLexWeb-ws" name="DigiclassWsService" pathFile="" registered="false" reusability="exposto" type="WebService"/> </bsra> """ filename = self.resources + '/bsra_services.xml' parser = XpathParser().parser(filename) nodes = parser.content('//bsra/service').nodes self.assertEqual(1, len(nodes)) node = parser.attributes()[0] self.assertEqual('DigiclassWsService', node.get('identify')) self.assertEqual('LEXW-BsLexWeb-ws', node.get('moduleName')) self.assertEqual('DigiclassWsService', node.get('name')) self.assertEqual('', node.get('pathFile')) self.assertEqual('false', node.get('registered')) self.assertEqual('exposto', node.get('reusability')) self.assertEqual('WebService', node.get('type'))
def test_convert_two_nodes_to_dict(self): """ <violations> <entry> <string>checkstyle</string> <int>177</int> </entry> <entry> <string>cpd</string> <int>1155</int> </entry> </violations> """ filename = self.resources + '/build.xml' parser = XpathParser().parser(filename) nodes = parser.content('//violations/entry').nodes self.assertEqual(4, len(nodes)) result = parser.concat('./string', './int') self.assertEqual("{'pmd': '231', 'findbugs': '1397', 'cpd': '1155', 'checkstyle': '177'}", result.__str__())
def _extrair_dados_bsra_warnings(self, build, arquivo_xml): xp = XpathParser() try: xp.parser(arquivo_xml) content = xp.content( '//hudson.plugins.bsra.parser.Warning[descendant::message]' ).items() for item in content: data = util.Text().get_data_from_string(item.get('message')) bsra = Bsra() bsra.build = build bsra.nome = data.get('Nome') bsra.identificador = data.get('Identificador') bsra.tipo = data.get('Tipo') bsra.reusabilidade = data.get('Reusabilidade').replace('.', '') bsra.modulo = item.get('moduleName') bsra.registrado = False bsra.save() except Exception, e: log(identifier=__name__, filename=arquivo_xml, message='Erro ao extrair dados do BSRA Warnings: %s' % e)
def test_convert_two_nodes_to_dict(self): """ <violations> <entry> <string>checkstyle</string> <int>177</int> </entry> <entry> <string>cpd</string> <int>1155</int> </entry> </violations> """ filename = self.resources + '/build.xml' parser = XpathParser().parser(filename) nodes = parser.content('//violations/entry').nodes self.assertEqual(4, len(nodes)) result = parser.concat('./string', './int') self.assertEqual( "{'pmd': '231', 'findbugs': '1397', 'cpd': '1155', 'checkstyle': '177'}", result.__str__())
def test_get_children_content_from_node_list(self): """ <project> <hudson.tasks.Maven> <targets>String 1</targets> <mavenName>String 2</mavenName> <pom>String 3</pom> <usePrivateRepository>String 4</usePrivateRepository> </hudson.tasks.Maven> <hudson.tasks.Maven> <targets>String 1</targets> <mavenName>String 2</mavenName> <pom>String 3</pom> <usePrivateRepository>String 4</usePrivateRepository> </hudson.tasks.Maven> </project> """ parser = XpathParser().parser(self.file) nodes = parser.content('//hudson.tasks.Maven').nodes self.assertEqual(6, len(nodes)) result = parser.items() node1 = result[0] self.assertEqual('-e -U clean', node1.get('targets')) self.assertEqual('maven2.2.1', node1.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-pom/pom.xml', node1.get('pom')) self.assertEqual('false', node1.get('usePrivateRepository')) node2 = result[1] self.assertEqual('-e -U clean install', node2.get('targets')) self.assertEqual('maven2.2.1', node2.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-util/pom.xml', node2.get('pom')) self.assertEqual('false', node2.get('usePrivateRepository')) node3 = result[2] self.assertEqual('-e -U clean install', node3.get('targets')) self.assertEqual('maven2.2.1', node3.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-ejbClient/pom.xml', node3.get('pom')) self.assertEqual('false', node3.get('usePrivateRepository')) node4 = result[3] self.assertEqual('-e -U clean install', node4.get('targets')) self.assertEqual('maven2.2.1', node4.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-ejb/pom.xml', node4.get('pom')) self.assertEqual('false', node4.get('usePrivateRepository')) node5 = result[4] self.assertEqual( '-e -U -DskipTests=true install org.codehaus.mojo:was6-maven-plugin:1.2-SNAPSHOT:ejbdeploy -Dwas6.skip=true', node5.get('targets')) self.assertEqual('maven2.2.1', node5.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-pom/pom.xml', node5.get('pom')) self.assertEqual('false', node5.get('usePrivateRepository')) node6 = result[5] self.assertEqual( '-e install -Pqualidade org.codehaus.mojo:was6-maven-plugin:1.2-SNAPSHOT:ejbdeploy -Dwas6.skip=true org.apache.maven.plugins:maven-javadoc-plugin:2.7:javadoc -Dmaven.javadoc.skip=true', node6.get('targets')) self.assertEqual('maven2.2.1', node6.get('mavenName')) self.assertEqual('LEXW-BsLexWeb-pom/pom.xml', node6.get('pom')) self.assertEqual('false', node6.get('usePrivateRepository'))
def test_return_empty_if_node_doesnot_exists(self): parser = XpathParser().parser(self.file) result = parser.content('//xpto').text() self.assertEqual('', result)
def extrair(self, **argumentos): arquivo_xml = argumentos.get('arquivo') xp = XpathParser() try: job = argumentos.get('job') build_name = argumentos.get('nome') xp.parser(arquivo_xml) build_number = xp.content('//build/number').text() try: build = Build.objects.get(job=job, number=build_number) except: build = Build() build.job = job build.name = build_name build.number = build_number build.result = xp.content('//build/result').text() build.description = xp.content('//build/description').text() build.charset = xp.content('//build/charset').text() build.built_on = xp.content('//build/builtOn').text() build.workspace = xp.content('//build/workspace').text() build.hudson_version = xp.content('//build/hudsonVersion').text() build.release_version = xp.content( '//hudson.plugins.release.ReleaseWrapper_-ReleaseBuildBadgeAction/releaseVersion' ).text() build.bsra_warnings = xp.content('//result/numberOfWarnings') datetime_util = util.DateTime() build.datetime = datetime_util.str_to_datetime(build_name) build.duration = datetime_util.ms_to_seconds( xp.content('//build/duration').text()) build.user = util.Text().format_login( xp.content('//hudson.model.Cause_-UserCause/authenticationName' ).text()) violations = xp.content('//violations/entry').concat( './string', './int') build.checkstyle_violations = violations.get('checkstyle') build.cpd_violations = violations.get('cpd') build.findbugs_violations = violations.get('findbugs') build.pmd_violations = violations.get('pmd') qualidade = xp.content( '//hudson.plugins.selo__qualidade.PromoteAction').items() if len(qualidade) > 0: selo_qualidade = qualidade[0] selo_qualidade = xp.content( '//hudson.plugins.selo__qualidade.PromoteAction').items( )[0] build.selo_qualidade_user = selo_qualidade.get('user') build.selo_qualidade_numeroRs = selo_qualidade.get('numeroRs') build.selo_qualidade_mensagem = selo_qualidade.get('mensagem') build.selo_qualidade_level = selo_qualidade.get('level') build.selo_qualidade_levelValue = selo_qualidade.get( 'levelValue') build.save() return build except Exception, e: log(identifier=__name__, filename=arquivo_xml, message=e)