-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmakerCSSTools.py
executable file
·75 lines (60 loc) · 2.15 KB
/
makerCSSTools.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import re
class CSSTools:
def listAllStyleSheetsInPath(self, path, ext=".css"):
theResult = []
for thing in os.listdir(path):
(path, file) = os.path.split(thing)
(one, two) = os.path.splitext(file)
if two == ext:
theResult.append(one + ext)
return theResult
def getIDsFromStyleSheet(self, fileName):
f = open(fileName, "r")
contents = f.read()
f.close()
ids = re.compile("#(.*?) |{", re.IGNORECASE).findall(contents)
finalIDList = []
new = []
for item in ids:
if new.count(item) == 0:
if item != "":
new.append(item)
finalIDList.append(item)
return finalIDList
def getClassesFromStyleSheet(self, fileName):
f = open(fileName, "r")
contents = f.read()
f.close()
classes = re.compile("[.](.*?) |{", re.IGNORECASE).findall(contents)
finalClassList = []
new = []
for item in classes:
if new.count(item) == 0:
if item != "":
new.append(item)
finalClassList.append(item)
return finalClassList
def listUsedStyleSheetsForFilename(self, fileName):
"""
returns a list of stylesheets used in that file
or False
"""
name = os.path.splitext(fileName)[0]
if os.path.isfile(name + ".head"):
f = open(name + ".head", "r")
contents = f.read()
f.close()
list = []
# print self.listAllStyleSheetsInPath(os.path.split(fileName)[0] + "/")
for stylesheet in self.listAllStyleSheetsInPath(
os.path.split(fileName)[0] + "/"
):
# print "looking for ", stylesheet
quotes = ['"', "'"]
for q in quotes:
if contents.count(q + stylesheet + q) < 1:
list.append(stylesheet)
return list
else:
return False