summaryrefslogtreecommitdiff
path: root/scripts/unreleased-projects
blob: 7639780e39b498f9ab38132f46fe22540266d3b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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 <http://www.gnu.org/licenses/>.


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+)*(_debian-[0-9.-]+)?$' % 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):
                release_tag_is_current = tag_revno == [revno]
                logging.debug('return: %s' % release_tag_is_current)
                return release_tag_is_current
        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()