def app_cleanup(app, request): """Removes session, cache and error files Args: app(str): application name request: the global request object Returns: True if everything went ok, False otherwise """ r = True # Remove error files path = apath('%s/errors/' % app, request) if os.path.exists(path): for f in os.listdir(path): try: if not f.startswith('.'): os.unlink(os.path.join(path, f)) except IOError: r = False # Remove session files path = apath('%s/sessions/' % app, request) if os.path.exists(path): for f in os.listdir(path): try: if not f.startswith('.'): recursive_unlink(os.path.join(path, f)) except (OSError, IOError): r = False # Remove cache files path = apath('%s/cache/' % app, request) if os.path.exists(path): CacheOnDisk(folder=path).clear() for f in os.listdir(path): try: if not f.startswith('.'): recursive_unlink(os.path.join(path, f)) except (OSError, IOError): r = False return r
def test_CacheOnDisk(self): # defaults to mode='http' s = Storage({'application': 'admin', 'folder': 'applications/admin'}) cache = CacheOnDisk(s) self.assertEqual(cache('a', lambda: 1, 0), 1) self.assertEqual(cache('a', lambda: 2, 100), 1) cache.clear('b') self.assertEqual(cache('a', lambda: 2, 100), 1) cache.clear('a') self.assertEqual(cache('a', lambda: 2, 100), 2) cache.clear() self.assertEqual(cache('a', lambda: 3, 100), 3) self.assertEqual(cache('a', lambda: 4, 0), 4) # test singleton behaviour cache = CacheOnDisk(s) cache.clear() self.assertEqual(cache('a', lambda: 3, 100), 3) self.assertEqual(cache('a', lambda: 4, 0), 4) # test key deletion cache('a', None) self.assertEqual(cache('a', lambda: 5, 100), 5) # test increment self.assertEqual(cache.increment('a'), 6) self.assertEqual(cache('a', lambda: 1, 100), 6) cache.increment('b') self.assertEqual(cache('b', lambda: 'x', 100), 1)
def test_CacheOnDisk(self): # defaults to mode='http' s = Storage({'application': 'admin', 'folder': 'applications/admin'}) cache = CacheOnDisk(s) self.assertEqual(cache('a', lambda: 1, 0), 1) self.assertEqual(cache('a', lambda: 2, 100), 1) cache.clear('b') self.assertEqual(cache('a', lambda: 2, 100), 1) cache.clear('a') self.assertEqual(cache('a', lambda: 2, 100), 2) cache.clear() self.assertEqual(cache('a', lambda: 3, 100), 3) self.assertEqual(cache('a', lambda: 4, 0), 4) # test singleton behaviour cache = CacheOnDisk(s) cache.clear() self.assertEqual(cache('a', lambda: 3, 100), 3) self.assertEqual(cache('a', lambda: 4, 0), 4) # test key deletion cache('a', None) self.assertEqual(cache('a', lambda: 5, 100), 5) # test increment self.assertEqual(cache.increment('a'), 6) self.assertEqual(cache('a', lambda: 1, 100), 6) cache.increment('b') self.assertEqual(cache('b', lambda: 'x', 100), 1)
## register with janrain.com, write your domain:api_key in private/janrain.key from gluon.contrib.login_methods.rpx_account import use_janrain use_janrain(auth, filename='private/janrain.key') ######################################################################### ## Define your tables below (or better in another model file) for example ## ## >>> db.define_table('mytable',Field('myfield','string')) ## ## Fields can be 'string','text','password','integer','double','boolean' ## 'date','time','datetime','blob','upload', 'reference TABLENAME' ## There is an implicit 'id integer autoincrement' field ## Consult manual for more options, validators, etc. ## ## More API examples for controllers: ## ## >>> db.mytable.insert(myfield='value') ## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL) ## >>> for row in rows: print row.id, row.myfield ######################################################################### from gluon.cache import CacheOnDisk cache.disk = CacheOnDisk(request, folder='/var/tmp/myquery') db.define_table("mytable", Field("product"), Field("price")) if db(db.mytable).count() <= 0: items = {"Apples": 1.00, "Oranges": 2.00, "Bananas": 3.00} for k, v in items.iteritems(): db.mytable.insert(product=k, price=v)