~cjwatson/ubuntu-archive-publishing/tidy-copy-indices

« back to all changes in this revision

Viewing changes to lib/scripts/generate_extra_overrides.py

[r=cjwatson] Add some options to make it easier to run generate-extra-overrides locally

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        self.parser.add_option(
104
104
            "-s", "--series", dest="series", action="append",
105
105
            help="Series to operate on (may be given multiple times).")
 
106
        self.parser.add_option(
 
107
            "-a", "--arch", dest="architectures", action="append",
 
108
            help="Arches to operate on (may be given multiple times).")
 
109
        self.parser.add_option(
 
110
            "-g", "--germinate-root", dest="germinate_root",
 
111
            help="Location to write germinate output to.")
 
112
        self.parser.add_option(
 
113
            "-m", "--misc-root", dest="misc_root",
 
114
            help="Location to write miscellaneous output to.")
106
115
 
107
116
    @property
108
117
    def name(self):
140
149
        # the distribution's archives in the ARCHIVEROOTS environment
141
150
        # variable, joined by spaces.  We only care about the first archive.
142
151
        self.archiveroot = os.environ["ARCHIVEROOTS"].split()[0]
143
 
        self.germinateroot = self.archiveroot + "-germinate"
144
 
        self.miscroot = self.archiveroot + "-misc"
 
152
        if not self.options.germinate_root:
 
153
            self.options.germinate_root = self.archiveroot + "-germinate"
 
154
        if not self.options.misc_root:
 
155
            self.options.misc_root = self.archiveroot + "-misc"
145
156
 
146
157
    def setUpDirs(self):
147
158
        """Create output directories if they did not already exist."""
148
 
        if not file_exists(self.germinateroot):
 
159
        if not file_exists(self.options.germinate_root):
149
160
            self.logger.debug(
150
 
                "Creating germinate root %s.", self.germinateroot)
151
 
            os.makedirs(self.germinateroot)
152
 
        if not file_exists(self.miscroot):
153
 
            self.logger.debug("Creating misc root %s.", self.miscroot)
154
 
            os.makedirs(self.miscroot)
 
161
                "Creating germinate root %s.", self.options.germinate_root)
 
162
            os.makedirs(self.options.germinate_root)
 
163
        if not file_exists(self.options.misc_root):
 
164
            self.logger.debug("Creating misc root %s.", self.options.misc_root)
 
165
            os.makedirs(self.options.misc_root)
155
166
 
156
167
    def addLogHandler(self):
157
168
        """Send germinate's log output to a separate file."""
160
171
 
161
172
        self.germinate_logger = logging.getLogger("germinate")
162
173
        self.germinate_logger.setLevel(logging.INFO)
163
 
        self.log_file = os.path.join(self.germinateroot, "germinate.output")
 
174
        self.log_file = os.path.join(self.options.germinate_root,
 
175
                                     "germinate.output")
164
176
        self.log_handler = logging.FileHandler(self.log_file, mode="w")
165
177
        self.log_handler.setFormatter(GerminateFormatter())
166
178
        self.germinate_logger.addHandler(self.log_handler)
212
224
 
213
225
    def composeOutputPath(self, flavour, series_name, arch, base):
214
226
        return os.path.join(
215
 
            self.germinateroot,
 
227
            self.options.germinate_root,
216
228
            "%s_%s_%s_%s" % (base, flavour, series_name, arch))
217
229
 
218
230
    def recordOutput(self, path, seed_outputs):
387
399
        Any per-seed outputs not in seed_outputs are considered stale.
388
400
        """
389
401
        all_outputs = glob.glob(
390
 
            os.path.join(self.germinateroot, "*_*_%s_*" % series_name))
 
402
            os.path.join(self.options.germinate_root,
 
403
                         "*_*_%s_*" % series_name))
391
404
        for output in all_outputs:
392
405
            if os.path.basename(output) not in seed_outputs:
393
406
                os.remove(output)
415
428
 
416
429
            seed_outputs = set()
417
430
            override_path = os.path.join(
418
 
                self.miscroot, "more-extra.override.%s.main" % series_name)
 
431
                self.options.misc_root,
 
432
                "more-extra.override.%s.main" % series_name)
419
433
            with AtomicFile(override_path) as override_file:
420
434
                for pid, reader in procs:
421
435
                    log_records, overrides, arch_seed_outputs = pickle.load(
435
449
        for series in self.series:
436
450
            series_name = series.name
437
451
            components = self.getComponents(series)
438
 
            architectures = sorted(
439
 
                arch.architecture_tag for arch in series.architectures)
 
452
            if not self.options.architectures:
 
453
                architectures = sorted(
 
454
                    arch.architecture_tag for arch in series.architectures)
 
455
            else:
 
456
                architectures = self.options.architectures
440
457
 
441
458
            self.generateExtraOverrides(
442
459
                series_name, components, architectures, self.args,