This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.py
executable file
·399 lines (339 loc) · 9.08 KB
/
updater.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/usr/bin/pythonw
'''
This is the heart and brains of the WoW Updater Addon. In theory it can
be used to create a CLI or GUI version. Since only a GUI version is
useful ATM there is no CLI version written
'''
__author__ = "Patrick Butler <[email protected]>"
__version__ = "$Revision: 31 $"
__copyright__ = "Copyright 2005,2006 Patrick Butler"
__license__ = "GPL Version 2"
import platform
import urllib
import sys
import re
import shutil
import os
import mutex
import pickle
################################
# AddOn Plugins
################################
import wowaddon
import aceaddons
import cosmos
import curses
import nurfedui
import ctmod
import uiwownet
import wowinterface
import local
import remote
from wowaddon import ParseError, DownloadError
class VerCheckError(Exception): pass
class CleanError(Exception): pass
class UnzipError(Exception): pass
class CopyError(Exception): pass
class UpdaterError(Exception): pass
schemaver = 4
class Updater:
def __init__(self):
self.defaults = { 'zipdir' : 'zips',
'mods' : None,
'release' : '-1',
'version' : schemaver,
'zipdir' : 'zips',
'verify' : 'True'
#'ifacedir' : 'Interface',
}
self.config = {}
self.loglines = []
self.errors = []
self.progmutex = mutex.mutex()
self.startmutex = mutex.mutex()
#keep us from doing anything until we are done setting up
self.startmutex.testandset()
self.modspkl = "mods.pkl"
self.confpkl = "config.pkl"
self.filepkl = "files.pkl"
if(platform.system() == "Windows"):
wdir = r"C:\Program Files\World of Warcraft"
wdir64 = r"C:\Program Files (x86)\World of Warcraft"
if os.path.exists(wdir64):
self.defaults['wowdir'] = wdir64
else:
self.defaults['wowdir'] = wdir
elif(platform.system() == "Darwin"):
self.defaults['wowdir'] = "/Applications/World of Warcraft"
#Work in the .app dir
workingdir = os.path.join(os.path.dirname(sys.argv[0]), "working")
if(not os.path.exists(workingdir)) :
os.makedirs(workingdir)
os.chdir(workingdir)
#Store config file in a sane place on OSX
confdir = os.path.join(os.environ['HOME'], "Library", "Preferences", "org.killertux.wowaddonupdater")
if(not os.path.exists(confdir) ):
os.makedirs(confdir)
self.modspkl = os.path.join(confdir, self.modspkl)
self.confpkl = os.path.join(confdir, self.confpkl)
self.filepkl = os.path.join(confdir, self.filepkl)
else:
self.defaults['wowdir'] = ""
self.loadConfig()
self.startmutex.unlock()
return True
def __del__(self):
self.saveConfig()
def log(self, str):
'''
Logs str to the self.loglines variable for later user
'''
self.loglines.append(str)
def out2(self, str):
'''
Minor output message
'''
self.log("**" + str)
def error(self, str):
'''
Minor output message
'''
self.log("**" + str)
self.errors.append(str)
def out(self, str, nolog = 0):
'''
Output message logged by default, notlogged if nolog=1
'''
if nolog == 0:
self.log("*" + str)
def gauge(self, i, max):
'''
This is a skeleton function used in UIs
'''
pass
def getoption(self, name, default = True):
'''
Returns an option specified in name
'''
if not self.config.has_key( name ):
if not self.defaults.has_key( name ) or not default:
return None
else:
#print self.defaults[name]
return self.defaults[name]
else:
#print self.config[name]
return self.config[name]
def setoption(self, name, value):
'''
Sets an option specified in name to value
'''
self.config[name] = value
def loadConfig(self):
'''
Loads configuration form the config file
'''
if not self.progmutex.testandset():
return False
self.mods = []
self.config = {}
self.files = {}
if os.path.exists(self.modspkl) and os.path.getsize(self.modspkl) > 0 :
self.mods = pickle.load(open(self.modspkl))
for m in self.mods:
m.setUpdater(self)
if os.path.exists(self.confpkl) and os.path.getsize(self.confpkl) > 0 :
self.config = pickle.load(open(self.confpkl))
if os.path.exists(self.filepkl) and os.path.getsize(self.filepkl) > 0 :
self.files = pickle.load(open(self.filepkl))
self.updateConfig()
self.progmutex.unlock()
def saveConfig(self):
'''
Saves current state to the config files
'''
#print "saveConfig()"
modspkl = open(self.modspkl, 'wb')
confpkl = open(self.confpkl, 'wb')
filepkl = open(self.filepkl, 'wb')
pickle.dump(self.mods, modspkl)
pickle.dump(self.config, confpkl)
pickle.dump(self.files, filepkl)
modspkl.close()
confpkl.close()
filepkl.close()
#self.progmutex.unlock()
def fullClean(self):
'''
Cleans installed files and zip files
'''
for m in self.mods:
m.cleaninst()
m.cleanzip()
ifacedir = os.path.join(self.getoption('wowdir'), "Interface");
#if os.path.exists(ifacedir):
# shutil.rmtree(ifacedir, True)
if os.path.exists(self.getoption('zipdir')):
shutil.rmtree(self.getoption('zipdir'), True)
self.saveConfig()
def getModType(self, name):
'''
Retuns the type of a mod specified by name
'''
return wowaddon.getModType(name)
def getModTypes(self):
'''
Returns all possible mod types
'''
return wowaddon.getModTypes()
def addMod(self, type, args):
'''
Used by a plugin to announce itself to the class
'''
self.mods.insert( 0, type(self, args) )
def upMod(self, n):
'''
Moves mod n up one in the queue
'''
if n > 0:
tmp = self.mods[n]
self.mods[n] = self.mods[n - 1]
self.mods[n - 1] = tmp
#print self.mods
def downMod(self, n):
'''
Moves mod n down one in the queue
'''
if (n + 1) < len(self.mods):
tmp = self.mods[n]
self.mods[n] = self.mods[n + 1]
self.mods[n + 1] = tmp
#print self.mods
def delMod(self, n):
'''
Deletes the mod from the queue and cleans the zip files and such up
'''
self.mods[n].cleanzip()
self.mods[n].cleaninst()
del self.mods[n]
#print self.mods
def initialize(self):
'''
Initialize the program at run time
'''
self.errors = []
ifacedir = os.path.join(self.getoption("wowdir"), "Interface")
zipdir = self.getoption("zipdir")
try:
if(not os.path.isdir(ifacedir) and not os.path.exists(ifacedir)):
os.makedirs(ifacedir)
if(not os.path.isdir(zipdir)):
os.makedirs(zipdir)
except OSError:
self.error("Could not make/create Interface dir")
#raise FileError
def run(self):
'''
This does everything, updates and install mods
'''
if not self.progmutex.testandset() or self.startmutex.test():
return False
self.out2("Starting....")
#self.setoption("ifacedir", "iface")
steps = 6
total = len(self.mods )*steps
i = 0
self.initialize()
for m in self.mods:
try:
name = m.getname()
#name = m.name
except:
name = m.name
self.out2("Checking %s ..." % name)
try:
notok = True
if self.getoption('verify') == True:
notok = m.verify()
if not m.isuptodate() or not notok:
try:
i+=1; self.gauge(i, total)
self.out2("Cleaning up zipfile for %s ..." % name)
m.cleanzip()
i+=1; self.gauge(i, total)
except FileError, e:
self.error("Error cleaning zipfile for %s: %s." % (name, e))
continue
try:
self.out2("Updating %s ..." % name)
m.update()
i+=1; self.gauge(i, total)
except wowaddon.DownloadError, e:
self.error("Error on updating version for %s: %s %s." % (name, e.__class__, e) )
continue
try:
self.out2("Cleaning up old install files for %s ..." % name)
m.cleaninst()
i+=1; self.gauge(i, total)
except wowaddon.FileError, e:
self.error("Error cleaning old install files for %s: %s." % (name, e))
continue
try:
self.out2("Unzipping %s ..." % name)
m.unzip()
i+=1; self.gauge(i, total)
except wowaddon.FileError, e:
self.error("Error unzipping %s: %s." % (name, e))
continue
try:
self.out2("Copying %s ..." % name)
m.copy()
self.saveConfig()
i+=1; self.gauge(i, total)
except wowaddon.FileError, e:
self.error("Error copying %s: %s." % (name, e))
continue
else:
self.out2("%s is up to date." % name)
i+=steps; self.gauge(i, total)
except (ParseError, DownloadError), e:
self.error("Error on checking version for %s: %s %s." % (name, e.__class__, e) )
continue
self.out2("Done.")
self.out("Done.")
self.progmutex.unlock()
return
def abort(self):
'''
Not used at the moment
'''
# Method for use by main thread to signal an abort
self._want_abort = 1
def updateConfig(self):
'''
Function called at runtime to initialize saved values
'''
if self.config == {}:
pver = self.getoption('version')
else:
pver = self.getoption('version', False)
if pver == None:
pver = 1
if pver == 1:
pver += 1
if pver == 2:
self.mods = []
pver += 1
if pver == 3:
self.setoption("verify", True)
pver += 1
self.setoption("version", pver)
self.saveConfig()
# def registerFile(self, file, mod):
# if not files.has_key(file):
# files[file] = 1
# def unregisterFile(self, file, mod):
# if not files.has_key(file):
# files[file] = 0
if __name__ == "__main__":
pass