Commits

Kirill Simonov committed 0da4c0e

tweak.resource: unpack remote resources into $HOME instead of $TEMP.

  • Participants
  • Parent commits 9bd7cab

Comments (0)

Files changed (2)

File src/htsql_tweak/resource/__init__.py

 from . import wsgi, locate
 from htsql.addon import Addon, Parameter
 from htsql.validator import StrVal
+import threading
 
 
 class TweakResourceAddon(Addon):
             Parameter('indicator', StrVal(r'^[/]+$'), default='-'),
     ]
 
+    def __init__(self, app, attributes):
+        super(TweakResourceAddon, self).__init__(app, attributes)
+        self.lock = threading.Lock()
 
+

File src/htsql_tweak/resource/locate.py

 #
 
 
+from __future__ import with_statement
+from htsql.context import context
 from htsql.util import maybe
 from htsql.adapter import Protocol, named
 import mimetypes
 import os, os.path
 import cStringIO
 import zipfile
-import tempfile
 import urllib2
 import pkg_resources
 
         self.init_repository()
 
     def init_repository(self):
-        tempdir = tempfile.gettempdir()
-        staticdir = os.path.join(tempdir, '.htsql.%s' % os.getuid())
-        if not os.path.exists(staticdir):
-            os.mkdir(staticdir, 0700)
+        userdir = os.path.expanduser('~')
+        staticdir = os.path.join(userdir, '.htsql.shared')
         resourcedir = os.path.join(staticdir, 'resource')
-        if not os.path.exists(resourcedir):
-            os.mkdir(resourcedir)
         cachedir = os.path.join(resourcedir, '%s.%s' % (self.cache, self.md5))
         if not os.path.exists(cachedir):
-            self.init_cache(cachedir)
+            addon = context.app.tweak.resource
+            with addon.lock:
+                if not os.path.exists(staticdir):
+                    os.mkdir(staticdir, 0700)
+                if not os.path.exists(resourcedir):
+                    os.mkdir(resourcedir)
+                if not os.path.exists(cachedir):
+                    self.init_cache(cachedir)
         self.repository = cachedir
 
     def init_cache(self, cachedir):