Permalink
Browse files

Merge pull request #156 from DavidS48/do_something

Added support for logging SVN repo/commit information.
  • Loading branch information...
robintw committed Sep 19, 2016
2 parents cc121f9 + 3b0f6b9 commit ff440db241f83cb1981301802e0a52ee8c4a61cc
View
@@ -12,7 +12,7 @@
import difflib
import warnings
from recipyCommon.version_control import add_git_info, hash_file
from recipyCommon.version_control import add_git_info, add_svn_info, hash_file
from recipyCommon.config import option_set, get_db_path
from recipyCommon.utils import open_or_create_db
from recipyCommon.libraryversions import get_version
@@ -73,6 +73,10 @@ def log_init():
if not option_set('ignored metadata', 'git'):
add_git_info(run, scriptpath)
if not option_set('ignored metadata', 'svn'):
add_svn_info(run, scriptpath)
# Put basics into DB
RUN_ID = db.insert(run)
View
@@ -55,6 +55,9 @@
{% if gitcommit is defined %}
\aGit:\b commit {{ gitcommit }}, in repo {{ gitrepo }}, with origin {{ gitorigin }}
{% endif %}
{% if svnrepo is defined %}
\aSvn:\b commit {{ svncommit }}, in repo {{ svnrepo }}.
{% endif %}
\aEnvironment:\b {{ environment|join(", ") }}
{% if libraries is defined %}
\aLibraries:\b {{ libraries|join(", ") }}
@@ -1,4 +1,6 @@
from git import Repo, InvalidGitRepositoryError
import svn.local
import subprocess
import hashlib
from recipyCommon.config import option_set
@@ -43,3 +45,42 @@ def add_git_info(run, scriptpath):
except (InvalidGitRepositoryError, ValueError):
# We can't store git info for some reason, so just skip it
pass
# The released version of PySvn doesn't do local diffs yet, so we have to do
# it the hard way...
class SvnException(Exception):
pass
def svn_diff(path):
"""
Run svn diff for the given path and return the result. Raise SvnException
if the command doesn't return 0.
"""
cmd = ["svn", "diff", path]
p = subprocess.Popen(cmd,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT,
env={"LANG" : "en_US.UTF-8"})
stdout = p.stdout.read()
r = p.wait()
if r != 0:
raise SvnException("SVN Command exited with status code {0}".format(r))
return stdout.decode()
def add_svn_info(run, scriptpath):
"""
Add information about the svn repository holding the source file to the
database.
"""
try:
svn_client = svn.local.LocalClient(scriptpath)
svn_info = svn_client.info()
run["svnrepo"] = svn_info["repository_root"]
run["svncommit"] = svn_info["commit_revision"]
if not option_set('ignored metadata', 'diff'):
run['diff'] = svn_diff(svn_info["wc-info/wcroot-abspath"])
except (SvnException, ValueError):
# We can't access svn info for some reason, so just skip it
pass
@@ -213,6 +213,44 @@ <h3>Git</h3>
</div>
{% endif %}
{% if run.svnrepo %}
<div class="row">
<div class="col-md-12">
<h3>SVN</h3>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-condensed">
<tr>
<td class="col-md-1">SVN Repo</td>
<td>
<a href="{{ run.svnrepo | safe }}">{{ run.svnrepo | safe }}</a>
</td>
</tr>
<tr>
<td class="col-md-1">SVN Commit</td>
<td>
{{ run.svncommit | safe }}
</td>
</tr>
<tr>
<td class="col-md-1">SVN diff</td>
{% if run.diff and run.diff | length > 0 %}
<td style="padding: 0;">
{{ run.diff | colordiff | highlight(query) | safe }}
</td>
{% else %}
<td>No changes</td>
{% endif %}
</tr>
</table>
</div>
</div>
{% endif %}
{% if diffs | length > 0 %}
<div class="row">
<div class="col-md-12">
@@ -80,7 +80,43 @@ def create_app(self):
'script': 'C:\\Code\\test-recipy\\example_script2.py',
'unique_id': '6daab87a-8cf2-4e3d-afb9-1ee5b6b8ecdb'
},
# Run with warnings
# SVN info present
{
'author': 'Robin',
'command': 'C:\\Anaconda3\\python.exe',
'date': '{TinyDate}:2015-08-22T08:42:59',
'description': '',
'diff': None,
'environment': ['Windows-7-6.1.7601-SP1', 'python 3.4.3 |Anaconda 2.2.0 (64-bit)| (default, Mar 6 2015, 12:06:10) [MSC v.1600 64 bit (AMD64)]'],
'svncommit': '43513',
'svnrepo' : "http://www.testrepo.org/repo",
'gitcommit' : None,
'gitorigin': None,
'gitrepo': None,
'inputs': [],
'outputs': ['C:\\Code\\test-recipy\\testNGCM_2.npy'],
'script': 'C:\\Code\\test-recipy\\example_script2.py',
'unique_id': '6daab87a-8cf2-4e3d-afb9-1ee5b6b8ecdb'
},
# SVN and git info both present
{
'author': 'Robin',
'command': 'C:\\Anaconda3\\python.exe',
'date': '{TinyDate}:2015-08-22T08:42:59',
'description': '',
'diff': None,
'environment': ['Windows-7-6.1.7601-SP1', 'python 3.4.3 |Anaconda 2.2.0 (64-bit)| (default, Mar 6 2015, 12:06:10) [MSC v.1600 64 bit (AMD64)]'],
'gitcommit': 'c681315966a9fca0662f57ac45191eb9fdc8cd9c',
'gitorigin': None,
'gitrepo': "/home/jvdzwaan/code/recipy-demo",
'svncommit': '43513',
'svnrepo' : "http://www.testrepo.org/repo",
'inputs': [],
'outputs': ['C:\\Code\\test-recipy\\testNGCM_2.npy'],
'script': 'C:\\Code\\test-recipy\\example_script2.py',
'unique_id': '6daab87a-8cf2-4e3d-afb9-1ee5b6b8ecdb'
},
# Run with warnings
{
"author": "jvdzwaan",
"command": "/home/jvdzwaan/.virtualenvs/recipy/bin/python",
View
@@ -1,6 +1,7 @@
setuptools
wrapt
GitPython
svn
flask
Flask-Script
flask_bootstrap
View
@@ -71,7 +71,7 @@
install_requires=['wrapt', 'tinydb>=3.0.0', 'tinydb-serialization',
'jinja2', 'docopt', 'GitPython', 'Flask', 'colorama',
'Flask-Script', 'flask_bootstrap', 'flask-wtf',
'python-dateutil', 'six'],
'python-dateutil', 'six', "svn"],
entry_points={
'console_scripts': [

0 comments on commit ff440db

Please sign in to comment.