def testGetNamespaces(self): """Test for get_namespaces.""" self.assertEqual(['', 'fun', 'ns1'], metadata.get_namespaces()) self.assertEqual(['fun', 'ns1'], metadata.get_namespaces('a')) self.assertEqual(['', 'fun'], metadata.get_namespaces('', 'g')) self.assertEqual(['fun'], metadata.get_namespaces('f', 'g')) self.assertEqual([], metadata.get_namespaces('f', ''))
def send_daily_birthday_messages(): """ It goes through all the namespaces making queries to the datastore for users who have the same birth day and birth month as today """ today = datetime.now() current_namespace = namespace_manager.get_namespace() for namespace in get_namespaces(): # Forget about the default empty namespace if namespace: logging.debug("Birthdays for today [%s]-[%s] namespace [%s]", today.month, today.day, namespace) namespace_manager.set_namespace(namespace) #Clear the cached list for the day memcache.delete('birthdays') #Go through every birthday celebrant for celebrant in get_birthdays(month=today.month, day=today.day): logging.info("Found a birthday for today! %s", celebrant.email) #Schedule sending the email deferred.defer(send_birthday_message, celebrant, _queue="mail-queue") #Restore to the original namespace namespace_manager.set_namespace(current_namespace) return 'Birthday messages were scheduled for today'
def delete_all_entities(): for namespace in get_namespaces(): set_namespace(namespace) for kind in get_kinds(): if kind.startswith('__'): continue while True: data = Query(kind=kind, keys_only=True).Get(200) if not data: break Delete(data)
def delete_all_entities(): from google.appengine.api.datastore import Delete, Query from google.appengine.ext.db.metadata import get_kinds, get_namespaces from google.appengine.api.namespace_manager import set_namespace for namespace in get_namespaces(): set_namespace(namespace) for kind in get_kinds(): if kind.startswith('__'): continue while True: data = Query(kind=kind, keys_only=True).Get(200) if not data: break Delete(data)
def delete_all_entities(): from google.appengine.api.datastore import Delete, Query from google.appengine.ext.db.metadata import get_kinds, get_namespaces from google.appengine.api.namespace_manager import set_namespace for namespace in get_namespaces(): set_namespace(namespace) for kind in get_kinds(): if kind.startswith('__'): continue while True: data = Query(kind=kind, keys_only=True).Get(200) if not data: break Delete(data)
def select_namespaces2run(): return get_namespaces()