def _update_history(self): """Update the history file""" version = self.data['new_version'] history = self.vcs.history_file() if not history: logger.warn("No history file found") return history_lines = open(history).read().split('\n') headings = utils.extract_headings_from_history(history_lines) if not len(headings): logger.warn("No detectable existing version headings in the " "history file.") inject_location = 0 underline_char = '-' else: first = headings[0] inject_location = first['line'] underline_line = first['line'] + 1 try: underline_char = history_lines[underline_line][0] except IndexError: logger.debug("No character on line below header.") underline_char = '-' header = '%s (unreleased)' % version inject = [header, underline_char * len(header), '', self.data['nothing_changed_yet'], '', ''] history_lines[inject_location:inject_location] = inject contents = '\n'.join(history_lines) open(history, 'w').write(contents) logger.info("Injected new section into the history: %r", header)
def _grab_history(self): """Calculate the needed history/changelog changes Every history heading looks like '1.0 b4 (1972-12-25)'. Extract them, check if the first one matches the version and whether it has a the current date. """ default_location = None config = self.setup_cfg.config if config and config.has_option('zest.releaser', 'history_file'): default_location = config.get('zest.releaser', 'history_file') history_file = self.vcs.history_file(location=default_location) if not history_file: logger.warn("No history file found") self.data['history_lines'] = None self.data['history_file'] = None return logger.debug("Checking %s", history_file) history_lines = open(history_file).read().split('\n') # ^^^ TODO: .readlines()? headings = utils.extract_headings_from_history(history_lines) if not len(headings): logger.error("No detectable version heading in the history " "file %s", history_file) sys.exit() good_heading = self.data['history_header'] % self.data # ^^^ history_header is a string with %(abc)s replacements. line = headings[0]['line'] previous = history_lines[line] history_lines[line] = good_heading logger.debug("Set heading from %r to %r.", previous, good_heading) history_lines[line + 1] = utils.fix_rst_heading( heading=good_heading, below=history_lines[line + 1]) logger.debug("Set line below heading to %r", history_lines[line + 1]) self.data['history_lines'] = history_lines self.data['history_file'] = history_file