-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from michaeljoseph/replace-iterpipes-with-sh
Replace iterpipes with sh
- Loading branch information
Showing
17 changed files
with
183 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from subprocess import Popen, PIPE, CalledProcessError | ||
|
||
|
||
def check_output(*popenargs, **kwargs): | ||
""" | ||
Run command with arguments and return its output as a byte string. | ||
Backported from Python 2.7 as it's implemented as pure python on stdlib. | ||
>>> check_output(['/usr/bin/python', '--version']) | ||
Python 2.6.2 | ||
""" | ||
process = Popen(stdout=PIPE, *popenargs, **kwargs) | ||
output, unused_err = process.communicate() | ||
retcode = process.poll() | ||
if retcode: | ||
cmd = kwargs.get("args") | ||
if cmd is None: | ||
cmd = popenargs[0] | ||
error = CalledProcessError(retcode, cmd) | ||
error.output = output | ||
raise error | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import logging | ||
|
||
import iterpipes | ||
from changes import config | ||
from changes.compat import check_output, CalledProcessError | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def handle_dry_run(function, *args): | ||
if not config.arguments.get('--dry-run', True): | ||
return function(*args) | ||
else: | ||
log.debug('dry run of %s %s, skipping' % (function, args)) | ||
return True | ||
|
||
|
||
def execute(command, dry_run=True): | ||
log.debug('executing %s', command) | ||
if not dry_run: | ||
try: | ||
return [result for result in iterpipes.linecmd(command)(None)] | ||
except iterpipes.CalledProcessError, e: | ||
return check_output(command.split(' ')).split('\n') | ||
except CalledProcessError as e: | ||
log.debug('return code: %s, output: %s', e.returncode, e.output) | ||
return False | ||
else: | ||
log.debug('dry run of %s, skipping' % command) | ||
return True |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
import logging | ||
|
||
import sh | ||
|
||
from changes import config, shell | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def commit_version_change(): | ||
app_name, dry_run, new_version = config.common_arguments() | ||
|
||
command = 'git commit -m %s %s/__init__.py %s' % ( | ||
new_version, app_name, config.CHANGELOG | ||
commit_result = shell.handle_dry_run( | ||
sh.git.commit, | ||
('-m', new_version, '%s/__init__.py' % app_name, config.CHANGELOG) | ||
) | ||
|
||
if not (shell.execute(command, dry_run=dry_run) and | ||
shell.execute('git push', dry_run=dry_run)): | ||
raise Exception('Version change commit failed') | ||
if commit_result: | ||
push_result = shell.handle_dry_run(sh.git.push, ()) | ||
if not push_result: | ||
raise Exception('Version change commit failed') | ||
|
||
|
||
def tag(): | ||
_, dry_run, new_version = config.common_arguments() | ||
|
||
shell.execute( | ||
'git tag -a %s -m "%s"' % (new_version, new_version), | ||
dry_run=dry_run | ||
tag_result = shell.handle_dry_run( | ||
sh.git.tag, | ||
('-a', new_version, '-m', '"%s"' % new_version) | ||
) | ||
shell.execute('git push --tags', dry_run=dry_run) | ||
|
||
if tag_result: | ||
push_tags_result = shell.handle_dry_run(sh.git.push, ('--tags')) | ||
if not push_tags_result: | ||
raise Exception('Tagging failed') |
Oops, something went wrong.