aboutsummaryrefslogtreecommitdiff
path: root/egg-author.py
blob: c897f047c6c864410a7832840875ba4237dfa5bd (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
# egg-authors.py
#
# Just drop this file in your ~/.hg directory and add
# the following lines to your .hgrc:
#
# [extensions]
# egg-author=~/.hg/egg-author.py
#
# This silly file may be used and distributed according to the terms of
# the GNU General Public License, version 2 or later "(at your option)".
#
# See http://mercurial.selenic.com/wiki/License for more info, including
# a link to the license text.
#
# TODO: Add automatic meta-file updates when tagging tip?  Or perhaps
# based on a repo-specific setting, since people using the tarball method
# might not want their meta-files cluttered with long lists of files...

'''Tools to help make egg authors' lives easier'''

import fnmatch, re
from mercurial.i18n import _
from mercurial import cmdutil, commands, util
import mercurial.match as matchmod

# This is probably really really dumb code. I don't know python
def _find_release_info_file(repo):
    stat = repo.status(clean=True)
    
    for x in stat[:5]:
        for fn in x:
            if fnmatch.fnmatch(fn, '*.release-info'):
                raise util.Abort(_('%s is modified (please commit or revert '
                                   'and retry)') % fn)
    
    release_info_file = None
    
    for x in stat[5:]:
        for fn in x:
            if fnmatch.fnmatch(fn, "*.release-info"):
                if release_info_file:
                    raise util.Abort(_('Found more than one release-info file!'))
                else:
                    release_info_file = fn

    if not release_info_file:
        raise util.Abort(_('Could not find release-info file. You need to '
                           'create one first. See %s for more info.')
                         % 'http://wiki.call-cc.org/releasing-your-egg')
    
    return release_info_file

def _clean_scheme_string(s):
    # This is a pathetic attempt at being safe. You shouldn't be using
    # these names anywway, and the user should be already be trusted when
    # they're allowed to commit.
    return re.sub(r'\\', r'\\\\', re.sub(r'"', r'\\"', s))

def eggtag(ui, repo, name1, *names, **opts):
    '''Tag a Chicken egg for release.

    The syntax is identical to "hg tag", which it executes
    automatically.  This command just adds a (release ..) entry to
    your .release-info file for each tag.
    '''
    allnames = [t.strip() for t in (name1,) + names]

    release_info_file = _find_release_info_file(repo)
    fp = repo.wfile(release_info_file, 'r+')
    commands.tag(ui, repo, name1, *names, **opts)
    
    # if hg's original tag command succeeded, we can do our stuff
    relinfo_message = ('Updated release-info file for release tag %s' % (', '.join(allnames)))
    fp.seek(0, 2) # to the end
    for n in allnames:
        fp.write("(release \"%s\")\n" % _clean_scheme_string(n))
    fp.close()

    m = matchmod.exact(repo.root, '', [release_info_file])
    repo.commit(text=relinfo_message, user=opts.get('user'), date=opts.get('date'), match=m)

cmdtable = {
    "eggtag": (eggtag,
               [('r', 'rev', '',
                 _('revision to tag'), _('REV')),
                ('', 'remove', None, _('remove a tag')),
                ('e', 'edit', None, _('edit commit message')),
                ('m', 'message', '',
                 _('use <text> as commit message'), _('TEXT')),
                ],
               "hg eggtag [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...")
}