app/soc/logic/helper/convert_db.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 19 Apr 2009 17:42:44 +0000
changeset 2246 c29272f640b0
parent 2068 f5e8fbbd3bea
permissions -rw-r--r--
Tweak the 'load balancing' algorithm In order to reduce contention we randomly skipped jobs, but this caused many jobs to end up stopping early. Now instead we keep on going until we time out (also increased the chance of doing work). Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1603
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Converts the DB from an old scheme to a new one.
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from django import http
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from soc.models import user as user_model
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.logic import accounts
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic.models.user import logic as user_logic
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
def convert_user_accounts(*args, **kwargs):
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
  """Converts all current user accounts to normalized form.
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  """
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
  data = user_logic.getAll(user_model.User.all())
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
  for user in data:
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
    normalized = accounts.normalizeAccount(user.account)
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
    if user.account != normalized:
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
      user.account = normalized
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
      user.put()
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
ec08b2b00439 Add a script to normalize user accounts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  return http.HttpResponse('Done')