-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
from tempfile import mkdtemp | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def check(data): | ||
"""Run p.r.codeanalysis when releasing with zest.releaser.""" | ||
from zest.releaser.utils import ask | ||
if not ask('Run code analysis before tagging?'): | ||
return | ||
|
||
filename = '{0}/status.rst'.format(os.path.realpath(mkdtemp())) | ||
try: | ||
with open(filename, 'w') as output: | ||
subprocess.call(['bin/code-analysis'], stdout=output) | ||
with open(filename) as output: | ||
print(''.join(output.readlines())) | ||
except Exception as e: | ||
print(e) | ||
msg = 'Something went wrong when running "bin/code-analysis". ' \ | ||
'Do you want to continue despite that?' | ||
if not ask(msg, default=False): | ||
sys.exit(1) | ||
else: | ||
msg = 'Do you want to write code analysis result on status.rst?' | ||
if ask(msg, default=True): | ||
with open(filename) as output: | ||
status_text = [ | ||
clean_line(line) | ||
for line in output.readlines() | ||
] | ||
|
||
with open('status.rst', 'w') as code_analyis_file: | ||
code_analyis_file.write(' ') | ||
code_analyis_file.write(' '.join(status_text)) | ||
|
||
# It's nice to clean up the temporal file, but if something happens while | ||
# trying to remove it, just ignore it | ||
try: | ||
os.remove(filename) | ||
except Exception: | ||
pass | ||
|
||
|
||
def clean_line(line): | ||
"""Remove console coloring from lines.""" | ||
# error (codes taken from Analyser.log) | ||
line = line.replace('\033[00;31m', '') | ||
line = line.replace('\033[0m', '') | ||
|
||
# ok (codes taken from Analyser.colors) | ||
line = line.replace('\033[00;32m', '') | ||
line = line.replace('\033[0m', '') | ||
return line |
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