author | Lennard de Rijk <ljvderijk@gmail.com> |
Wed, 30 Sep 2009 21:39:09 +0200 | |
changeset 2996 | 9a62e3cad4a8 |
parent 2973 | ba3f2522e8df |
child 2997 | a7cb53d213d7 |
permissions | -rw-r--r-- |
2973
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""The module conversion updates are defined in this module. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
] |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
from google.appengine.api.labs import taskqueue |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
from google.appengine.ext import db |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
from django.http import HttpResponse |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
|
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
30 |
from soc.logic.models.program import logic as program_logic |
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
31 |
from soc.tasks.helper import decorators |
2973
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
from soc.tasks.helper import error_handler |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
# batch size to use when going through the entities |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
DEF_BATCH_SIZE = 10 |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
def startUpdateWithUrl(request, task_url): |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
"""Spawns an update task for the given task URL. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
Args: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
request: Django Request object |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
task_url: The URL used to run this update task |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
Returns: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
True iff the new task is successfully added to the Task Queue API |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
""" |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
new_task = taskqueue.Task(url=task_url) |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
new_task.add() |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
return True |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
|
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
56 |
|
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
57 |
@decorators.iterative_task(program_logic) |
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
58 |
def runProgramConversionUpdate(request, entities, context, *args, **kwargs): |
2973
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
"""Appengine Task that converts Programs into GSoCPrograms. |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
61 |
Args: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
request: Django Request object |
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
63 |
entities: list of Program entities to convert |
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
64 |
context: the context of this task |
2973
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
""" |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
from soc.modules.gsoc.models.program import GSoCProgram |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
68 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
# get all the properties that are part of each Programs |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
program_model = program_logic.getModel() |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
71 |
program_properties = program_model.properties().keys() |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
73 |
# use this to store all the new GSoCPrograms |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
74 |
gsoc_programs = [] |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
75 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
for entity in entities: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
gsoc_properties = {} |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
for program_property in program_properties: |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
80 |
# copy over all the information from the program entity |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
gsoc_properties[program_property] = getattr(entity, program_property) |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
83 |
# create the new GSoCProgram entity and prepare it to be stored |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
84 |
gsoc_program_entity = GSoCProgram(key_name=entity.key().name(), **gsoc_properties) |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
85 |
gsoc_programs.append(gsoc_program_entity) |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
|
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
87 |
# store all the new GSoCPrograms |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
88 |
db.put(gsoc_programs) |
ba3f2522e8df
Added first version of the 1st step in the module conversion process.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
89 |
|
2996
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
90 |
# task completed, return |
9a62e3cad4a8
Use the iterative task iterator for the ProgramConversion update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2973
diff
changeset
|
91 |
return |