0

I'm a newbie in Python. I would like create a python script which checks(maybe parsing) every commited xml-file for the availablity of a special tag (e.g. status="Needs Review"). If the xml-file consists of this tag then send an email with a link to the topic. If not continue commit without sending any email.

Does anybody have a code sample how to realize this as a python script. xml-file-sample:

<topic template="Default" status="Needs Review" lasteditedby="user1">
  <title translate="true">Sample Title</title>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Statistische Messungen</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Font Style" style="font-family:&apos;Optima LT&apos;; font-size:10pt; font-weight:normal; font-style:normal; text-decoration:none; text-transform:none; vertical-align:baseline; color:#000000; background-color:transparent; letter-spacing:normal; letter-scaling:100%;" translate="true">This is a sample Text</text></para>
  </body>
</topic>

I guess there are different ways to do this and I know there some python codings for post-commits, but I can't find codings for this issue.

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
M. Addam
  • 11
  • 1
  • Do you need to extract **Statistische Messungen** and **This is a sample Text**? – Andrés Pérez-Albela H. Nov 06 '15 at 10:54
  • I need to check each xml file (when commiting to svn) for the status-tag if set to "Need Review". If this status is set in each xml file an email with a list of corresponding files should sent to the Reviewer. This code snippet is a good snippet. Just need to grep the content of commited xml-files instead of xml code snippet. – M. Addam Nov 12 '15 at 08:48

1 Answers1

0

This code snippet from Andres is a good basis. I just need to grep the contents of commited xml files, such like "svn look changed" (for xml-files) and for each xml-file "svn look cat.

from lxml import html
from mailer import Mailer
from mailer import Message
import sys, os

xml = """<topic template="Default" status="Needs Review" lasteditedby="user1">
  <title translate="true">Sample Title</title>
  <body>
    <header>
      <para styleclass="Heading1"><text styleclass="Heading1" translate="true">Statistische Messungen</text></para>
    </header>
    <para styleclass="Normal"><text styleclass="Font Style" style="font-family:&apos;Optima LT&apos;; font-size:10pt; font-weight:normal; font-style:normal; text-decoration:none; text-transform:none; vertical-align:baseline; color:#000000; background-color:transparent; letter-spacing:normal; letter-scaling:100%;" translate="true">This is a sample Text</text></para>
  </body>
</topic>"""


tree = html.fromstring(xml)
if tree.xpath('//topic/@status')[0] == "Needs Review":
    print "This topic needs review"
    print "Sending e-mail"  
    # Call email function here...
else:
    print "This topic doesn't need review"
    print "Continuing commit without sending e-mail"
    # Continue with commit
M. Addam
  • 11
  • 1