1
0
Fork 0
pgcli/release.py

114 lines
2.6 KiB
Python
Raw Normal View History

2014-12-15 00:06:25 +00:00
#!/usr/bin/env python
2014-12-18 18:33:14 +00:00
from __future__ import print_function
2014-12-15 00:06:25 +00:00
import re
import ast
import subprocess
2014-12-18 18:30:58 +00:00
import sys
from optparse import OptionParser
2014-12-15 00:06:25 +00:00
2014-12-15 00:21:17 +00:00
DEBUG = False
CONFIRM_STEPS = False
DRY_RUN = False
def skip_step():
"""
Asks for user's response whether to run a step. Default is yes.
:return: boolean
"""
global CONFIRM_STEPS
if CONFIRM_STEPS:
choice = raw_input("--- Confirm step? (y/N) [y] ")
if choice.lower() == 'n':
return True
return False
def run_step(*args):
"""
Prints out the command and asks if it should be run.
If yes (default), runs it.
:param args: list of strings (command and args)
"""
global DRY_RUN
cmd = args
print(' '.join(cmd))
if skip_step():
print('--- Skipping...')
elif DRY_RUN:
print('--- Pretending to run...')
else:
subprocess.check_output(cmd)
2014-12-15 00:21:17 +00:00
def version(version_file):
2014-12-15 00:06:25 +00:00
_version_re = re.compile(r'__version__\s+=\s+(.*)')
2014-12-15 00:21:17 +00:00
with open(version_file, 'rb') as f:
ver = str(ast.literal_eval(_version_re.search(
2014-12-15 00:06:25 +00:00
f.read().decode('utf-8')).group(1)))
2014-12-15 00:21:17 +00:00
return ver
2014-12-15 00:21:17 +00:00
def commit_for_release(version_file, ver):
run_step('git', 'reset')
run_step('git', 'add', version_file)
run_step('git', 'commit', '--message', 'Releasing version %s' % ver)
2014-12-15 00:06:25 +00:00
def create_git_tag(tag_name):
run_step('git', 'tag', tag_name)
2014-12-15 00:06:25 +00:00
def register_with_pypi():
run_step('python', 'setup.py', 'register')
2014-12-15 00:06:25 +00:00
def create_source_tarball():
run_step('python', 'setup.py', 'sdist')
2014-12-15 00:06:25 +00:00
2015-04-03 01:23:29 +00:00
def push_to_github():
run_step('git', 'push', 'origin', 'master')
2015-04-03 01:23:29 +00:00
2015-01-31 23:28:38 +00:00
def push_tags_to_github():
run_step('git', 'push', '--tags', 'origin')
2015-01-31 23:28:38 +00:00
2014-12-15 00:06:25 +00:00
if __name__ == '__main__':
2014-12-15 00:21:17 +00:00
if DEBUG:
subprocess.check_output = lambda x: x
ver = version('pgcli/__init__.py')
2014-12-18 18:33:14 +00:00
print('Releasing Version:', ver)
parser = OptionParser()
parser.add_option(
"-c", "--confirm-steps", action="store_true", dest="confirm_steps",
default=False, help=("Confirm every step. If the step is not "
"confirmed, it will be skipped.")
)
parser.add_option(
"-d", "--dry-run", action="store_true", dest="dry_run",
default=False, help="Print out, but not actually run any steps."
)
popts, pargs = parser.parse_args()
CONFIRM_STEPS = popts.confirm_steps
DRY_RUN = popts.dry_run
choice = raw_input('Are you sure? (y/N) [n] ')
2014-12-18 18:30:58 +00:00
if choice.lower() != 'y':
sys.exit(1)
2014-12-15 00:21:17 +00:00
commit_for_release('pgcli/__init__.py', ver)
2014-12-15 00:06:25 +00:00
create_git_tag('v%s' % ver)
register_with_pypi()
create_source_tarball()
2015-04-03 01:23:29 +00:00
push_to_github()
2015-01-31 23:28:38 +00:00
push_tags_to_github()