views:

184

answers:

2

Is it possible to open a file on GAE just to read its contents and get the last modified tag?

I get a IOError: [Errno 13] file not accessible: I know that i cannot delete or update but i believe reading should be possible Has anyone faced a similar problem?

os.stat(f,'r').st_mtim
A: 

You can read files, but they're on Goooogle's wacky GAE filesystem so you have to use a relative path. I just whipped up a quick app with a main.py file and test.txt in the same folder. Don't forget the 'e' on st_mtime.

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util


class MainHandler(webapp.RequestHandler):

  def get(self):
    path = os.path.join(os.path.split(__file__)[0], 'test.txt')

    self.response.out.write(os.stat(path).st_mtime)


def main():
  application = webapp.WSGIApplication([('/', MainHandler)],
                                       debug=True)
  util.run_wsgi_app(application)


if __name__ == '__main__':
  main()
MStodd
There's nothing unusual about file access for apps except the unavailability of static files.
Nick Johnson
+3  A: 

You've probably declared the file as static in app.yaml. Static files are not available to your application; if you need to serve them both as static files and read them as application files, you'll need to include 2 copies in your project (ideally using symlinks, so you don't actually have to maintain an actual copy.)

Wooble
how can i use symblinks in GAE environment ?
PanosJee
You create the symlinks in your local copy; the files will actually be copied twice to App Engine: once to the static file servers and once to the application servers. You can also include external packages by symlinking your local copies to your application directory rather than copying the whole package to each project that uses it.
Wooble
that was an awesome tip!thanx!
PanosJee