--- wowace-orig.py	2008-03-31 11:29:58.212818511 -0400
+++ wowace.py	2008-03-31 17:12:50.330527109 -0400
@@ -11,6 +11,7 @@
 import platform
 import urllib2
 import gzip
+import time
 from StringIO import StringIO
 from optparse import OptionParser
 from xml.dom.minidom import parse
@@ -47,24 +48,33 @@
         else:
             # I might want to do something else here -- not sure.
             pass
-        
+
         self.batchupdating = False
-        
+
         self.wowdir = wowdir
         self.wowace = wowace
         self.externals = externals
         self.session = {}
         self.refresh()
-    
+
     def refresh(self):
         """Refetch the local and remote addon listings."""
+	   self.local_file = urlparse.urljoin(self.wowdir, self.externals and 'latest.xml' or 'latest-noext.xml')
+	   self.server_file = urlparse.urljoin(self.wowace, self.externals and 'latest.xml' or 'latest-noext.xml')
+	   self.latest_date = os.stat.st_size(self.local_file)	# attempt at getting and comparing the date of the latest file
+	   self.current_date = time.localtime()
+	   if self.current_date - self.latest_date > 600:	#if it's 10 minutes or older
+		    logging.info('Local index %s is older than 10 minutes. Fetching updated index %s to replace it.' % (self.local_file, self.server_file))
+		    # don't know how to write it, but update local_file to be equivalent to server_file
+
+	   feed = self.local_file
         self.localaddons = self.get_local_addons()
         self.remoteaddons = self.get_remote_addons()
         self.session.clear()
-    
+
     def update_addon(self, name, get_deps = True, unpackage = False, script = False, delete_old = True, force = False, optimize = False):
         """Update an addon.
-        
+
         Required arguments:
         name -- name of the addon to update
 
@@ -75,7 +85,7 @@
             potentially dangerous than unpackaging (default False)
         delete_old -- whether to delete the old addon directory before extracting the new one (default True)
         force -- whether to redownload the addon even if there isn't a new version (default False)
-        
+
         If the addon directory contains '.svn' or '.ignore', nothing will be done.
         If the addon requested is not already installed, install it.
         save_local_addons will be called unless self.batchupdating == True.
@@ -111,18 +121,18 @@
                     os.chdir(os.path.join(self.wowdir, name))
                     for s in get_scripts('.'):
                         os.system(os.path.join('.', s))
-                
+
                 if optimize:
                     # Comment out files that are missing in the .toc (speed reasons):
                     toc = TocFile(os.path.join(self.wowdir, name, name+'.toc'))
                     toc.comment_missing_files()
                     toc.save()
-                
+
                 self.save_local_addons()
                 self.session[name] = True
             else:
                 logging.warning("Upgrade failed!  Problem fetching/reading file.")
-    
+
     def update_all(self, get_deps = True, unpackage = False, script = False, delete_old = True, force = False, optimize = False):
         """Update all addons"""
         self.batchupdating = True # Avoid pointlessly writing to disk on every update.
@@ -130,10 +140,10 @@
             self.update_addon(addon, get_deps, unpackage, script, delete_old, force, optimize)
         self.batchupdating = False
         self.save_local_addons()
-    
+
     def addon_can_be_updated(self, name, force = False):
         """Checks whether an addon can be updated
-        
+
         If force evaluates to True, this will return True regardless of the local and remote versions.
         This will ALWAYS return False if there's a .ignore or .svn path in the addon, or if the addon can't be found on the server.
         This will also always return False if an addon has already been updated this session.  (This is to avoid repeatedly downloading dependencies when using force.)
@@ -144,15 +154,15 @@
         new_version = self.remoteaddons[name]['version']
         if force or old_version != new_version:
             return True
-    
+
     def addons_to_be_updated(self, force = False):
         addons = self.localaddons.keys()
         addons.sort() # This is functionally unnecessary... but it looks nicer on the output.
         return [addon for addon in addons if self.addon_can_be_updated(addon, force)]
-    
+
     def unpackage_addon(self, name):
         """Follow the instructions in filelist.wau to unpackage an addon.
-        
+
         See http://wowace.com/wiki/WowAceUpdater#The_Package_System for details of the package system.
         """
         if os.path.exists(os.path.join(self.wowdir, name+'.nounpack')):
@@ -180,7 +190,7 @@
             filelist_file.close()
             self.batchupdating = False
             self.save_local_addons()
