Como aún no soy un experto en Python, quiero include cada file xml cambiado dentro de una transacción dentro de un commit en un repository svn y hacer algo. En este caso, compruebo si existe un file xml y luego envío un correo electrónico. Para esto utilizo pysvn y lxml para analizar la label correspondiente. Esto funciona pero solo para un solo file. Si tengo 2 files con la label, no funciono. Además tiene sentido, si hay más de 1 file xml que tiene la label "Necesita revisión" para enviar solo 1 correo electrónico con una list de los files correspondientes. ¿Alguien tiene una idea de cómo cambiar el "para file modificado …" para darse count de esto?
#!/bin/env python import os import sys import subprocess # Import pysvn libs to act with svn import pysvn # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText # Use lxml lib to parse tree for status from lxml import html #tmpFile = open('D:\my.log', 'w') repository = sys.argv[1] transactionId = sys.argv[2] transaction = pysvn.Transaction(repository, transactionId, is_revision=True) for changedFile in transaction.changed(): tree = html.fromstring(transaction.cat(changedFile)) if tree.xpath('//topic/@status')[0] == "Needs Review": #tmpFile.writelines("This topic needs review") # me == my email address # you == recipient's email address me = "test@example.com" you = "test2@example.com" # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "TODO Review JiveX Doku" msg['From'] = me msg['To'] = you # Create the body of the message (a plain-text and an HTML version). text = "Some Text and please check this File." html = """\ <html> <head></head> <body> <p>The following commited Files need a Review. Please Check.<br> Here is the List of Files with links: <a href=".../file1">file 1</a><br><a href=".../file2">file 2</a>. </p> </body> </html> """ # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and prefernetworking. msg.attach(part1) msg.attach(part2) # Send the message via local SMTP server. s = smtplib.SMTP('192.168.1.20') # sendmail function takes 3 arguments: sender's address, recipient's address # and message to send - here it is sent as one string. s.sendmail(me, you, msg.as_string()) s.quit()