forked from citation-style-language/utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsl-add-rights.py
35 lines (31 loc) · 1.26 KB
/
csl-add-rights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Python script for additional style validation
# Author: Rintze M. Zelle
# Version: 2011-12-17
# * Requires lxml library (http://lxml.de/)
#
# Add CC by-sa license
import os, glob, re
from lxml import etree
path = 'C:\Documents and Settings\zelle\My Documents\CSL\styles\\'
verbatims = {}
for independentStyle in glob.glob( os.path.join(path, '*.csl') ):
style = etree.parse(independentStyle)
styleElement = style.getroot()
verbatimsStyle = []
try:
verbatimsStyle = styleElement.find(".//{http://purl.org/net/xbiblio/csl}rights")
for verbatim in verbatimsStyle:
verbatim = verbatim.text
if verbatim in verbatims:
verbatims[verbatim] += 1
else:
verbatims[verbatim] = 1
except:
info = styleElement.find(".//{http://purl.org/net/xbiblio/csl}info")
rights = etree.SubElement(info, "rights")
rights.text = "This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/"
style = etree.tostring(style, pretty_print=True, xml_declaration=True, encoding="utf-8")
style = style.replace("'", '"', 4)
f = open(independentStyle, 'w')
f.write ( style )
f.close()