|
a/scripts/uninstall-home.py |
|
b/scripts/uninstall-home.py |
|
... |
|
... |
2 |
import logging
|
2 |
import logging
|
3 |
|
3 |
|
4 |
from pylons import c
|
4 |
from pylons import c
|
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 |
|
8 |
|
8 |
from allura.lib import helpers as h
|
9 |
from allura.lib import helpers as h
|
9 |
from allura import model as M
|
10 |
from allura import model as M
|
10 |
from forgewiki import model as WM
|
11 |
from forgewiki import model as WM
|
11 |
from allura.ext.project_home import ProjectHomeApp
|
12 |
from allura.ext.project_home import ProjectHomeApp
|
|
... |
|
... |
15 |
log.addHandler(handler)
|
16 |
log.addHandler(handler)
|
16 |
|
17 |
|
17 |
def main():
|
18 |
def main():
|
18 |
test = sys.argv[-1] == 'test'
|
19 |
test = sys.argv[-1] == 'test'
|
19 |
log.info('Removing "home" tools')
|
20 |
log.info('Removing "home" tools')
|
|
|
21 |
affected_projects = 0
|
|
|
22 |
possibly_orphaned_projects = 0
|
|
|
23 |
solr_delete = Mock()
|
20 |
for some_projects in chunked_project_iterator({'neighborhood_id': {'$ne': ObjectId("4be2faf8898e33156f00003e")}}):
|
24 |
for some_projects in chunked_project_iterator({'neighborhood_id': {'$ne': ObjectId("4be2faf8898e33156f00003e")}}):
|
21 |
for project in some_projects:
|
25 |
for project in some_projects:
|
22 |
c.project = project
|
26 |
c.project = project
|
23 |
old_home_app = project.app_instance('home')
|
27 |
old_home_app = project.app_instance('home')
|
24 |
if isinstance(old_home_app, ProjectHomeApp):
|
28 |
if isinstance(old_home_app, ProjectHomeApp):
|
25 |
|
29 |
|
|
|
30 |
# would we actually be able to install a wiki?
|
|
|
31 |
if M.ProjectRole.by_name('Admin') is None:
|
|
|
32 |
log.warning('project %s may be orphaned' % project.shortname)
|
|
|
33 |
possibly_orphaned_projects += 1
|
|
|
34 |
continue
|
|
|
35 |
|
|
|
36 |
affected_projects += 1
|
|
|
37 |
|
26 |
# remove the existing home tool
|
38 |
# remove the existing home tool
|
27 |
if test:
|
39 |
if test:
|
28 |
log.info('would remove "home" tool from project ' + project.shortname)
|
40 |
log.info('would remove "home" tool from project ' + project.shortname)
|
29 |
else:
|
41 |
else:
|
30 |
log.info('removing "home" tool from project ' + project.shortname)
|
42 |
log.info('removing "home" tool from project ' + project.shortname)
|
|
|
43 |
with patch('allura.app.g.solr.delete', solr_delete):
|
31 |
project.uninstall_app('home')
|
44 |
project.uninstall_app('home')
|
32 |
|
45 |
|
33 |
# ...and put a Wiki in its place (note we only create a Wiki if we deleted the old home)
|
46 |
# ...and put a Wiki in its place (note we only create a Wiki if we deleted the old home)
|
34 |
if test:
|
47 |
if test:
|
35 |
log.info('would create Wiki "home" for project ' + project.shortname)
|
48 |
log.info('would create Wiki "home" for project ' + project.shortname)
|
36 |
else:
|
49 |
else:
|
|
... |
|
... |
75 |
# if we changed the home page name, make sure the Wiki knows that's the root page
|
88 |
# if we changed the home page name, make sure the Wiki knows that's the root page
|
76 |
new_home_app.root_page_name = home_title
|
89 |
new_home_app.root_page_name = home_title
|
77 |
|
90 |
|
78 |
session(project).flush()
|
91 |
session(project).flush()
|
79 |
session(project).clear()
|
92 |
session(project).clear()
|
|
|
93 |
if test:
|
|
|
94 |
log.info('%s projects would be updated' % affected_projects)
|
|
|
95 |
else:
|
|
|
96 |
log.info('%s projects were updated' % affected_projects)
|
|
|
97 |
if possibly_orphaned_projects:
|
|
|
98 |
log.warning('%n possibly orphaned projects found' % possibly_orphaned_projects)
|
|
|
99 |
if not test:
|
|
|
100 |
assert solr_delete.call_count == affected_projects, solr_delete.call_count
|
80 |
|
101 |
|
81 |
PAGESIZE=1024
|
102 |
PAGESIZE=1024
|
82 |
|
103 |
|
83 |
def chunked_project_iterator(q_project):
|
104 |
def chunked_project_iterator(q_project):
|
84 |
'''shamelessly copied from refresh-all-repos.py'''
|
105 |
'''shamelessly copied from refresh-all-repos.py'''
|