Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: examples/games/scummvm/nacl-scumm/AppEngineMount.py

Issue 37213005: Update scummvm to 1.6.0, also make it a packaged app. (Closed) Base URL: https://naclports.googlecode.com/svn/trunk/src
Patch Set: . Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « examples/games/scummvm/nacl.patch ('k') | examples/games/scummvm/nacl-scumm/README » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 """
2 Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 """
6
7 import cgi
8 import datetime
9 import urllib
10 import wsgiref.handlers
11 import os
12 import logging
13
14 from google.appengine.ext import db
15 from google.appengine.api import users
16 from google.appengine.ext import webapp
17 from google.appengine.ext.webapp.util import run_wsgi_app
18 from google.appengine.ext.webapp import template
19 from google.appengine.ext.webapp import Request
20 from google.appengine.ext.db import Key
21
22
23 """
24 This script is an example server backend for use with the App Engine
25 mount type in nacl-mounts.
26 """
27
28
29 class File(db.Model):
30 owner = db.UserProperty()
31 filename = db.StringProperty()
32 data = db.BlobProperty()
33
34
35 class MainPage(webapp.RequestHandler):
36 def get(self):
37 # Require the user to login.
38 user = users.get_current_user()
39 if not user:
40 self.redirect(users.create_login_url(self.request.uri))
41 return
42
43 template_values = {
44 }
45 path = os.path.join(os.path.dirname(__file__), 'index.html')
46 self.response.out.write(template.render(path, template_values))
47
48
49 def FileKey(filename, user):
50 if not user:
51 u_id = -1
52 else:
53 u_id = user.user_id()
54 return Key.from_path('File', '%s_%s' % (filename, u_id))
55
56
57 class FileHandlingPage(webapp.RequestHandler):
58 def post(self):
59 user = users.get_current_user()
60
61 split = self.request.path.rsplit('/', 1)
62 assert (len(split) > 1)
63 method = split[1]
64
65 self.response.headers['Content-Type'] = 'application/octet-stream'
66
67 if method == 'read':
68 filename = self.request.get(u'filename')
69 assert filename
70 k = FileKey(filename, user)
71 f = File.get(k)
72 if f:
73 self.response.out.write(f.data)
74 self.response.out.write('1')
75 else:
76 self.response.out.write('0')
77
78 elif method == 'write':
79 self.response.out.write('1')
80 data = self.request.get(u'data')
81 filename = self.request.get(u'filename')
82 assert filename
83 assert data
84 def create_or_update(filename, data, owner):
85 k = FileKey(filename, user)
86 f = File.get(k)
87 if not f:
88 f = File(key=k)
89 f.owner = owner
90 f.filename = filename
91 f.data = data
92 return f
93
94 f = db.run_in_transaction(create_or_update, filename, data, user)
95
96 def db_put(file):
97 f.put()
98
99 db.run_in_transaction(db_put, f)
100
101 elif method == 'list':
102 prefix = self.request.get(u'prefix')
103 assert prefix
104 # First make sure that the file is there
105 k = FileKey(prefix, user)
106 f = File.get(k)
107 if not f:
108 return
109 q = File.all()
110 q.filter('owner =', user)
111 q.filter('filename >', prefix)
112 q.filter('filename <', prefix + u'ffff')
113 prefixslash = prefix
114 if prefixslash[-1] != '/':
115 prefixslash += '/'
116 depth = len(prefixslash.split('/'))
117 results = q.fetch(limit=100)
118 for r in results:
119 # make sure the file is directly under prefixslash
120 if len(r.filename.split('/')) != depth:
121 continue
122 self.response.out.write('%s\n' % r.filename)
123
124 elif method == 'remove':
125 filename = self.request.get(u'filename')
126 assert filename
127 k = FileKey(filename, user)
128 try:
129 db.delete(k)
130 self.response.out.write('1')
131 except:
132 self.response.out.write('0')
133 return
134
135 else:
136 assert False
137
138
139 application = webapp.WSGIApplication([
140 ('/', MainPage),
141 ('/_file/.*', FileHandlingPage),
142
143 ], debug=True)
144
145
146 def main():
147 run_wsgi_app(application)
148
149
150 if __name__ == '__main__':
151 main()
OLDNEW
« no previous file with comments | « examples/games/scummvm/nacl.patch ('k') | examples/games/scummvm/nacl-scumm/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698