From a31350f14a8ed1c1445b9cc872e43102c59da21f Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Fri, 20 Aug 2010 10:31:05 -0400 Subject: [PATCH 1/7] Consolidate the version string to reside in one central place to ease change making. Signed-off-by: James McCoy --- sandbox/release.py | 2 +- scripts/supybot | 3 ++- setup.py | 3 ++- src/conf.py | 2 +- src/version.py | 3 +++ 5 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/version.py diff --git a/sandbox/release.py b/sandbox/release.py index 0538e6c30..18230630f 100644 --- a/sandbox/release.py +++ b/sandbox/release.py @@ -90,7 +90,7 @@ if __name__ == '__main__': error('Invalid third line in ChangeLog.') print 'Updating version in version files.' - versionFiles = ('src/conf.py', 'scripts/supybot', 'setup.py') + versionFiles = ['src/version.py'] for fn in versionFiles: sh = 'perl -pi -e "s/^version\s*=.*/version = \'%s\'/" %s' % (v, fn) system(sh, 'Error changing version in %s' % fn) diff --git a/scripts/supybot b/scripts/supybot index 83c1eefe4..1ebf73322 100644 --- a/scripts/supybot +++ b/scripts/supybot @@ -65,6 +65,8 @@ import supybot.utils as utils import supybot.registry as registry import supybot.questions as questions +from supybot.version import version + def main(): import supybot.conf as conf import supybot.world as world @@ -125,7 +127,6 @@ def main(): log.info('Total CPU time taken: %s seconds.', user+system) log.info('No more Irc objects, exiting.') -version = '0.83.4.1+git' if __name__ == '__main__': ### # Options: diff --git a/setup.py b/setup.py index de6b483ad..beaae41c4 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,8 @@ import glob import shutil import os.path +from src.version import version + plugins = [s for s in os.listdir('plugins') if os.path.exists(os.path.join('plugins', s, 'plugin.py'))] @@ -116,7 +118,6 @@ package_dir = {'supybot': 'src', for plugin in plugins: package_dir['supybot.plugins.' + plugin] = 'plugins/' + plugin -version = '0.83.4.1+git' setup( # Metadata name='supybot', diff --git a/src/conf.py b/src/conf.py index 89111a010..72952695a 100644 --- a/src/conf.py +++ b/src/conf.py @@ -40,7 +40,7 @@ import supybot.ircutils as ircutils ### # version: This should be pretty obvious. ### -version = '0.83.4.1+git' +from supybot.version import version ### # *** The following variables are affected by command-line options. They are diff --git a/src/version.py b/src/version.py new file mode 100644 index 000000000..df82bea75 --- /dev/null +++ b/src/version.py @@ -0,0 +1,3 @@ +"""stick the various versioning attributes in here, so we only have to change +them once.""" +version = '0.83.4.1+git' From d1bf3feaea2e9d9524bbc076ee10e5e96f0ab370 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 9 Jun 2012 14:38:50 -0400 Subject: [PATCH 2/7] release: Use optparse to handle arguments instead of doing it manually Signed-off-by: James McCoy --- sandbox/release.py | 47 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/sandbox/release.py b/sandbox/release.py index 18230630f..66d3e4a35 100644 --- a/sandbox/release.py +++ b/sandbox/release.py @@ -5,6 +5,8 @@ import re import sys import shutil +from optparse import OptionParser + def firstLines(filename, n): fd = file(filename) lines = [] @@ -27,13 +29,6 @@ def system(sh, errmsg=None): if ret: error(errmsg + ' (error code: %s)' % ret) -def usage(): - error('Usage: %s [-s|-n] \nSpecify -s to pass it on ' - 'to the relevant git commands.\nSpecify -n to perform a dry-run ' - 'release. No commits or tags are pushed and no files are uploaded.' - '\nMust be called from a git checkout.' - % sys.argv[0]) - def checkGitRepo(): system('test "$(git rev-parse --is-inside-work-tree)" = "true"', 'Must be run from a git checkout.') @@ -46,28 +41,28 @@ def checkGitRepo(): 'Your tree is unclean. Can\'t run from here.') if __name__ == '__main__': - if len(sys.argv) < 3 or len(sys.argv) > 5: - usage() + usage = 'usage: %prog [options] ' + parser = OptionParser(usage=usage) + parser.set_defaults(sign=False, verbose=False) + parser.add_option('-s', '--sign', action='store_true', dest='sign', + help='Pass on -s to relevant git commands') + parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run', + help='Build the release, but do not push to the git ' + 'remote or upload the release archives.') + (options, args) = parser.parse_args() + + if len(args) != 2: + parser.error('Both username and version must be specified') + + (u, v) = args + if not re.match(r'^\d+\.\d+\.\d+(\.\d+)?\w*$', v): + parser.error('Invalid version string: ' + 'must be of the form MAJOR.MINOR.PATCHLEVEL') checkGitRepo() - sign = '' - dryrun = False - while len(sys.argv) > 3: - if sys.argv[1] == '-s': - sign = '-s' - sys.argv.pop(1) - elif sys.argv[1] == '-n': - dryrun = True - sys.argv.pop(1) - else: - usage() - - print 'Check version string for validity.' - (u, v) = sys.argv[1:] - if not re.match(r'^\d+\.\d+\.\d+(\.\d+)?\w*$', v): - error('Invalid version string: ' - 'must be of the form MAJOR.MINOR.PATCHLEVEL.') + sign = options.sign + dryrun = options.dry_run if os.path.exists('supybot'): error('I need to make the directory "supybot" but it already exists.' From fefacf5b2feea8fa463669717304b6cb74cae52e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 17 Jun 2012 09:36:29 -0400 Subject: [PATCH 3/7] release: Allow specifying a branch to cut the release from. Signed-off-by: James McCoy --- sandbox/release.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sandbox/release.py b/sandbox/release.py index 66d3e4a35..e713ea7bb 100644 --- a/sandbox/release.py +++ b/sandbox/release.py @@ -43,12 +43,14 @@ def checkGitRepo(): if __name__ == '__main__': usage = 'usage: %prog [options] ' parser = OptionParser(usage=usage) - parser.set_defaults(sign=False, verbose=False) + parser.set_defaults(sign=False, verbose=False, branch='master') parser.add_option('-s', '--sign', action='store_true', dest='sign', help='Pass on -s to relevant git commands') parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run', help='Build the release, but do not push to the git ' 'remote or upload the release archives.') + parser.add_option('-b', '--branch', metavar='BRANCH', dest='branch', + help='Branch to use for the release. Default: %default') (options, args) = parser.parse_args() if len(args) != 2: @@ -63,14 +65,15 @@ if __name__ == '__main__': sign = options.sign dryrun = options.dry_run + branch = options.branch if os.path.exists('supybot'): error('I need to make the directory "supybot" but it already exists.' ' Change to an appropriate directory or remove the supybot ' 'directory to continue.') print 'Checking out fresh tree from git.' - system('git clone git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' - % u) + system('git clone -b %s git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' + % (branch, u)) os.chdir('supybot') print 'Checking RELNOTES version line.' @@ -105,7 +108,7 @@ if __name__ == '__main__': if not dryrun: print 'Pushing commits and tag.' - system('git push origin master') + system('git push origin %s' % branch) system('git push --tags') print 'Creating tarball (gzip).' From e6d361fc922ed5cc408a2c56b735f0b7d4e27407 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 17 Jun 2012 10:30:17 -0400 Subject: [PATCH 4/7] release: Revamp to use subprocess instead of os.system Signed-off-by: James McCoy --- sandbox/release.py | 67 +++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/sandbox/release.py b/sandbox/release.py index e713ea7bb..92fc70ec7 100644 --- a/sandbox/release.py +++ b/sandbox/release.py @@ -4,6 +4,7 @@ import os import re import sys import shutil +import subprocess from optparse import OptionParser @@ -13,6 +14,7 @@ def firstLines(filename, n): while n: n -= 1 lines.append(fd.readline().rstrip('\r\n')) + fd.close() return lines def firstLine(filename): @@ -22,23 +24,29 @@ def error(s): sys.stderr.write(s+'\n') sys.exit(-1) -def system(sh, errmsg=None): +def system(sh, errmsg=None, **kwargs): if errmsg is None: - errmsg = repr(sh) - ret = os.system(sh) + if isinstance(sh, basestring): + errmsg = repr(sh) + else: + errmsg = repr(' '.join(sh)) + ret = subprocess.call(sh, **kwargs) if ret: error(errmsg + ' (error code: %s)' % ret) def checkGitRepo(): system('test "$(git rev-parse --is-inside-work-tree)" = "true"', - 'Must be run from a git checkout.') + 'Must be run from a git checkout.', + shell=True) system('test "$(git rev-parse --show-cdup >/dev/null)" = ""', - 'Must be run from the top-level directory of the git checkout.') + 'Must be run from the top-level directory of the git checkout.', + shell=True) system('git rev-parse --verify HEAD >/dev/null ' '&& git update-index --refresh' '&& git diff-files --quiet' '&& git diff-index --cached --quiet HEAD --', - 'Your tree is unclean. Can\'t run from here.') + 'Your tree is unclean. Can\'t run from here.', + shell=True) if __name__ == '__main__': usage = 'usage: %prog [options] ' @@ -72,8 +80,8 @@ if __name__ == '__main__': ' Change to an appropriate directory or remove the supybot ' 'directory to continue.') print 'Checking out fresh tree from git.' - system('git clone -b %s git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' - % (branch, u)) + system(['git', 'clone', '-b', branch, + 'git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' % u]) os.chdir('supybot') print 'Checking RELNOTES version line.' @@ -90,36 +98,45 @@ if __name__ == '__main__': print 'Updating version in version files.' versionFiles = ['src/version.py'] for fn in versionFiles: - sh = 'perl -pi -e "s/^version\s*=.*/version = \'%s\'/" %s' % (v, fn) + sh = ['perl', '-pi', '-e', 's/^version\s*=.*/version = \'%s\'/' % v, fn] system(sh, 'Error changing version in %s' % fn) - system('git commit %s -m \'Updated to %s.\' %s' - % (sign, v, ' '.join(versionFiles))) + commit = ['git', 'commit'] + if sign: + commit.append('-s') + system(commit + ['-m', 'Updated to %s.' % v] + versionFiles) print 'Tagging release.' - system('git tag %s -m "Release %s" %s' % (sign or '-a', v, v)) + tag = ['git', 'tag'] + if sign: + tag.append('-s') + system(tag + ['-m', "Release %s" % v, 'v%s' % v]) print 'Committing %s+git to version files.' % v for fn in versionFiles: - sh = 'perl -pi -e "s/^version\s*=.*/version = \'%s\'/" %s' % \ - (v + '+git', fn) - system(sh, 'Error changing version in %s' % fn) - system('git commit %s -m \'Updated to %s+git.\' %s' - % (sign, v, ' '.join(versionFiles))) + system(['perl', '-pi', '-e', + 's/^version\s*=.*/version = \'%s+git\'/' % v, fn], + 'Error changing version in %s' % fn) + system(commit + ['-m', 'Updated to %s+git.' % v] + versionFiles) if not dryrun: print 'Pushing commits and tag.' - system('git push origin %s' % branch) - system('git push --tags') + system(['git', 'push', 'origin', branch]) + system(['git', 'push', '--tags']) + archive = ['git', 'archive', '--prefix=Supybot-%s/' % v] print 'Creating tarball (gzip).' - system('git archive --prefix=Supybot-%s/ --format=tar %s ' - '| gzip -c >../Supybot-%s.tar.gz' % (v, v, v)) + system(archive + ['-o', '../Supybot-%s.tar.gz' % v, + '--format=tgz', 'v%s' % v]) + + system(['git', 'config', 'tar.bz2.command', 'bzip2 -c']) + print 'Creating tarball (bzip2).' - system('git archive --prefix=Supybot-%s/ --format=tar %s ' - '| bzip2 -c >../Supybot-%s.tar.bz2' % (v, v, v)) + system(archive + ['-o', '../Supybot-%s.tar.bz2' % v, + '--format=bz2', 'v%s' % v]) + print 'Creating zip.' - system('git archive --prefix=Supybot-%s/ --format=zip %s ' - '>../Supybot-%s.zip' % (v, v, v)) + system(archive + ['-o', '../Supybot-%s.zip' % v, + '--format=zip', 'v%s' % v]) os.chdir('..') shutil.rmtree('supybot') From f8824458b38dc620eb1a3b1ef962ff4fef220aa3 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 17 Jun 2012 10:34:23 -0400 Subject: [PATCH 5/7] release: Fix repository location Signed-off-by: James McCoy --- sandbox/release.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox/release.py b/sandbox/release.py index 92fc70ec7..bc90db6e5 100644 --- a/sandbox/release.py +++ b/sandbox/release.py @@ -80,8 +80,8 @@ if __name__ == '__main__': ' Change to an appropriate directory or remove the supybot ' 'directory to continue.') print 'Checking out fresh tree from git.' - system(['git', 'clone', '-b', branch, - 'git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot' % u]) + repo = 'git+ssh://%s@supybot.git.sourceforge.net/gitroot/supybot/supybot' % u + system(['git', 'clone', '-b', branch, repo]) os.chdir('supybot') print 'Checking RELNOTES version line.' From 786d184b0af21dc3c1edaf2b8d35ecce835ffcb7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 17 Jun 2012 11:46:07 -0400 Subject: [PATCH 6/7] setup.py: Correct homepage metadata Signed-off-by: James McCoy --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index beaae41c4..aee29eb97 100644 --- a/setup.py +++ b/setup.py @@ -123,7 +123,7 @@ setup( name='supybot', version=version, author='Jeremy Fincher', - url='http://supybot.com/', + url='http://sourceforge.net/projects/supybot/', author_email='jemfinch@supybot.com', download_url='http://www.sf.net/project/showfiles.php?group_id=58965', description='A flexible and extensible Python IRC bot and framework.', From a42ab2e2d493bc37b0674df4bb8fd89ec0f9bdbd Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 2 Jul 2012 21:11:50 -0400 Subject: [PATCH 7/7] ircutils.FormatParser: Make getInt only get integers that are valid colors If a colored message were wrapped just right (e.g., a colored number ending the chunk), FormatParser would gobble up the color format code and the number in the message, causing a KeyError when trying to look up the color in mircColors. Signed-off-by: James McCoy --- plugins/Filter/plugin.py | 3 ++- src/ircutils.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index 389dcd5de..68dbc42b5 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -357,7 +357,8 @@ class Filter(callbacks.Plugin): if c == ' ': return c if fg is None: - fg = str(random.randint(2, 15)).zfill(2) + fg = random.randint(2, 15) + fg = str(fg).zfill(2) return '\x03%s%s' % (fg, c) def colorize(self, irc, msg, args, text): diff --git a/src/ircutils.py b/src/ircutils.py index 2b03797b9..c39e73ad5 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -410,11 +410,16 @@ class FormatParser(object): i = 0 setI = False c = self.getChar() - while c.isdigit() and i < 100: - setI = True - i *= 10 - i += int(c) - c = self.getChar() + while c.isdigit(): + j = i * 10 + j += int(c) + if j >= 16: + self.ungetChar(c) + break + else: + setI = True + i = j + c = self.getChar() self.ungetChar(c) if setI: return i @@ -426,6 +431,8 @@ class FormatParser(object): c = self.getChar() if c == ',': context.bg = self.getInt() + else: + self.ungetChar(c) def wrap(s, length): processed = []