comparison addDriToIndexMeta.py @ 31:0190f49bce88

added change flag
author dwinter
date Thu, 06 Jun 2013 05:55:09 +0200
parents bcd8076ff7ec
children be8640c08d99
comparison
equal deleted inserted replaced
30:bcd8076ff7ec 31:0190f49bce88
19 def correctAuthor(tree): 19 def correctAuthor(tree):
20 """ersetzt in den autor felder "\r" durch ;""" 20 """ersetzt in den autor felder "\r" durch ;"""
21 21
22 22
23 authors = tree.xpath("/resource/meta/bib/author") 23 authors = tree.xpath("/resource/meta/bib/author")
24
25 changed = False
24 for author in authors: 26 for author in authors:
25 27
26 if author.text is not None: 28 if author.text is not None:
27 splitted =author.text.split("\n") 29 splitted =author.text.split("\n")
28 txt = "; ".join(splitted) 30 txt = "; ".join(splitted)
29 31
30 author.text=txt 32 if txt!=author.text:
33 author.text=txt
34 changed=True
31 35
32 36 return changed
33 37
34 def addPURL(fl,purl,test=False): 38 def addPURL(fl,purl,test=False):
35 try: 39 try:
36 tree = etree.parse(fl) 40 tree = etree.parse(fl)
37 except: 41 except:
39 return False 43 return False
40 44
41 dris = tree.xpath("/resource/meta/dri[@type='mpiwg']") 45 dris = tree.xpath("/resource/meta/dri[@type='mpiwg']")
42 46
43 47
44 correctAuthor(tree) 48 changed = correctAuthor(tree)
45 49
46 50
47 51
48 if len(dris)==0: # erzeuge neu 52 if len(dris)==0: # erzeuge neu
49 newDri = etree.Element("dri",type="mpiwg") 53 newDri = etree.Element("dri",type="mpiwg")
55 else: 59 else:
56 metas[0].append(newDri) 60 metas[0].append(newDri)
57 else: 61 else:
58 dris[0].text=purl 62 dris[0].text=purl
59 alreadyExistsFile.write("%s \n"%fl) 63 alreadyExistsFile.write("%s \n"%fl)
60 #return True 64 if not changed: #nothing has to be done
65 return True
61 66
62 print etree.tostring(tree, pretty_print=True) 67 print etree.tostring(tree, pretty_print=True)
63 68
64 69
65 if not test: 70 if not test: