Switch to unified view

a/scripts/project-import.py b/scripts/project-import.py
...
...
2
import datetime
2
import datetime
3
import json
3
import json
4
import logging
4
import logging
5
import multiprocessing
5
import multiprocessing
6
import re
6
import re
7
import string
7
import sys
8
import sys
8
9
9
import colander as col
10
import colander as col
10
11
11
from ming.orm import session, ThreadLocalORMSession
12
from ming.orm import session, ThreadLocalORMSession
...
...
163
    worker_name = multiprocessing.current_process().name
164
    worker_name = multiprocessing.current_process().name
164
    M.session.artifact_orm_session._get().skip_mod_date = True
165
    M.session.artifact_orm_session._get().skip_mod_date = True
165
    shortname = p.shortname or p.name.shortname
166
    shortname = p.shortname or p.name.shortname
166
    project = M.Project.query.get(shortname=shortname,
167
    project = M.Project.query.get(shortname=shortname,
167
            neighborhood_id=nbhd._id)
168
            neighborhood_id=nbhd._id)
169
    project_template = nbhd.get_project_template()
168
170
169
    if project and not (options.update and p.shortname):
171
    if project and not (options.update and p.shortname):
170
        log.warning('[%s] Skipping existing project "%s". To update an existing '
172
        log.warning('[%s] Skipping existing project "%s". To update an existing '
171
                    'project you must provide the project shortname and run '
173
                    'project you must provide the project shortname and run '
172
                    'this script with --update.' % (worker_name, shortname))
174
                    'this script with --update.' % (worker_name, shortname))
...
...
184
            return 0
186
            return 0
185
    else:
187
    else:
186
        log.info('[%s] Updating project "%s".' % (worker_name, shortname))
188
        log.info('[%s] Updating project "%s".' % (worker_name, shortname))
187
189
188
    project.notifications_disabled = True
190
    project.notifications_disabled = True
191
192
    if options.ensure_tools and 'tools' in project_template:
193
        for i, tool in enumerate(project_template['tools'].iterkeys()):
194
            tool_config = project_template['tools'][tool]
195
            if project.app_instance(tool_config['mount_point']):
196
                continue
197
            tool_options = tool_config.get('options', {})
198
            for k, v in tool_options.iteritems():
199
                if isinstance(v, basestring):
200
                    tool_options[k] = string.Template(v).safe_substitute(
201
                        project.root_project.__dict__.get('root_project', {}))
202
            project.install_app(tool,
203
                    mount_label=tool_config['label'],
204
                    mount_point=tool_config['mount_point'],
205
                    **tool_options)
206
189
    project.summary = p.summary
207
    project.summary = p.summary
190
    project.short_description = p.description
208
    project.short_description = p.description
191
    project.external_homepage = p.external_homepage
209
    project.external_homepage = p.external_homepage
192
    project.last_updated = datetime.datetime.utcnow()
210
    project.last_updated = datetime.datetime.utcnow()
193
    # These properties may have been populated by nbhd template defaults in
211
    # These properties may have been populated by nbhd template defaults in
...
...
265
            help='Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL).')
283
            help='Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL).')
266
    parser.add_argument('--update', dest='update', default=False,
284
    parser.add_argument('--update', dest='update', default=False,
267
            action='store_true',
285
            action='store_true',
268
            help='Update existing projects. Without this option, existing '
286
            help='Update existing projects. Without this option, existing '
269
                 'projects will be skipped.')
287
                 'projects will be skipped.')
288
    parser.add_argument('--ensure-tools', dest='ensure_tools', default=False,
289
            action='store_true',
290
            help='Check nbhd project template for default tools, and install '
291
                 'them on the project(s) if not already installed.')
270
    parser.add_argument('--nprocs', '-n', action='store', dest='nprocs', type=int,
292
    parser.add_argument('--nprocs', '-n', action='store', dest='nprocs', type=int,
271
            help='Number of processes to divide the work among.',
293
            help='Number of processes to divide the work among.',
272
            default=multiprocessing.cpu_count())
294
            default=multiprocessing.cpu_count())
273
    return parser.parse_args()
295
    return parser.parse_args()
274
296