Switch to unified view

a/scripts/restore_project.py b/scripts/restore_project.py
1
import os
1
import os
2
import sys
2
import sys
3
import struct
3
import struct
4
import logging
4
import logging
5
5
6
from ming.schema import Invalid
7
from ming.orm import state, session, mapper, MappedClass
6
from ming.orm import state, session, Mapper
8
from ming.orm.base import instrument, DocumentTracker
9
7
10
from pylons import c
8
from pylons import c
11
from bson import BSON
9
from bson import BSON
12
from allura import model as M
10
from allura import model as M
13
from allura.command import ReindexCommand
11
from allura.command import ReindexCommand
...
...
27
    log.info('Reloading %s into %s', dirname, new_shortname)
25
    log.info('Reloading %s into %s', dirname, new_shortname)
28
    with open(os.path.join(dirname, 'project.bson')) as fp:
26
    with open(os.path.join(dirname, 'project.bson')) as fp:
29
        project_doc = _read_bson(fp)
27
        project_doc = _read_bson(fp)
30
    project = M.Project.query.get(_id=project_doc['_id'])
28
    project = M.Project.query.get(_id=project_doc['_id'])
31
    st = state(project)
29
    st = state(project)
32
    st.document = instrument(project_doc, DocumentTracker(st))
30
    st.document = project_doc
33
    if project is None:
31
    if project is None:
34
        log.fatal('Project not found')
32
        log.fatal('Project not found')
35
        return 2
33
        return 2
36
    project.shortname = new_shortname
34
    project.shortname = new_shortname
37
    project.set_tool_data('sfx', unix_group_name=new_unix_group_name)
35
    project.set_tool_data('sfx', unix_group_name=new_unix_group_name)
...
...
62
    reindex.run(['--project', new_shortname])
60
    reindex.run(['--project', new_shortname])
63
    return 0
61
    return 0
64
62
65
def get_repo_collections():
63
def get_repo_collections():
66
    res = {}
64
    res = {}
67
    for name, cls in MappedClass._registry.iteritems():
65
    for m in Mapper.all_mappers():
66
        cls = m.mapped_class
68
        cname = cls.__mongometa__.name
67
        cname = cls.__mongometa__.name
69
        if issubclass(cls, M.Repository): res[cname] = cls
68
        if issubclass(cls, M.Repository): res[cname] = cls
70
    return res
69
    return res
71
70
72
def _read_bson(fp):
71
def _read_bson(fp):