• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

Revisionf6fbbd506ffba570865aeef43b5549350e9d120b (tree)
Zeit2012-05-17 00:15:17
AutorTim Van Steenburgh <tvansteenburgh@geek...>
CommiterYaroslav Luzin

Log Message

[#4202] Clean up copy-pasted chunked_project_iterator usage.

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@geek.net>

Ändern Zusammenfassung

Diff

--- a/scripts/migrations/010-fix-home-permissions.py
+++ b/scripts/migrations/010-fix-home-permissions.py
@@ -7,6 +7,7 @@ from ming.orm import session
77 from bson import ObjectId
88
99 from allura import model as M
10+from allura.lib import utils
1011 from forgewiki.wiki_main import ForgeWikiApp
1112
1213 log = logging.getLogger('fix-home-permissions')
@@ -22,8 +23,9 @@ def main():
2223 else:
2324 log.info('Fixing permissions for all Home Wikis')
2425
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
2729 for project in some_projects:
2830 c.project = project
2931 home_app = project.app_instance('home')
@@ -56,21 +58,6 @@ def main():
5658 home_app.config.acl = map(dict, new_acl.values())
5759 session(home_app.config).flush()
5860
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-
7461 def project_role(project, name):
7562 role = M.ProjectRole.query.get(project_id=project._id, name=name)
7663 if role is None:
--- a/scripts/migrations/011-fix-subroles.py
+++ b/scripts/migrations/011-fix-subroles.py
@@ -12,11 +12,11 @@ For project.users:
1212 import sys
1313 import logging
1414
15-from pylons import c
1615 from ming.orm import session
1716 from ming.orm.ormsession import ThreadLocalORMSession
1817
1918 from allura import model as M
19+from allura.lib import utils
2020
2121 log = logging.getLogger('fix-subroles')
2222 log.addHandler(logging.StreamHandler(sys.stdout))
@@ -27,7 +27,7 @@ def main():
2727 log.info('Examining subroles in all non-user projects.')
2828 n_users = M.Neighborhood.query.get(name='Users')
2929 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):
3131 for project in some_projects:
3232 project_name = '%s.%s' % (project.neighborhood.name, project.shortname)
3333 project_roles = {}
@@ -53,7 +53,7 @@ def main():
5353 for user in project.users():
5454 pr = user.project_role(project=project)
5555 if not pr.roles: continue
56- for parent, children in [('Admin', ('Developer', 'Member')),
56+ for parent, children in [('Admin', ('Developer', 'Member')),
5757 ('Developer', ('Member',))]:
5858 if project_roles[parent]._id not in pr.roles: continue
5959 for role_name in children:
@@ -73,21 +73,5 @@ def main():
7373
7474 log.info('%s projects examined.' % num_projects_examined)
7575
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-
9276 if __name__ == '__main__':
9377 main()
--- a/scripts/migrations/012-uninstall-home.py
+++ b/scripts/migrations/012-uninstall-home.py
@@ -7,6 +7,7 @@ from bson import ObjectId
77 from mock import Mock, patch
88
99 from allura.lib import helpers as h
10+from allura.lib import utils
1011 from allura import model as M
1112 from forgewiki import model as WM
1213 from allura.ext.project_home import ProjectHomeApp
@@ -21,7 +22,8 @@ def main():
2122 possibly_orphaned_projects = 0
2223 solr_delete = Mock()
2324 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")}}):
2527 for project in some_projects:
2628 c.project = project
2729 old_home_app = project.app_instance('home')
@@ -102,20 +104,5 @@ def main():
102104 assert solr_delete.call_count == affected_projects, solr_delete.call_count
103105 assert notification_post.call_count == 2 * affected_projects, notification_post.call_count
104106
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-
120107 if __name__ == '__main__':
121108 main()
--- a/scripts/migrations/013-update-ordinals.py
+++ b/scripts/migrations/013-update-ordinals.py
@@ -6,6 +6,7 @@ from ming.orm import session
66 from ming.orm.ormsession import ThreadLocalORMSession
77
88 from allura import model as M
9+from allura.lib import utils
910
1011 log = logging.getLogger('update-ordinals')
1112 log.addHandler(logging.StreamHandler(sys.stdout))
@@ -14,7 +15,7 @@ def main():
1415 test = sys.argv[-1] == 'test'
1516 num_projects_examined = 0
1617 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):
1819 for project in some_projects:
1920 c.project = project
2021 mounts = project.ordered_mounts(include_search=True)
@@ -47,21 +48,5 @@ def main():
4748 ThreadLocalORMSession.flush_all()
4849 ThreadLocalORMSession.close_all()
4950
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-
6651 if __name__ == '__main__':
6752 main()
--- a/scripts/refresh-all-repos.py
+++ b/scripts/refresh-all-repos.py
@@ -1,11 +1,11 @@
11 import logging
22 import optparse
3-from collections import defaultdict
43
54 from pylons import c
65 from ming.orm import ThreadLocalORMSession
76
87 from allura import model as M
8+from allura.lib import utils
99
1010 log = logging.getLogger(__name__)
1111
@@ -45,7 +45,7 @@ def main():
4545 M.repo.DiffInfoDoc.m.remove({})
4646 M.repo.LastCommitDoc.m.remove({})
4747 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):
4949 for p in chunk:
5050 c.project = p
5151 if projects:
@@ -73,18 +73,5 @@ def main():
7373 ThreadLocalORMSession.flush_all()
7474 ThreadLocalORMSession.close_all()
7575
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-
8976 if __name__ == '__main__':
9077 main()