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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#!/usr/bin/env python
# Copyright 2008-2010 David D Lowe
# released under the GPLv3
from pigment import PigmentType, Pigment
from pigment_more import DirBasedPigment, DirBasedPigmentType
import pigment
import os, sys
import gtk
from glob import glob
if __name__ == "__main__" or 'pychecker' in sys.argv[0]:
sys.path.append("..")
import handy
import ep_exceptions
import hashlib
from gettext import gettext as _
class GDMType(DirBasedPigmentType):
humanName = {"en":"GDM"}
humanPluralName = {"en":"GDM"}
codeName = "gdm"
abbreviation = "gdm"
directoryName = "gdm"
canGeneratePreview = True
attachmentTypeHelp = _("The theme file should be the directory that bears the name of theme, and containing a file named GdmGreeterTheme.desktop")
@staticmethod
def get_Pigment():
return GDM
@classmethod
def does_system_support_me(klass):
import xsplash_hack
if xsplash_hack.XsplashHackType.does_system_support_me():
return False
return os.path.exists("/usr/share/gdm/defaults.conf") or \
os.path.exists("/etc/gdm/gdm.conf-custom")
publicBaseDir = "/usr/share/gdm/themes"
personalBaseDir = ""
isDirectoryShared = False
specificChildren = ()
class GDM(DirBasedPigment):
type = GDMType
def __init__(self):
DirBasedPigment.__init__(self)
def activate(self, progressCallback=None, shell=None):
if progressCallback is None:
progressCallback = lambda(a1): False
if shell is None:
print >> sys.stderr, "shell is None, should include a shell with root acces for GDM"
import shell
shell = shell.SubprocessShell()
shell.prepare()
if self.attDirname == "" or self.attDirname is None:
print >> sys.stderr, "GDM object (" + str(self) + ") has no attDirname"
raise(Exception("GDM object has no attDirname"))
if progressCallback(0.0): return
from ConfigParser import SafeConfigParser # for reading INI files
class BetterConfigParser(SafeConfigParser):
"""Better than SafeConfigParser: it's case-sensitive"""
def __init__(self):
SafeConfigParser.__init__(self)
def optionxform(self, optionstr):
return optionstr
configParser = BetterConfigParser()
if os.path.exists("/usr/share/gdm/defaults.conf"):
if not os.path.exists("/etc/gdm/gdm.conf"):
shell.do(["touch","/etc/gdm/gdm.conf"])
conf = "/etc/gdm/gdm.conf"
else:
conf = "/etc/gdm/gdm.conf-custom"
configParser.read(conf)
configParser.set("greeter", "GraphicalTheme", self.attDirname)
configParser.set("greeter", "GraphicalThemes", "happygnome:/" + self.attDirname) # I'm not sure why this line is necessary
if not os.path.exists(conf + ".epidermisinit.bak"):
shell.do(["cp", conf, conf + ".epidermisinit.bak"])
import subprocess
subprocess.call(["mkdir", "-p", "/tmp/epidermis"])
subprocess.call(["touch", "/tmp/epidermis/gdm.conf-custom"])
configParser.write(open("/tmp/epidermis/gdm.conf-custom", "w"))
shell.do(["mv", "-f", "/tmp/epidermis/gdm.conf-custom", conf])
# Can't seem to get this to work with the shell, fortunately, it doesn't need to be run
# as root, so I'll use subprocess
subprocess.call("gdmflexiserver --command=\"UPDATE_CONFIG greeter/GraphicalTheme\"", shell=True)
subprocess.call("gdmflexiserver --command=\"UPDATE_CONFIG greeter/GraphicalThemes\"", shell=True)
progressCallback(1.0)
def is_activated(self):
return self.is_meat_activated()
def is_attachment_correct(self, attachmentIndex=None):
if not DirBasedPigment.is_attachment_correct(self, attachmentIndex):
return False
if attachmentIndex is None:
att = self.attachments[0]
else:
att = self.attachments[attachmentIndex]
if not os.path.exists(os.path.join(att, "GdmGreeterTheme.desktop")):
return False
return Pigment.is_attachment_correct(self, attachmentIndex)
def is_meat_installed(self):
(md1, md2) = (hashlib.md5(), hashlib.md5())
try:
f1 = glob(self.attPath + "/*")
f2 = glob("/usr/share/gdm/themes/%s/*" % self.attDirname)
except:
return False
for mm, ff in ((md1, f1), (md2, f2)):
for af in ff:
try:
ss = file(af, "rb").read(8096)
except:
return False
if not ss:
break
mm.update(ss)
return md1 == md2
def is_meat_activated(self):
(md1, md2) = (hashlib.md5(), hashlib.md5())
try:
f1 = glob(self.attPath + "/*")
from ConfigParser import SafeConfigParser # for reading INI files
class BetterConfigParser(SafeConfigParser):
"""Better than SafeConfigParser: it's case-sensitive"""
def __init__(self):
SafeConfigParser.__init__(self)
def optionxform(self, optionstr):
return optionstr
if os.path.exists("/usr/share/gdm/defaults.conf"):
conf = "/etc/gdm/gdm.conf"
else:
conf = "/etc/gdm/gdm.conf-custom"
configParser = BetterConfigParser()
configParser.read(conf)
nn = configParser.get("greeter", "GraphicalTheme")
f2 = glob("/usr/share/gdm/themes/%s/*" % nn)
except:
return False
for mm, ff in ((md1, f1), (md2, f2)):
for af in ff:
try:
ss = file(af, "rb").read(8096)
except:
return False
if not ss:
break
mm.update(ss)
return md1 == md2
def generate_preview(self):
if len(self.attPath) < 1:
return None
if not os.path.exists(os.path.join(self.attPath, "GdmGreeterTheme.desktop")):
return None
desktopFile = open(os.path.join(self.attPath, "GdmGreeterTheme.desktop"), "r")
screenshotName = None
for line in desktopFile.readlines():
line.strip()
if line[:10] == "Screenshot" and line[10].strip()[0] == "=":
screenshotName = line[len(line.split("=")[0]) + 1:].strip()
break
if screenshotName is None:
return None
try:
pb = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(self.attPath, screenshotName), 100, 75)
except:
import traceback
traceback.print_exc()
return None
if pb is None:
return None
else:
self.preview = pb
return pb
def does_activation_require_root(self):
return True
def get_display_data(self, index=0):
return
|