allura
Revision | f6fbbd506ffba570865aeef43b5549350e9d120b (tree) |
---|---|
Zeit | 2012-05-17 00:15:17 |
Autor | Tim Van Steenburgh <tvansteenburgh@geek...> |
Commiter | Yaroslav Luzin |
[#4202] Clean up copy-pasted chunked_project_iterator usage.
Signed-off-by: Tim Van Steenburgh <tvansteenburgh@geek.net>
@@ -7,6 +7,7 @@ from ming.orm import session | ||
7 | 7 | from bson import ObjectId |
8 | 8 | |
9 | 9 | from allura import model as M |
10 | +from allura.lib import utils | |
10 | 11 | from forgewiki.wiki_main import ForgeWikiApp |
11 | 12 | |
12 | 13 | log = logging.getLogger('fix-home-permissions') |
@@ -22,8 +23,9 @@ def main(): | ||
22 | 23 | else: |
23 | 24 | log.info('Fixing permissions for all Home Wikis') |
24 | 25 | |
25 | - for some_projects in chunked_project_iterator({'neighborhood_id': {'$nin': [ObjectId('4be2faf8898e33156f00003e'), # /u | |
26 | - ObjectId('4dbf2563bfc09e6362000005')]}}): # /motorola | |
26 | + for some_projects in utils.chunked_find(M.Project, {'neighborhood_id': { | |
27 | + '$nin': [ObjectId('4be2faf8898e33156f00003e'), # /u | |
28 | + ObjectId('4dbf2563bfc09e6362000005')]}}): # /motorola | |
27 | 29 | for project in some_projects: |
28 | 30 | c.project = project |
29 | 31 | home_app = project.app_instance('home') |
@@ -56,21 +58,6 @@ def main(): | ||
56 | 58 | home_app.config.acl = map(dict, new_acl.values()) |
57 | 59 | session(home_app.config).flush() |
58 | 60 | |
59 | -PAGESIZE=1024 | |
60 | - | |
61 | -def chunked_project_iterator(q_project): | |
62 | - '''shamelessly copied from refresh-all-repos.py''' | |
63 | - page = 0 | |
64 | - while True: | |
65 | - results = (M.Project.query | |
66 | - .find(q_project) | |
67 | - .skip(PAGESIZE*page) | |
68 | - .limit(PAGESIZE) | |
69 | - .all()) | |
70 | - if not results: break | |
71 | - yield results | |
72 | - page += 1 | |
73 | - | |
74 | 61 | def project_role(project, name): |
75 | 62 | role = M.ProjectRole.query.get(project_id=project._id, name=name) |
76 | 63 | if role is None: |
@@ -12,11 +12,11 @@ For project.users: | ||
12 | 12 | import sys |
13 | 13 | import logging |
14 | 14 | |
15 | -from pylons import c | |
16 | 15 | from ming.orm import session |
17 | 16 | from ming.orm.ormsession import ThreadLocalORMSession |
18 | 17 | |
19 | 18 | from allura import model as M |
19 | +from allura.lib import utils | |
20 | 20 | |
21 | 21 | log = logging.getLogger('fix-subroles') |
22 | 22 | log.addHandler(logging.StreamHandler(sys.stdout)) |
@@ -27,7 +27,7 @@ def main(): | ||
27 | 27 | log.info('Examining subroles in all non-user projects.') |
28 | 28 | n_users = M.Neighborhood.query.get(name='Users') |
29 | 29 | project_filter = dict(neighborhood_id={'$ne':n_users._id}) |
30 | - for some_projects in chunked_project_iterator(project_filter): | |
30 | + for some_projects in utils.chunked_find(M.Project, project_filter): | |
31 | 31 | for project in some_projects: |
32 | 32 | project_name = '%s.%s' % (project.neighborhood.name, project.shortname) |
33 | 33 | project_roles = {} |
@@ -53,7 +53,7 @@ def main(): | ||
53 | 53 | for user in project.users(): |
54 | 54 | pr = user.project_role(project=project) |
55 | 55 | if not pr.roles: continue |
56 | - for parent, children in [('Admin', ('Developer', 'Member')), | |
56 | + for parent, children in [('Admin', ('Developer', 'Member')), | |
57 | 57 | ('Developer', ('Member',))]: |
58 | 58 | if project_roles[parent]._id not in pr.roles: continue |
59 | 59 | for role_name in children: |
@@ -73,21 +73,5 @@ def main(): | ||
73 | 73 | |
74 | 74 | log.info('%s projects examined.' % num_projects_examined) |
75 | 75 | |
76 | - | |
77 | -PAGESIZE=1024 | |
78 | - | |
79 | -def chunked_project_iterator(q_project): | |
80 | - '''shamelessly copied from refresh-all-repos.py''' | |
81 | - page = 0 | |
82 | - while True: | |
83 | - results = (M.Project.query | |
84 | - .find(q_project) | |
85 | - .skip(PAGESIZE*page) | |
86 | - .limit(PAGESIZE) | |
87 | - .all()) | |
88 | - if not results: break | |
89 | - yield results | |
90 | - page += 1 | |
91 | - | |
92 | 76 | if __name__ == '__main__': |
93 | 77 | main() |
@@ -7,6 +7,7 @@ from bson import ObjectId | ||
7 | 7 | from mock import Mock, patch |
8 | 8 | |
9 | 9 | from allura.lib import helpers as h |
10 | +from allura.lib import utils | |
10 | 11 | from allura import model as M |
11 | 12 | from forgewiki import model as WM |
12 | 13 | from allura.ext.project_home import ProjectHomeApp |
@@ -21,7 +22,8 @@ def main(): | ||
21 | 22 | possibly_orphaned_projects = 0 |
22 | 23 | solr_delete = Mock() |
23 | 24 | notification_post = Mock() |
24 | - for some_projects in chunked_project_iterator({'neighborhood_id': {'$ne': ObjectId("4be2faf8898e33156f00003e")}}): | |
25 | + for some_projects in utils.chunked_find(M.Project, {'neighborhood_id': { | |
26 | + '$ne': ObjectId("4be2faf8898e33156f00003e")}}): | |
25 | 27 | for project in some_projects: |
26 | 28 | c.project = project |
27 | 29 | old_home_app = project.app_instance('home') |
@@ -102,20 +104,5 @@ def main(): | ||
102 | 104 | assert solr_delete.call_count == affected_projects, solr_delete.call_count |
103 | 105 | assert notification_post.call_count == 2 * affected_projects, notification_post.call_count |
104 | 106 | |
105 | -PAGESIZE=1024 | |
106 | - | |
107 | -def chunked_project_iterator(q_project): | |
108 | - '''shamelessly copied from refresh-all-repos.py''' | |
109 | - page = 0 | |
110 | - while True: | |
111 | - results = (M.Project.query | |
112 | - .find(q_project) | |
113 | - .skip(PAGESIZE*page) | |
114 | - .limit(PAGESIZE) | |
115 | - .all()) | |
116 | - if not results: break | |
117 | - yield results | |
118 | - page += 1 | |
119 | - | |
120 | 107 | if __name__ == '__main__': |
121 | 108 | main() |
@@ -6,6 +6,7 @@ from ming.orm import session | ||
6 | 6 | from ming.orm.ormsession import ThreadLocalORMSession |
7 | 7 | |
8 | 8 | from allura import model as M |
9 | +from allura.lib import utils | |
9 | 10 | |
10 | 11 | log = logging.getLogger('update-ordinals') |
11 | 12 | log.addHandler(logging.StreamHandler(sys.stdout)) |
@@ -14,7 +15,7 @@ def main(): | ||
14 | 15 | test = sys.argv[-1] == 'test' |
15 | 16 | num_projects_examined = 0 |
16 | 17 | log.info('Examining all projects for mount order.') |
17 | - for some_projects in chunked_project_iterator({}): | |
18 | + for some_projects in utils.chunked_find(M.Project): | |
18 | 19 | for project in some_projects: |
19 | 20 | c.project = project |
20 | 21 | mounts = project.ordered_mounts(include_search=True) |
@@ -47,21 +48,5 @@ def main(): | ||
47 | 48 | ThreadLocalORMSession.flush_all() |
48 | 49 | ThreadLocalORMSession.close_all() |
49 | 50 | |
50 | - | |
51 | -PAGESIZE=1024 | |
52 | - | |
53 | -def chunked_project_iterator(q_project): | |
54 | - '''shamelessly copied from refresh-all-repos.py''' | |
55 | - page = 0 | |
56 | - while True: | |
57 | - results = (M.Project.query | |
58 | - .find(q_project) | |
59 | - .skip(PAGESIZE*page) | |
60 | - .limit(PAGESIZE) | |
61 | - .all()) | |
62 | - if not results: break | |
63 | - yield results | |
64 | - page += 1 | |
65 | - | |
66 | 51 | if __name__ == '__main__': |
67 | 52 | main() |
@@ -1,11 +1,11 @@ | ||
1 | 1 | import logging |
2 | 2 | import optparse |
3 | -from collections import defaultdict | |
4 | 3 | |
5 | 4 | from pylons import c |
6 | 5 | from ming.orm import ThreadLocalORMSession |
7 | 6 | |
8 | 7 | from allura import model as M |
8 | +from allura.lib import utils | |
9 | 9 | |
10 | 10 | log = logging.getLogger(__name__) |
11 | 11 |
@@ -45,7 +45,7 @@ def main(): | ||
45 | 45 | M.repo.DiffInfoDoc.m.remove({}) |
46 | 46 | M.repo.LastCommitDoc.m.remove({}) |
47 | 47 | M.repo.CommitRunDoc.m.remove({}) |
48 | - for chunk in chunked_project_iterator(q_project): | |
48 | + for chunk in utils.chunked_find(M.Project, q_project): | |
49 | 49 | for p in chunk: |
50 | 50 | c.project = p |
51 | 51 | if projects: |
@@ -73,18 +73,5 @@ def main(): | ||
73 | 73 | ThreadLocalORMSession.flush_all() |
74 | 74 | ThreadLocalORMSession.close_all() |
75 | 75 | |
76 | -def chunked_project_iterator(q_project): | |
77 | - page = 0 | |
78 | - while True: | |
79 | - results = (M.Project.query | |
80 | - .find(q_project) | |
81 | - .skip(PAGESIZE*page) | |
82 | - .limit(PAGESIZE) | |
83 | - .all()) | |
84 | - if not results: break | |
85 | - yield results | |
86 | - page += 1 | |
87 | - | |
88 | - | |
89 | 76 | if __name__ == '__main__': |
90 | 77 | main() |