*** .wine/drive_c/World of Warcraft/Interface/AddOns/wowace.py	Tue Apr  1 11:33:29 2008
--- .wine/drive_c/World of Warcraft/Interface/AddOns/wowace.schmidt.py.txt	Thu Apr  3 12:12:06 2008
***************
*** 11,16 ****
--- 11,17 ----
  import platform
  import urllib2
  import gzip
+ import time
  from StringIO import StringIO
  from optparse import OptionParser
  from xml.dom.minidom import parse
***************
*** 22,28 ****
  __copyright__ = 'Copyright (c) 2007 David Lynch'
  __license__ = 'New BSD License'
  
! default_wowdir = False #Change this to, e.g. "F://World of Warcraft//Interface//Addons' if your wow directory is in a nonstandard location.
  default_wowace = 'http://files.wowace.com/'
  default_externals = False
  
--- 23,29 ----
  __copyright__ = 'Copyright (c) 2007 David Lynch'
  __license__ = 'New BSD License'
  
! default_wowdir = '/home/derek/wow/adds/' #Change this to, e.g. "F://World of Warcraft//Interface//Addons' if your wow directory is in a nonstandard location.
  default_wowace = 'http://files.wowace.com/'
  default_externals = False
  
***************
*** 56,67 ****
          self.session = {}
          self.refresh()
  
!     def refresh(self):
!         """Refetch the local and remote addon listings."""
          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.
  
--- 57,95 ----
          self.session = {}
          self.refresh()
  
!     def refresh(self): #Refetch the local and remote addon listings.
!         self.local_index = urlparse.urljoin(self.wowdir, self.externals and 'latest.xml' or 'latest-noext.xml')    # appears to be two arguments, but i can't unpack it as two ~_~
!         self.server_index = urlparse.urljoin(self.wowace, self.externals and 'latest.xml' or 'latest-noext.xml')
!         self.current_date = time.clock()
! #        if not os.path.exists(self.local_index):
! #              self.local = file(self.local_index, 'w')
! #              self.local =
! #              self.local.close()
!         self.latest_date = os.path.exists(self.local_index) and os.path.getsize(self.local_index) > 0 and os.path.getmtime(self.local_index) or self.current_date - 601	# attempt at getting and comparing the date of the latest file
!         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_index, self.server_index))
!               self.get_remote_index(self.local_index, self.server_index)
!         else:
!               logging.info('Local index %s is newer than 10 minutes. Using this data.' % self.local_index)
! 
          self.localaddons = self.get_local_addons()
          self.remoteaddons = self.get_remote_addons()
          self.session.clear()
  
+     def get_remote_index(self, url_local, url_remote): # to update the local index file from the server
+         logging.info('Downloading index.')
+ #        logging.info('nonsense parameter: %s' % nonsense)     # for some reason I get some nonsense data here
+         logging.info('url_local: %s' % url_local)
+         logging.info('url_remote: %s' % url_remote)
+         request = urllib2.Request(url_remote)
+         #request.add_header('Accept-encoding', 'gzip')	# i doubt this is needed
+         request.add_header('User-agent', USER_AGENT)
+         self.local = file(url_local, 'w')
+         f = urllib2.urlopen(request)
+         self.local = StringIO(f.read())
+         f.close()
+         self.local.close()
+ 
      def update_addon(self, name, get_deps = True, unpackage = False, script = False, delete_old = True, force = False, optimize = False):
          """Update an addon.
  
***************
*** 226,237 ****
          return addons
  
      def get_remote_addons(self):
!         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)
!         logging.info('Done processing new addon list.')
          return addons
  
      def save_local_addons(self):
--- 254,264 ----
          return addons
  
      def get_remote_addons(self):
!         #feed = urlparse.urljoin(self.wowace, self.externals and 'latest.xml' or 'latest-noext.xml')
!         logging.info('Checking feed for updated addons')
!         addons = waFeed(_fetch(self.local_index)).addons
          if len(addons)==0:
!             logging.warning('No addons found in index')
          return addons
  
      def save_local_addons(self):
***************
*** 391,405 ****
              os.chmod(dest, permissions)
  
  def _fetch(url):
!     #logging.info('Requesting.')
      request = urllib2.Request(url)
      request.add_header('Accept-encoding', 'gzip')
      request.add_header('User-agent', USER_AGENT)
      f = urllib2.urlopen(request)
!     #logging.info('Downloading.')
      data = StringIO(f.read())
-     #logging.info('Done with the download.')
      f.close()
      if f.headers.get('content-encoding', '') == 'gzip':
          data = gzip.GzipFile(fileobj=data)
      return data
--- 418,436 ----
              os.chmod(dest, permissions)
  
  def _fetch(url):
!     logging.info('url: %s' % url)
!     if url.startswith('/'):
!         f = file(url)
!         request = False
!     else:
          request = urllib2.Request(url)
          request.add_header('Accept-encoding', 'gzip')
          request.add_header('User-agent', USER_AGENT)
          f = urllib2.urlopen(request)
! #    logging.info('f: ' % f)
      data = StringIO(f.read())
      f.close()
+     if request:
          if f.headers.get('content-encoding', '') == 'gzip':
              data = gzip.GzipFile(fileobj=data)
      return data
***************
*** 427,442 ****
      s = platform.system()
      if s == 'Windows':
          return os.path.join(os.environ['PROGRAMFILES'], 'World of Warcraft\\Interface\\Addons')
!     elif s == 'Darwin':
!         #macosx
          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'
  
  def get_scripts(path):
      s = platform.system()
--- 458,478 ----
      s = platform.system()
      if s == 'Windows':
          return os.path.join(os.environ['PROGRAMFILES'], 'World of Warcraft\\Interface\\Addons')
!     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.
+         # 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()
