~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/scripts/base.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-01 13:37:39 UTC
  • mfrom: (12913.2.23 mail-scope)
  • Revision ID: launchpad@pqm.canonical.com-20110801133739-r61kp1hfiqe0x83z
[r=adeuring,gmb][bug=810290] add 'mail_header:' feature scope

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    )
44
44
from canonical.lp import initZopeless
45
45
from lp.services.features import (
 
46
    UseFeatureController,
46
47
    get_relevant_feature_controller,
47
48
    install_feature_controller,
48
49
    make_script_feature_controller,
323
324
        if self.options.profile:
324
325
            profiler = Profile()
325
326
 
326
 
        original_feature_controller = get_relevant_feature_controller()
327
 
        install_feature_controller(make_script_feature_controller(self.name))
328
 
        try:
329
 
            if profiler:
330
 
                profiler.runcall(self.main)
 
327
        with UseFeatureController(make_script_feature_controller(self.name)):
 
328
            try:
 
329
                if profiler:
 
330
                    profiler.runcall(self.main)
 
331
                else:
 
332
                    self.main()
 
333
            except LaunchpadScriptFailure, e:
 
334
                self.logger.error(str(e))
 
335
                sys.exit(e.exit_status)
 
336
            except SilentLaunchpadScriptFailure, e:
 
337
                sys.exit(e.exit_status)
331
338
            else:
332
 
                self.main()
333
 
        except LaunchpadScriptFailure, e:
334
 
            self.logger.error(str(e))
335
 
            sys.exit(e.exit_status)
336
 
        except SilentLaunchpadScriptFailure, e:
337
 
            sys.exit(e.exit_status)
338
 
        else:
339
 
            date_completed = datetime.datetime.now(UTC)
340
 
            self.record_activity(date_started, date_completed)
341
 
        finally:
342
 
            install_feature_controller(original_feature_controller)
 
339
                date_completed = datetime.datetime.now(UTC)
 
340
                self.record_activity(date_started, date_completed)
343
341
        if profiler:
344
342
            profiler.dump_stats(self.options.profile)
345
343