mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +01:00
release: Use optparse to handle arguments instead of doing it manually
Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
parent
a31350f14a
commit
d1bf3feaea
@ -5,6 +5,8 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
def firstLines(filename, n):
|
def firstLines(filename, n):
|
||||||
fd = file(filename)
|
fd = file(filename)
|
||||||
lines = []
|
lines = []
|
||||||
@ -27,13 +29,6 @@ def system(sh, errmsg=None):
|
|||||||
if ret:
|
if ret:
|
||||||
error(errmsg + ' (error code: %s)' % ret)
|
error(errmsg + ' (error code: %s)' % ret)
|
||||||
|
|
||||||
def usage():
|
|
||||||
error('Usage: %s [-s|-n] <sf username> <version>\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():
|
def checkGitRepo():
|
||||||
system('test "$(git rev-parse --is-inside-work-tree)" = "true"',
|
system('test "$(git rev-parse --is-inside-work-tree)" = "true"',
|
||||||
'Must be run from a git checkout.')
|
'Must be run from a git checkout.')
|
||||||
@ -46,28 +41,28 @@ def checkGitRepo():
|
|||||||
'Your tree is unclean. Can\'t run from here.')
|
'Your tree is unclean. Can\'t run from here.')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 3 or len(sys.argv) > 5:
|
usage = 'usage: %prog [options] <username> <version>'
|
||||||
usage()
|
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()
|
checkGitRepo()
|
||||||
|
|
||||||
sign = ''
|
sign = options.sign
|
||||||
dryrun = False
|
dryrun = options.dry_run
|
||||||
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.')
|
|
||||||
|
|
||||||
if os.path.exists('supybot'):
|
if os.path.exists('supybot'):
|
||||||
error('I need to make the directory "supybot" but it already exists.'
|
error('I need to make the directory "supybot" but it already exists.'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user