Switch to unified view

a/scripts/refresh-all-repos.py b/scripts/refresh-all-repos.py
1
import argparse
1
import logging
2
import logging
2
3
3
import faulthandler
4
import faulthandler
4
from pylons import c
5
from pylons import c
5
from ming.orm import ThreadLocalORMSession
6
from ming.orm import ThreadLocalORMSession
...
...
42
            else:
43
            else:
43
                mount_points = [ac.options.mount_point for ac in
44
                mount_points = [ac.options.mount_point for ac in
44
                                M.AppConfig.query.find(dict(project_id=p._id))]
45
                                M.AppConfig.query.find(dict(project_id=p._id))]
45
            for app in (p.app_instance(mp) for mp in mount_points):
46
            for app in (p.app_instance(mp) for mp in mount_points):
46
                c.app = app
47
                c.app = app
47
                if not hasattr(app, 'repo'): continue
48
                if not hasattr(app, 'repo'):
49
                    continue
50
                if c.app.repo.tool.lower() not in options.repo_types:
51
                    log.info("Skipping %r: wrong type (%s)", c.app.repo,
52
                            c.app.repo.tool.lower())
53
                    continue
48
                try:
54
                try:
49
                    c.app.repo._impl._setup_hooks()
55
                    c.app.repo._impl._setup_hooks()
50
                except:
56
                except:
51
                    log.exception('Error setting up hooks for %r', c.app.repo)
57
                    log.exception('Error setting up hooks for %r', c.app.repo)
52
58
...
...
101
                except:
107
                except:
102
                    log.exception('Error refreshing %r', c.app.repo)
108
                    log.exception('Error refreshing %r', c.app.repo)
103
        ThreadLocalORMSession.flush_all()
109
        ThreadLocalORMSession.flush_all()
104
        ThreadLocalORMSession.close_all()
110
        ThreadLocalORMSession.close_all()
105
111
112
113
def repo_type_list(s):
114
    repo_types = []
115
    for repo_type in s.split(','):
116
        repo_type = repo_type.strip()
117
        if repo_type not in ['svn', 'git', 'hg']:
118
            raise argparse.ArgumentTypeError(
119
                    '{} is not a valid repo type.'.format(repo_type))
120
        repo_types.append(repo_type)
121
    return repo_types
122
123
106
def parse_options():
124
def parse_options():
107
    import argparse
108
    parser = argparse.ArgumentParser(description='Scan repos on filesytem and '
125
    parser = argparse.ArgumentParser(description='Scan repos on filesytem and '
109
            'update repo metadata in MongoDB. Run for all repos (no args), '
126
            'update repo metadata in MongoDB. Run for all repos (no args), '
110
            'or restrict by neighborhood, project, or code tool mount point.')
127
            'or restrict by neighborhood, project, or code tool mount point.')
111
    parser.add_argument('--nbhd', action='store', default='', dest='nbhd',
128
    parser.add_argument('--nbhd', action='store', default='', dest='nbhd',
112
            help='Restrict update to a particular neighborhood, e.g. /p/.')
129
            help='Restrict update to a particular neighborhood, e.g. /p/.')
...
...
115
            'subproject, use a slash: project/subproject.')
132
            'subproject, use a slash: project/subproject.')
116
    parser.add_argument('--project-regex', action='store', default='',
133
    parser.add_argument('--project-regex', action='store', default='',
117
            dest='project_regex',
134
            dest='project_regex',
118
            help='Restrict update to projects for which the shortname matches '
135
            help='Restrict update to projects for which the shortname matches '
119
            'the provided regex.')
136
            'the provided regex.')
137
    parser.add_argument('--repo-types', action='store', type=repo_type_list,
138
            default=['svn', 'git', 'hg'], dest='repo_types',
139
            help='Only refresh repos of the given type(s). Defaults to: '
140
            'svn,git,hg. Example: --repo-types=git,hg')
120
    parser.add_argument('--mount_point', default='', dest='mount_point',
141
    parser.add_argument('--mount_point', default='', dest='mount_point',
121
            help='Restrict update to repos at the given tool mount point. ')
142
            help='Restrict update to repos at the given tool mount point. ')
122
    parser.add_argument('--clean', action='store_true', dest='clean',
143
    parser.add_argument('--clean', action='store_true', dest='clean',
123
            default=False, help='Remove repo-related mongo docs (for '
144
            default=False, help='Remove repo-related mongo docs (for '
124
            'project(s) being refreshed only) before doing the refresh.')
145
            'project(s) being refreshed only) before doing the refresh.')