| 778 | return options |
| 779 | |
| 780 | def RunSteps(self, step_classes, args=None): |
| 781 | options = self.MakeOptions(args) |
| 782 | if not options: |
| 783 | return 1 |
| 784 | |
| 785 | # Ensure temp dir exists for state files. |
| 786 | state_dir = os.path.dirname(self._config["PERSISTFILE_BASENAME"]) |
| 787 | if not os.path.exists(state_dir): |
| 788 | os.makedirs(state_dir) |
| 789 | |
| 790 | state_file = "%s-state.json" % self._config["PERSISTFILE_BASENAME"] |
| 791 | if options.step == 0 and os.path.exists(state_file): |
| 792 | os.remove(state_file) |
| 793 | |
| 794 | steps = [] |
| 795 | for (number, step_class) in enumerate([BootstrapStep] + step_classes): |
| 796 | steps.append(MakeStep(step_class, number, self._state, self._config, |
| 797 | options, self._side_effect_handler)) |
| 798 | |
| 799 | try: |
| 800 | for step in steps[options.step:]: |
| 801 | if step.Run(): |
| 802 | return 0 |
| 803 | finally: |
| 804 | if options.json_output: |
| 805 | with open(options.json_output, "w") as f: |
| 806 | json.dump(self._state['json_output'], f) |
| 807 | |
| 808 | return 0 |
| 809 | |
| 810 | def Run(self, args=None): |
| 811 | return self.RunSteps(self._Steps(), args) |