def update_addon(uid,wow_dir): """Downloads latest version of addon and extract it into wow directory. uid: Wow interface addon addon id wow_dir: Wow addon directory""" url = 'http://www.wowinterface.com/patcher/info-%d.xml' % uid dom = minidom.parse(urllib2.urlopen(url)) if dom.getElementsByTagName('error'): if int(dom.getElementsByTagName('id')[0].firstChild.nodeValue) == 403: print 'The file is still being checked by mods, update will be downloaded next time you run this script.' #This function shouldn't print. return False else: print 'Please give this info to the addon author: <%d> - %s' % (int(dom.getElementsByTagName('id')[0].firstChild.nodeValue), str(dom.getElementsByTagName('message')[0].firstChild.nodeValue)) return False file_location = str(dom.getElementsByTagName('UIFileURL')[0].firstChild.nodeValue) size = int(dom.getElementsByTagName('UISize')[0].firstChild.nodeValue) if size > 1048576: #If size is lager then 1mb print 'Downloading big file, this may take more then few seconds' #This function shouldn't print. This is just a workaround. Again. f = urllib2.urlopen(file_location) data = StringIO(f.read()) f.close() data = zipfile.ZipFile(data) addon_dirs = [] for f in data.namelist(): dir = str(f.split('/',1)[0]) if not (dir in addon_dirs): addon_dirs.append(dir) wuiup_removedir(os.path.join(wow_dir, dir)) wuiup_unzip(data,wow_dir) data.close() return True
def _dl_del_unzip(self, file_location): f = urllib2.urlopen(file_location) data = StringIO(f.read()) f.close() data = zipfile.ZipFile(data) addon_dirs = [] for f in data.namelist(): dir = str(f.split('/',1)[0]) if not (dir in addon_dirs): addon_dirs.append(dir) wuiup_removedir(os.path.join(self.wow_dir, dir)) wuiup_unzip(data,self.wow_dir) data.close()
def _extract_zip(self, input_content): input_zip = StringIO(input_content) input_zip = ZipFile(input_zip) return {name: input_zip.read(name) for name in input_zip.namelist()}