@@ -0,0 +1,2501 @@
+#!/usr/bin/python2.4%0A#%0A# Copyright 2009 Google Inc.%0A#%0A# Licensed under the Apache License, Version 2.0 (the 'License')%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an 'AS IS' BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%0A%22%22%22Bulk datastore changes.%22%22%22%0A%0A__author__ = 'slamm@google.com (Stephen Lamm)'%0A%0Aimport getopt%0Aimport getpass%0Aimport os%0Aimport simplejson%0Aimport sys%0A%0ADIR_PATH = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))%0Asys.path.append('%25s/..' %25 DIR_PATH)%0Afrom appengine_tools import appengine_rpc%0A%0AUPDATER_URL_PATH = '/admin/update_result_parents'%0A%0Aclass ResultUpdater(object):%0A  def __init__(self, host, path, user, bookmark=None):%0A    self.path = path%0A    self.user = user%0A    user_agent = None%0A    # TODO: figure out a value for 'source'.%0A    #   Doc says, %22The source to specify in authentication requests.%22%0A    source = ''%0A    self.rpc_server = appengine_rpc.HttpRpcServer(%0A        host, self.GetCredentials, user_agent, source, save_cookies=True)%0A%0A  def GetCredentials(self):%0A    # TODO: Grab email/password from config%0A    return self.user, getpass.getpass('Password for %25s: ' %25 self.user)%0A%0A  def Send(self, bookmark, total_scanned, total_updated):%0A    response_data = self.rpc_server.Send(self.path, simplejson.dumps(%0A        (bookmark, total_scanned, total_updated)))%0A    return simplejson.loads(response_data)%0A%0Adef main(argv):%0A  options, args = getopt.getopt(%0A      argv%5B1:%5D,%0A      'h:u:',%0A      %5B'host=', 'gae_user='%5D)%0A  host = None%0A  gae_user = None%0A  for option_key, option_value in options:%0A    if option_key in ('-h', '--host'):%0A      host = option_value%0A    elif option_key in ('-u', '--gae_user'):%0A      gae_user = option_value%0A%0A  updater = ResultUpdater(host, UPDATER_URL_PATH, user=gae_user)%0A  bookmark = None%0A  total_scanned = 0%0A  total_updated = 0%0A  while 1:%0A    print 'Update batch: %25s (total_scanned=%25s, total_updated=%25s)' %25 (%0A        bookmark or 'no_bookmark', total_scanned, total_updated)%0A    bookmark, total_scanned, total_updated = updater.Send(%0A        bookmark, total_scanned, total_updated)%0A    if not bookmark:%0A      break%0A%0A%0Aif __name__ == '__main__':%0A  main(sys.argv)%0A

Add a client to migrate from ResultParent.user_agent_list to ResultParent.user_agent_pretty