|
a/scripts/migrations/024-migrate-custom-profile-text.py |
|
b/scripts/migrations/024-migrate-custom-profile-text.py |
|
... |
|
... |
4 |
from pylons import c
|
4 |
from pylons import c
|
5 |
|
5 |
|
6 |
from ming.orm import ThreadLocalORMSession
|
6 |
from ming.orm import ThreadLocalORMSession
|
7 |
|
7 |
|
8 |
from allura import model as M
|
8 |
from allura import model as M
|
|
|
9 |
from allura.lib import utils
|
9 |
from forgewiki import model as WM
|
10 |
from forgewiki import model as WM
|
10 |
from forgewiki.wiki_main import ForgeWikiApp
|
11 |
from forgewiki.wiki_main import ForgeWikiApp
|
11 |
|
12 |
|
12 |
log = logging.getLogger(__name__)
|
13 |
log = logging.getLogger(__name__)
|
13 |
|
14 |
|
|
... |
|
... |
17 |
" This project is created automatically during user registration"
|
18 |
" This project is created automatically during user registration"
|
18 |
" as an easy place to store personal data that doesn't need its own"
|
19 |
" as an easy place to store personal data that doesn't need its own"
|
19 |
" project such as cloned repositories.\n\n%s")
|
20 |
" project such as cloned repositories.\n\n%s")
|
20 |
|
21 |
|
21 |
def main():
|
22 |
def main():
|
22 |
for p in M.Project.query.find().all():
|
23 |
users = M.Neighborhood.query.get(name='Users')
|
|
|
24 |
for chunk in utils.chunked_find(M.Project, {'neighborhood_id': users._id}):
|
|
|
25 |
for p in chunk:
|
23 |
user = p.user_project_of
|
26 |
user = p.user_project_of
|
24 |
if not user:
|
27 |
if not user:
|
25 |
continue
|
28 |
continue
|
26 |
|
29 |
|
27 |
description = p.description
|
30 |
description = p.description
|
28 |
if description is None or re.match(default_description, description):
|
31 |
if description is None or re.match(default_description, description):
|
29 |
continue
|
32 |
continue
|
30 |
|
33 |
|
31 |
app = p.app_instance('wiki')
|
34 |
app = p.app_instance('wiki')
|
32 |
if app is None:
|
35 |
if app is None:
|
33 |
p.install_app('wiki')
|
36 |
p.install_app('wiki')
|
34 |
|
37 |
|
35 |
page = WM.Page.query.get(app_config_id=app.config._id, title='Home')
|
38 |
page = WM.Page.query.get(app_config_id=app.config._id, title='Home')
|
36 |
if page is None:
|
39 |
if page is None:
|
37 |
continue
|
40 |
continue
|
38 |
|
41 |
|
39 |
c.app = app
|
42 |
c.app = app
|
40 |
c.project = p
|
43 |
c.project = p
|
41 |
c.user = user
|
44 |
c.user = user
|
42 |
|
45 |
|
43 |
if "This is the personal project of" in page.text:
|
46 |
if "This is the personal project of" in page.text:
|
44 |
if description not in page.text:
|
47 |
if description not in page.text:
|
45 |
page.text = "%s\n\n%s" % (page.text, description)
|
48 |
page.text = "%s\n\n%s" % (page.text, description)
|
|
|
49 |
log.info("Update wiki home page text for %s" % user.username)
|
|
|
50 |
elif "This is the default page" in page.text:
|
|
|
51 |
page.text = default_personal_project_tmpl % (user.display_name, description)
|
46 |
log.info("Update wiki home page text for %s" % user.username)
|
52 |
log.info("Update wiki home page text for %s" % user.username)
|
47 |
elif "This is the default page" in page.text:
|
|
|
48 |
page.text = default_personal_project_tmpl % (user.display_name, description)
|
|
|
49 |
log.info("Update wiki home page text for %s" % user.username)
|
|
|
50 |
else:
|
53 |
else:
|
51 |
pass
|
54 |
pass
|
52 |
|
55 |
|
53 |
ThreadLocalORMSession.flush_all()
|
56 |
ThreadLocalORMSession.flush_all()
|
54 |
|
57 |
|
55 |
if __name__ == '__main__':
|
58 |
if __name__ == '__main__':
|
56 |
main()
|
59 |
main()
|