Skip to content

Commit

Permalink
Merge 41e2644 into c9e195e
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte committed Feb 15, 2016
2 parents c9e195e + 41e2644 commit 70e0221
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tg/util/files.py
@@ -1,6 +1,6 @@
import os
import os, sys
import re
from pkg_resources import resource_filename
from pkg_resources import resource_filename, resource_stream, get_default_cache
from .._compat import unicode_text, PY2


Expand Down Expand Up @@ -28,7 +28,7 @@ def get_dotted_filename(self, template_name, template_extension='.html'):
Given a string containing the file/template name passed to the @expose
decorator we will return a resource useable as a filename even
if the file is in fact inside a zipped egg.
if the file is in fact inside a zipped egg or in a frozen library.
The actual implementation is a revamp of the Genshi buffet support
plugin, but could be used with any kind a file inside a python package.
Expand Down Expand Up @@ -59,6 +59,18 @@ def get_dotted_filename(self, template_name, template_extension='.html'):
result = resource_filename(package, basename)
except ImportError as e:
raise DottedFileLocatorError(str(e) +". Perhaps you have forgotten an __init__.py in that folder.")
except NotImplementedError as e:
if not hasattr(self, '__temp_dir'):
executable = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0]
#only on windows substitute \\ to - to avoid long pathnames and preserve the structure
executable = os.path.abspath(executable).replace(':', '').replace('\\', '-')
self.__temp_dir = os.path.join(get_default_cache(), executable)
result = os.path.join(self.__temp_dir, package, basename)
if not os.path.isdir(os.path.dirname(result)):
os.makedirs(os.path.dirname(result))
rd = resource_stream(package, basename)
open(result, 'wb').write(rd.read())
rd.close()
else:
result = template_name

Expand Down

0 comments on commit 70e0221

Please sign in to comment.