|
a/scripts/migrations/012-uninstall-home.py |
|
b/scripts/migrations/012-uninstall-home.py |
|
... |
|
... |
5 |
from ming.orm import session
|
5 |
from ming.orm import session
|
6 |
from bson import ObjectId
|
6 |
from bson import ObjectId
|
7 |
from mock import Mock, patch
|
7 |
from mock import Mock, patch
|
8 |
|
8 |
|
9 |
from allura.lib import helpers as h
|
9 |
from allura.lib import helpers as h
|
|
|
10 |
from allura.lib import utils
|
10 |
from allura import model as M
|
11 |
from allura import model as M
|
11 |
from forgewiki import model as WM
|
12 |
from forgewiki import model as WM
|
12 |
from allura.ext.project_home import ProjectHomeApp
|
13 |
from allura.ext.project_home import ProjectHomeApp
|
13 |
|
14 |
|
14 |
log = logging.getLogger('uninstall-home')
|
15 |
log = logging.getLogger('uninstall-home')
|
|
... |
|
... |
19 |
log.info('Removing "home" tools')
|
20 |
log.info('Removing "home" tools')
|
20 |
affected_projects = 0
|
21 |
affected_projects = 0
|
21 |
possibly_orphaned_projects = 0
|
22 |
possibly_orphaned_projects = 0
|
22 |
solr_delete = Mock()
|
23 |
solr_delete = Mock()
|
23 |
notification_post = Mock()
|
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 |
for project in some_projects:
|
27 |
for project in some_projects:
|
26 |
c.project = project
|
28 |
c.project = project
|
27 |
old_home_app = project.app_instance('home')
|
29 |
old_home_app = project.app_instance('home')
|
28 |
if isinstance(old_home_app, ProjectHomeApp):
|
30 |
if isinstance(old_home_app, ProjectHomeApp):
|
29 |
|
31 |
|
|
... |
|
... |
100 |
log.warning('%s possibly orphaned projects found' % possibly_orphaned_projects)
|
102 |
log.warning('%s possibly orphaned projects found' % possibly_orphaned_projects)
|
101 |
if not test:
|
103 |
if not test:
|
102 |
assert solr_delete.call_count == affected_projects, solr_delete.call_count
|
104 |
assert solr_delete.call_count == affected_projects, solr_delete.call_count
|
103 |
assert notification_post.call_count == 2 * affected_projects, notification_post.call_count
|
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 |
if __name__ == '__main__':
|
107 |
if __name__ == '__main__':
|
121 |
main()
|
108 |
main()
|