|
a/scripts/migrations/013-update-ordinals.py |
|
b/scripts/migrations/013-update-ordinals.py |
|
... |
|
... |
4 |
from pylons import c
|
4 |
from pylons import c
|
5 |
from ming.orm import session
|
5 |
from ming.orm import session
|
6 |
from ming.orm.ormsession import ThreadLocalORMSession
|
6 |
from ming.orm.ormsession 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 |
|
10 |
|
10 |
log = logging.getLogger('update-ordinals')
|
11 |
log = logging.getLogger('update-ordinals')
|
11 |
log.addHandler(logging.StreamHandler(sys.stdout))
|
12 |
log.addHandler(logging.StreamHandler(sys.stdout))
|
12 |
|
13 |
|
13 |
def main():
|
14 |
def main():
|
14 |
test = sys.argv[-1] == 'test'
|
15 |
test = sys.argv[-1] == 'test'
|
15 |
num_projects_examined = 0
|
16 |
num_projects_examined = 0
|
16 |
log.info('Examining all projects for mount order.')
|
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 |
for project in some_projects:
|
19 |
for project in some_projects:
|
19 |
c.project = project
|
20 |
c.project = project
|
20 |
mounts = project.ordered_mounts(include_search=True)
|
21 |
mounts = project.ordered_mounts(include_search=True)
|
21 |
|
22 |
|
22 |
# ordered_mounts() means duplicate ordinals (if any) will be next to each other
|
23 |
# ordered_mounts() means duplicate ordinals (if any) will be next to each other
|
|
... |
|
... |
45 |
|
46 |
|
46 |
log.info('%s projects examined.' % num_projects_examined)
|
47 |
log.info('%s projects examined.' % num_projects_examined)
|
47 |
ThreadLocalORMSession.flush_all()
|
48 |
ThreadLocalORMSession.flush_all()
|
48 |
ThreadLocalORMSession.close_all()
|
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 |
if __name__ == '__main__':
|
51 |
if __name__ == '__main__':
|
67 |
main()
|
52 |
main()
|