-    
+
     def remove_addon(self, name):
         """Delete an addon, and remove its version information from localaddons."""
         path = os.path.join(self.wowdir, name)
@@ -189,7 +199,7 @@
             del(self.localaddons[name])
             self.save_local_addons()
             logging.info("Removing %s" % name)
-    
+
     def get_local_addons(self):
         logging.info("Loading local addons")
         if os.path.exists(os.path.join(self.wowdir, 'addon_versions.pkl')):
@@ -224,21 +234,21 @@
                         break
             addons[addon] = version
         return addons
-    
+
     def get_remote_addons(self):
-        feed = urlparse.urljoin(self.wowace, self.externals and 'latest.xml' or 'latest-noext.xml')
+#	   feed = urlparse.urljoin(self.wowace, self.externals and 'latest.xml' or 'latest-noext.xml')
         logging.info('Checking %s for updated addons' % feed)
         addons = waFeed(_fetch(feed)).addons
         if len(addons)==0:
             logging.warning('No addons found at %s' % feed)
         return addons
-    
+
     def save_local_addons(self):
         if not self.batchupdating:
             pickled_versions = open(os.path.join(self.wowdir, 'addon_versions.pkl'), 'wb')
             cPickle.dump(self.localaddons, pickled_versions)
             pickled_versions.close()
-    
+
     def _real_dependency(self, name):
         # First, just return the addon name if the addon exists.
         if name in self.remoteaddons:
@@ -285,17 +295,17 @@
 
 class TocFile:
     """Read and write World of Warcraft .toc files.
-    
+
     """
     remeta = re.compile(r'^.*##\s*([^:\s]+)\s*:\s*(.+)\s*$')
-    
+
     def __init__(self, filename):
         self.filename = filename
         self.meta = {}
         self.files = []
         self.parse()
         self.dirty = False
-    
+
     def parse(self):
         f = open(self.filename, 'r')
         for line in f.readlines():
@@ -308,7 +318,7 @@
                 else:
                     self.files.append(line.strip())
         f.close()
-    
+
     def save(self):
         if self.dirty:
             f = open(self.filename, 'w')
@@ -317,14 +327,14 @@
             for i in self.files:
                 f.write(i+'\n')
             f.close()
-    
+
     def comment_missing_files(self):
         d = os.path.dirname(self.filename)
         for f in self.files:
             if not os.path.exists(os.path.join(d, f.replace('\\', os.path.sep))):
                 self.dirty = True
                 self.files[self.files.index(f)] = '#'+f
-    
+
     def fix_optdeps(self):
         pass
 
@@ -378,9 +388,9 @@
             directory = os.path.normpath(os.path.join(path, root))
             if not os.path.isdir(directory):
                 os.makedirs(directory)
-            
+
             dest = os.path.join(directory, name)
-            
+
             nf = file(dest, 'wb')
             nf.write(zip.read(f))
             nf.close()
@@ -409,7 +419,7 @@
 def _removedir(path):
     if not os.path.isdir(path):
         return
-    
+
     for x in os.listdir(path):
         fullpath=os.path.join(path, x)
         if os.path.isfile(fullpath):
@@ -423,16 +433,21 @@
     s = platform.system()
     if s == 'Windows':
         return os.path.join(os.environ['PROGRAMFILES'], 'World of Warcraft\\Interface\\Addons')
-    elif s == 'Darwin':
-        #macosx
+    elif s == 'Darwin':	# mac os x
         userdir = os.path.expanduser('~/Applications/World of Warcraft/Interface/Addons')
         if os.path.exists(userdir):
             return userdir
         else:
             return '/Applications/World of Warcraft/Interface/Addons'
-    else:
-        #We're screwed. Return a best guess, which might, maybe, work for linux. Though probably not.
-        return '/usr/local/games/World of Warcraft/Interface/Addons'
+    else:		# We're screwed. Return a best guess, which might, maybe, work for linux. Though probably not.
+	   # If installed from wine, running from the same user's directory, it will likely be the following:
+	   userdir = os.path.expanduser('~/.wine/drive_c/World of Warcraft/Interface/AddOns')
+        if os.path.exists(userdir):
+		  return userdir
+	   else:
+		  return '/usr/share/games/World of Warcraft'
+	   # If using an installation on a MS Windows partition, it of course would be under that mount location:
+	   #return '/mnt/win/World of Warcraft/Interface/AddOns'	# or some such -- it'll be different for every system
 
 def get_scripts(path):
     s = platform.system()
