From f1af0a13254319a1ce2b610a9a997b9e22af7316 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 19 Aug 2011 08:01:38 +0100 Subject: Add unreleased-projects script. --- scripts/unreleased-projects | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 scripts/unreleased-projects diff --git a/scripts/unreleased-projects b/scripts/unreleased-projects new file mode 100755 index 0000000..3aaa9ba --- /dev/null +++ b/scripts/unreleased-projects @@ -0,0 +1,98 @@ +#!/usr/bin/python +# Copyright 2011 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import cliapp +import logging +import os +import re + + +class UnreleasedProjects(cliapp.Application): + + conf_file = os.path.expanduser('~/.sd-publish-all.conf') + + def add_settings(self): + self.settings.boolean(['verbose'], 'be verbose') + + def process_args(self, args): + for project_dir in self.project_dirs(): + logging.debug('examining project dir %s' % project_dir) + project_name = os.path.basename(os.path.dirname(project_dir)) + logging.debug('project name is %s' % project_name) + if self.is_released(project_name, project_dir): + if self.settings['verbose']: + self.output.write('released: %s\n' % project_dir) + else: + self.output.write('UNRELEASED: %s\n' % project_dir) + + def is_released(self, project_name, project_dir): + logging.debug('is_released: project_name=%s project_dir=%s' % + (project_name, project_dir)) + + revno = self.bzr_revno(project_dir) + logging.debug('revno = %s' % repr(revno)) + if revno is None: + logging.debug('no revno, so not released') + return False + + tags = self.bzr_tags(project_dir) + logging.debug('found tags: %s' % repr(tags)) + + pat = r'^%s-\d+(\.\d+)*$' % project_name + logging.debug('tag pattern = %s' % repr(pat)) + + for tag_revno, tag in tags: + logging.debug('tag_revno=%s' % repr(tag_revno)) + logging.debug('tag=%s' % repr(tag)) + if re.match(pat, tag): + result = [revno] < tag_revno + logging.debug('return: %s' % result) + return result + logging.debug('returning default result of False') + return False + + def bzr_revno(self, project_dir): + return int(self.runcmd(['bzr', 'revno'], cwd=project_dir).strip()) + + def bzr_tags(self, project_dir): + out = self.runcmd(['bzr', 'tags'], cwd=project_dir) + pairs = [line.split() for line in out.splitlines()] + pairs2 = [(self.revno_key(revno), tag) for tag, revno in pairs] + return list(reversed(sorted(pairs2))) + + def revno_key(self, revno_string): + return [int(x) for x in revno_string.split('.')] + + def project_dirs(self): + homedir = os.path.expanduser('~') + return [os.path.join(homedir, os.path.dirname(x), 'trunk') + for x in self.bug_dirs()] + + def bug_dirs(self): + return [line.split()[0] + for line in self.cat(self.conf_file).splitlines() + if line.strip()] + + def cat(self, filename): + with open(filename) as f: + return f.read() + + + + +if __name__ == '__main__': + UnreleasedProjects().run() -- cgit v1.2.1