15
15
import gobject, subprocess
16
16
import urllib, socket, urlparse
17
17
import ep_exceptions
18
19
from gtkcrashhandler import gtkcrashhandler_thread
21
22
def find_skins(directories=None, pigments=None):
22
"""Looks for skins in the directories passed and returns a list of Skin objects
23
and a list of exceptions encountered, similar to find_pigments
24
directories: the list of directories to search for in order of priority, by default
25
it is [MY_DATA_HOME, SHARED_PIGMENT_DIR]
26
pigments: a list of pigments already loaded that Skin can use to search for pigments"""
23
"""Look for skins in the directories passed.
25
Returns a list of Skin objects and a list of exceptions encountered,
26
similar to find_pigments.
29
directories -- the list of directories to search for in order of
30
priority (default: [MY_DATA_HOME, SHARED_PIGMENT_DIR])
31
pigments -- a list of pigments already loaded that Skin can use to
27
35
if directories is None:
28
36
directories = [MY_DATA_HOME, const.SHARED_PIGMENT_DIR]
30
pt = get_pigment_type("skin")().directoryName
38
pt = get_pigment_type("skin").directoryName
32
40
for dirr in directories:
33
41
if os.path.exists(os.path.join(dirr, pt)):
43
51
def find_pigments(pigmentTypeStr, directories=None):
44
"""Looks for pigments in the directories passed and returns a list of
45
Pigment objects, and a list of tuples of exception information
46
that may have been encountered loading pigments, hopefully, just [] ;)
47
This format: [pigment1, pigment2], [FileNotFoundException, exception, traceback, pigmDir]
48
pigmentTypeStr: the pigment type to look for, string (example: "wallpaper")
49
directories: a list of directories to search for in order of priority, by default it is
50
[MY_DATA_HOME, SHARED_PIGMENT_DIR]"""
52
"""Look for pigments in the directories passed.
54
Returns a list of Pigment objects, and a list of tuples of exception
55
information that may have been encountered loading pigments,
59
[pigment1, pigment2], [FileNotFoundException, exception, traceback, pigmDir]
62
pigmentTypeStr -- the pigment type to look for, string (example: "wallpaper")
63
directories -- a list of directories to search for in order of priority
64
(default: [MY_DATA_HOME, SHARED_PIGMENT_DIR])
51
67
if directories is None:
52
68
directories = [MY_DATA_HOME, const.SHARED_PIGMENT_DIR]
64
80
return retPigments, excps
66
82
def load_pigment(pigment, pigmentType, directories=None):
67
"""Returns a Pigment object that has been read from the appropriate file
68
pigment: the pigment's codeName
69
pigmentType: its type, string
70
directories: list of installationDirectories to search through, in
71
order of priority. By default it is [MY_DATA_HOME, SHARED_PIGMENT_DIR]"""
83
"""Load the specified Pigment object.
85
Returns a Pigment object that has been read from the appropriate file
88
pigment -- the pigment's codeName
89
pigmentType -- its type, string
90
directories -- list of installationDirectories to search through, in
92
(default: [MY_DATA_HOME, SHARED_PIGMENT_DIR])
72
95
if directories is None:
73
96
directories = [MY_DATA_HOME, const.SHARED_PIGMENT_DIR]
74
97
pp = create_pigment(pigmentType)
75
98
if isinstance(directories, str):
76
99
raise(Exception("deprecated"))
77
directories = [directories]
78
100
for dir in directories:
79
101
if does_pigment_exist(pigment, pigmentType, [dir]):
80
102
pp.installationDirectory = dir
84
106
raise(ep_exceptions.PigmentNotFoundException(pigment, pigmentType, directories))
86
108
def load_skin(skin, directories=None, pigments=None):
87
"""Returns a Skin object that has been read from the appropriate file
88
skin: the skin's codename
89
directories: list of installationDirectories to search through, in order of
90
priority. By default it is [MY_DATA_HOME, SHARED_PIGMENT_DIR]
91
pigments: list of preloaded Pigment objects"""
109
"""Load the specified Skin object.
111
Returns a Skin object that has been read from the appropriate file.
114
skin -- the skin's codename
115
directories -- list of installationDirectories to search through, in
117
(Default: [MY_DATA_HOME, SHARED_PIGMENT_DIR])
118
pigments -- list of preloaded Pigment objects
92
121
if directories is None:
93
122
directories = [MY_DATA_HOME, const.SHARED_PIGMENT_DIR]
94
123
if pigments is None: pigments = []
95
124
pp = create_pigment("skin")
96
125
if isinstance(directories, str):
97
126
raise(Exception("deprecated"))
98
directories = [directories]
99
127
for dir in directories:
100
128
if does_pigment_exist(skin, "skin", [dir]):
101
129
pp.installationDirectory = dir
106
134
raise(ep_exceptions.PigmentNotFoundException(skin, "skin", directories))
108
136
def does_pigment_exist(pigmentStr, pigmentType, directories=None):
109
"""Returns whether the pigment specified is installed in the installationDirectory
110
pigmentStr: a string specifying the pigment's code name
111
pigmentType: a string specifying the codeName of the pigment's type
112
directories: a list of installationDirectories in order of priority in which to search through"""
137
"""Return whether the pigment specified is installed.
140
pigmentStr -- a string specifying the pigment's code name
141
pigmentType -- a string specifying the codeName of the pigment's type
142
directories -- a list of installationDirectories in order of priority
143
in which to search through
113
146
if directories is None:
114
147
directories = [MY_DATA_HOME, const.SHARED_PIGMENT_DIR]
115
148
if isinstance(directories, str):
123
156
def get_pigment_type(pigmentTypeString):
124
157
"""Return the appropriate PigmentType class based on the string argument
125
Note: this includes the PackType, even though Pack is not a subclass of Pigment"""
127
from pigments import skin, wallpaper, metacity_, gtk_, icons, gnomesplash, cursors, grub, gdm, xsplash_hack, pack
129
pts = {"skin":skin.SkinType, "wallpaper":wallpaper.WallpaperType, "metacity": metacity_.MetacityType, \
130
"gtk":gtk_.GTKType, "icons":icons.IconsType, "gnomeSplash":gnomesplash.GnomeSplashType, \
131
"cursors":cursors.CursorsType, "grub":grub.GrubType, "gdm":gdm.GDMType, \
132
"xsplashHack":xsplash_hack.XsplashHackType, "pack":pack.PackType}
159
Note: this includes the PackType, even though Pack is not a subclass of Pigment.
162
pts = {"skin":"SkinType", "wallpaper":"WallpaperType", "metacity": "MetacityType", \
163
"gtk":"GTKType", "icons":"IconsType", "gnomeSplash":"GnomeSplashType", \
164
"cursors":"CursorsType", "grub":"GrubType", "gdm":"GDMType", \
165
"xsplashHack":"XsplashHackType", "pack":"PackType"}
134
if pigmentTypeString in pts.keys():
135
return pts[pigmentTypeString]
167
if pigmentTypeString in const.PIGMENT_TYPES + ["pack"]:
168
if pigmentTypeString in ("metacity", "gtk"):
169
module = __import__("pigments." + pigmentTypeString + "_", fromlist=["pigments"])
170
elif pigmentTypeString == "xsplashHack":
171
module = __import__("pigments.xsplash_hack", fromlist=["pigments"])
173
module = __import__("pigments." + pigmentTypeString.lower(), fromlist=["pigments"])
174
return getattr(module, pts[pigmentTypeString])
137
176
raise(ep_exceptions.PigmentTypeNotFoundException(pigmentTypeString))
139
178
def create_pigment(pigmentType):
140
"""Creates a new Pigment of type pigmentType
141
For example, passing "wallpaper" to this function would return wallpaper.Wallpaper()"""
179
"""Create a new Pigment of type pigmentType.
181
For example, passing "wallpaper" to this function would return wallpaper.Wallpaper()
143
185
if pigmentType in const.PIGMENT_TYPES:
144
return get_pigment_type(pigmentType)().get_Pigment()()
186
return get_pigment_type(pigmentType).get_Pigment()()
146
188
raise(ep_exceptions.PigmentTypeNotFoundException(pigmentType))
148
190
def manage_repo_pigments(application, installDict, removeDict, installationDirectory=None):
149
"""manage_repo_piments installs and uninstalls pigments! It also handles the GUI side of things
151
application: the EpidermisApp object that's being run, usually self
152
installDict: a dictionary of the pigment codeNames to install from the repo, example:
153
{"skin":[],"wallpaper":["wallpigment1"],"metacity":[],"gtk":["gtkpak1","gtkpak2"], \
154
"icons":[],"gnomeSplash":[],"cursors":[],"grub":[],"gdm":[],"xsplashHack":[]}
155
removeDict: a dictionary of the pigments codeNames to uninstall, in the same format as installDict
156
installationDirectory: the base directory where to install pigments
157
Should be called in the main thread"""
191
"""Install and uninstall pigments, using the GUI.
194
application -- the EpidermisApp object that's being run
195
installDict -- a dictionary of the pigment codeNames to install from
197
{"skin":[],"wallpaper":["wallpigment1"],"metacity":[],
198
"gtk":["gtkpak1","gtkpak2"],"icons":[],"gnomeSplash":[],
199
"cursors":[],"grub":[],"gdm":[],"xsplashHack":[]}
200
removeDict -- a dictionary of the pigments codeNames to uninstall,
201
in the same format as installDict
202
installationDirectory -- the base directory where to install pigments
204
This method should be called in the main thread.
160
207
application.runningManagePigments += 1
161
208
if application.runningManagePigments > 1:
209
raise Exception("More than one thread running manage_repo_pigments")
165
212
def cancel_callback(widget=None):
166
213
"""cancel_callback for the cancel button on the download window"""
167
214
app.cancel = True
168
gobject.idle_add(lambda:fetchWin.hide())
215
gobject.idle_add(fetchWin.hide)
170
217
def fetchWin_delete_callback(widget, event):
171
218
"""the delete_callback for the download window, calls the cancel_callback,
200
247
"""ManageRepoPigmentsThread installs and uninstalls pigments"""
202
249
def __init__(self,installDict,removeDict,app,progressbar, wTree, fetchWin, installationDirectory=None):
203
"""installDict: a dictionary of the pigments codeNames to install, example:
250
"""Initialise the thread.
253
installDict -- a dictionary of the pigments codeNames to install, example:
204
254
{"skin":[],"wallpaper":["wallpigment1"],"metacity":[],"gtk":["gtkpak1","gtkpak2"], \
205
255
"icons":[],"gnomeSplash":[],"cursors":[],"grub":[],"gdm":[],"xsplashHack":[]}
206
removeDict: a dictionary of the pigments codeNames to uninstall, similar to installDict in format
207
app: the EpidermisApp application object
208
progressbar: the progressbar where progress should be displayed
209
wTree: the wTree from which fetchWin was referenced
210
fetchWin: the window where progress should be displayed
211
installationDirectory: base directory where to install pigments"""
256
removeDict -- a dictionary of the pigments codeNames to uninstall, similar to installDict in format
257
app -- the EpidermisApp application object
258
progressbar -- the progressbar where progress should be displayed
259
wTree -- the wTree from which fetchWin was referenced
260
fetchWin -- the window where progress should be displayed
261
installationDirectory -- base directory where to install pigments
212
264
self.installDict = installDict
213
265
self.removeDict = removeDict