allura
修訂 | b4023f78c60fd8fc95bfc805bcb010a8f0bc4034 (tree) |
---|---|
時間 | 2012-02-23 06:00:49 |
作者 | Tim Van Steenburgh <tvansteenburgh@geek...> |
Commiter | Tim Van Steenburgh |
[#3749] Run project imports and updates as site admin.
Signed-off-by: Tim Van Steenburgh <tvansteenburgh@geek.net>
@@ -9,7 +9,8 @@ import sys | ||
9 | 9 | import colander as col |
10 | 10 | |
11 | 11 | from ming.orm import session, ThreadLocalORMSession |
12 | -from pylons import g | |
12 | +from pylons import c, g | |
13 | +from tg import config | |
13 | 14 | |
14 | 15 | from allura import model as M |
15 | 16 | from allura.lib import helpers as h |
@@ -158,7 +159,7 @@ def trove_ids(orig, new_): | ||
158 | 159 | if new_ is None: return orig |
159 | 160 | return set(t._id for t in list(new_)) |
160 | 161 | |
161 | -def create_project(p, nbhd, options): | |
162 | +def create_project(p, nbhd, user, options): | |
162 | 163 | worker_name = multiprocessing.current_process().name |
163 | 164 | M.session.artifact_orm_session._get().skip_mod_date = True |
164 | 165 | shortname = p.shortname or p.name.shortname |
@@ -208,15 +209,15 @@ def create_project(p, nbhd, options): | ||
208 | 209 | granted_to_project_id=project._id, |
209 | 210 | granted_by_neighborhood_id=nbhd._id) |
210 | 211 | project.notifications_disabled = False |
211 | - with h.push_context(project._id): | |
212 | + with h.push_config(c, project=project, user=user): | |
212 | 213 | ThreadLocalORMSession.flush_all() |
213 | 214 | g.post_event('project_updated') |
214 | 215 | session(project).clear() |
215 | 216 | return 0 |
216 | 217 | |
217 | -def create_projects(projects, nbhd, options): | |
218 | +def create_projects(projects, nbhd, user, options): | |
218 | 219 | for p in projects: |
219 | - r = create_project(Object(p), nbhd, options) | |
220 | + r = create_project(Object(p), nbhd, user, options) | |
220 | 221 | if r != 0: |
221 | 222 | sys.exit(r) |
222 | 223 |
@@ -228,6 +229,7 @@ def main(options): | ||
228 | 229 | nbhd = M.Neighborhood.query.get(name=options.neighborhood) |
229 | 230 | if not nbhd: |
230 | 231 | return 'Invalid neighborhood "%s".' % options.neighborhood |
232 | + admin = M.User.query.get(username=config.get('sfx.api.siteadmin', 'sf-robot')) | |
231 | 233 | |
232 | 234 | data = json.load(open(options.file, 'r')) |
233 | 235 | project = Project() |
@@ -242,7 +244,7 @@ def main(options): | ||
242 | 244 | jobs = [] |
243 | 245 | for i in range(options.nprocs): |
244 | 246 | p = multiprocessing.Process(target=create_projects, |
245 | - args=(chunks[i], nbhd, options), name='worker-' + str(i+1)) | |
247 | + args=(chunks[i], nbhd, admin, options), name='worker-' + str(i+1)) | |
246 | 248 | jobs.append(p) |
247 | 249 | p.start() |
248 | 250 |