Re: Absolute path for static assets/ Get file modified time

2011-11-16 Thread Michael Merickel
You will need to use the pkg_resources api from the Python stdlib.
Currently (this will be fixed in 1.3) there is no public API for computing
paths.

import pkg_resources

asset_path = 'mypackage:static/favicon.ico'
package, file = asset_path.split(':', 1)
abs_path = pkg_resources.resource_filename(package, file)
last_access_time = os.stat(abs_path)[8]

On Wed, Nov 16, 2011 at 3:55 PM, Jay T jay.pyl...@gmail.com wrote:

  How do I get the absolute path for static assets ? The reason I need the
 absolute path is to determine the last modified time of a specific file so
 I can append it to my static resources like JS and CSS files.
 I wrote a Mako template def like this but it fails at : here =
 os.path.dirname(__file__)

 %def name=appendFileModifiedTime(**path)
 %
fmTime = -1
import os
here = os.path.dirname(__file__)
path = os.path.join(here,path)
if os.path.exists(path):
fmTime = os.stat(path)[8]
else:
fmTime = -999

path = path +'?%s'%fmTime

return path
 %
 /%def

 Thanks,
 Jay

 --
 You received this message because you are subscribed to the Google Groups
 pylons-discuss group.
 To post to this group, send email to 
 pylons-discuss@googlegroups.**compylons-discuss@googlegroups.com
 .
 To unsubscribe from this group, send email to pylons-discuss+unsubscribe@*
 *googlegroups.com pylons-discuss%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/pylons-discuss?hl=enhttp://groups.google.com/group/pylons-discuss?hl=en
 .




-- 

Michael

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Absolute path for static assets/ Get file modified time

2011-11-16 Thread Jay T

 That worked. Thanks !

Jay

On 11/16/11 5:46 PM, Michael Merickel wrote:
You will need to use the pkg_resources api from the Python stdlib. 
Currently (this will be fixed in 1.3) there is no public API for 
computing paths.


import pkg_resources

asset_path = 'mypackage:static/favicon.ico'
package, file = asset_path.split(':', 1)
abs_path = pkg_resources.resource_filename(package, file)
last_access_time = os.stat(abs_path)[8]

On Wed, Nov 16, 2011 at 3:55 PM, Jay T jay.pyl...@gmail.com 
mailto:jay.pyl...@gmail.com wrote:


 How do I get the absolute path for static assets ? The reason I
need the absolute path is to determine the last modified time of a
specific file so I can append it to my static resources like JS
and CSS files.
I wrote a Mako template def like this but it fails at : here =
os.path.dirname(__file__)

%def name=appendFileModifiedTime(path)
%
   fmTime = -1
   import os
   here = os.path.dirname(__file__)
   path = os.path.join(here,path)
   if os.path.exists(path):
   fmTime = os.stat(path)[8]
   else:
   fmTime = -999

   path = path +'?%s'%fmTime

   return path
%
/%def

Thanks,
Jay

-- 
You received this message because you are subscribed to the Google

Groups pylons-discuss group.
To post to this group, send email to
pylons-discuss@googlegroups.com
mailto:pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to
pylons-discuss+unsubscr...@googlegroups.com
mailto:pylons-discuss%2bunsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.




--

Michael
--
You received this message because you are subscribed to the Google 
Groups pylons-discuss group.

To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.


--
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.