-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
csl-count-default-locales.py
49 lines (37 loc) · 1.42 KB
/
csl-count-default-locales.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Python script to count default-locale values
# Author: Rintze M. Zelle
# Version: 2013-04-07
# * Requires lxml library (http://lxml.de/)
#
# Prints the default-locale values
import os, glob, re, inspect
from lxml import etree
# http://stackoverflow.com/questions/50499
folderPath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentFolderPath = os.path.dirname (folderPath)
path = os.path.join(parentFolderPath, 'styles')
styles = []
for stylepath in glob.glob( os.path.join(path, '*.csl') ):
styles.append(os.path.join(stylepath))
for stylepath in glob.glob( os.path.join(path, 'dependent', '*.csl') ):
styles.append(os.path.join(stylepath))
uniqueStrings = {}
stylesTested = 0
for style in styles:
parsedStyle = etree.parse(style)
styleElement = parsedStyle.getroot()
stylesTested += 1
if "default-locale" in styleElement.attrib:
defaultLocale = styleElement.get("default-locale")
else:
defaultLocale = "no default-locale"
print("No default-locale:" + style)
if defaultLocale in uniqueStrings:
uniqueStrings[defaultLocale] += 1
else:
uniqueStrings[defaultLocale] = 1
sortedStrings = sorted(uniqueStrings, key=uniqueStrings.get, reverse=True)
print("Styles tested: " + "%d" % (stylesTested))
print("default-locale values:")
for string in sortedStrings:
print('"' + string + '"' + ": %d" % (uniqueStrings[string]))