Commit a0a868b8 authored by Michal Čihař's avatar Michal Čihař

Merge branch 'master' into bootstrap

parents 7c22f2c8 278fd4e3
......@@ -29,7 +29,7 @@ from weblate import settings_example
from weblate import appsettings
from weblate.accounts.avatar import HAS_LIBRAVATAR
from weblate.accounts.forms import HAS_ICU
from weblate.trans.util import get_configuration_errors
from weblate.trans.util import get_configuration_errors, get_clean_env
import weblate
import django
......@@ -261,6 +261,7 @@ def generate_ssh_key(request):
'-f', RSA_KEY_FILE[:-4]
],
stderr=subprocess.STDOUT,
env=get_clean_env(),
)
messages.success(request, _('Created new SSH key.'))
except (subprocess.CalledProcessError, OSError) as exc:
......@@ -288,6 +289,7 @@ def add_host_key(request):
output = subprocess.check_output(
cmdline,
stderr=subprocess.STDOUT,
env=get_clean_env(),
)
keys = [
line
......@@ -329,6 +331,7 @@ def ssh(request):
['which', 'ssh-keygen'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=get_clean_env(),
)
can_generate = (ret == 0 and not os.path.exists(RSA_KEY_FILE))
except subprocess.CalledProcessError:
......
......@@ -32,6 +32,7 @@ from translate.storage import mo
from translate.storage import factory
from weblate.trans.util import get_string, join_plural, add_configuration_error
from translate.misc import quote
from weblate.trans.util import get_clean_env
import weblate
import subprocess
import os.path
......@@ -695,6 +696,7 @@ class PoFormat(FileFormat):
['msginit', '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=get_clean_env(),
)
cls.msginit_found = (ret == 0)
except subprocess.CalledProcessError:
......@@ -727,6 +729,7 @@ class PoFormat(FileFormat):
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=get_clean_env(),
)
......
......@@ -28,6 +28,7 @@ from django.core.cache import cache
from django.utils import timezone
from django.core.urlresolvers import reverse
import os
import subprocess
import git
import traceback
import ConfigParser
......@@ -49,6 +50,7 @@ from weblate.trans.mixins import URLMixin, PercentMixin
from weblate.trans.boolean_sum import BooleanSum
from weblate.accounts.models import notify_new_string
from weblate.trans.models.changes import Change
from weblate.trans.util import get_clean_env
class TranslationManager(models.Manager):
......@@ -849,15 +851,19 @@ class Translation(models.Model, URLMixin, PercentMixin):
# Pre commit hook
if self.subproject.pre_commit_script != '':
ret = os.system('%s "%s"' % (
self.subproject.pre_commit_script,
self.get_filename()
))
if ret != 0:
try:
subprocess.check_call(
[
self.subproject.pre_commit_script,
self.get_filename()
],
env=get_clean_env(),
)
except (OSError, subprocess.CalledProcessError) as err:
weblate.logger.error(
'Failed to run pre commit script (%d): %s',
ret,
self.subproject.pre_commit_script
'Failed to run pre commit script %s: %s',
self.subproject.pre_commit_script,
err
)
# Create list of files to commit
......
......@@ -77,11 +77,37 @@ class VCSGitTest(RepoTestCase):
repo = GitRepository.clone(self.repo_path, self._tempdir)
self.assertFalse(repo.needs_commit())
def test_revision_info(self):
repo = GitRepository.clone(self.repo_path, self._tempdir)
info = repo.get_revision_info(repo.last_revision)
def check_valid_info(self, info):
self.assertTrue('summary' in info)
self.assertTrue('author' in info)
self.assertTrue('authordate' in info)
self.assertTrue('commit' in info)
self.assertTrue('commitdate' in info)
def test_revision_info(self):
repo = GitRepository.clone(self.repo_path, self._tempdir)
# Latest commit
info = repo.get_revision_info(repo.last_revision)
self.check_valid_info(info)
# GPG signed commit
info = repo.get_revision_info(
'd6179e46c8255f1d5029f06c49468caf57b13b61'
)
self.check_valid_info(info)
self.assertEquals(
info['author'],
'Michal Čihař <michal@cihar.com>'
)
# Normal commit
info = repo.get_revision_info(
'2ae1998450a693f0a7962d69a1eec4cb2213d595'
)
self.check_valid_info(info)
def test_needs_merge(self):
repo = GitRepository.clone(self.repo_path, self._tempdir)
self.assertFalse(repo.needs_merge('master'))
self.assertFalse(repo.needs_push('master'))
......@@ -24,6 +24,7 @@ from django.core.cache import cache
from importlib import import_module
import time
import random
import os
PLURAL_SEPARATOR = '\x1e\x1e'
......@@ -144,3 +145,13 @@ def get_configuration_errors():
Returns all configuration errors.
"""
return cache.get('configuration-errors', [])
def get_clean_env():
"""
Returns cleaned up environment for subprocess execution.
"""
return {
'HOME': os.environ['HOME'],
'PATH': os.environ['PATH'],
}
......@@ -22,6 +22,7 @@ Minimal distributed version control system abstraction for Weblate needs.
"""
import subprocess
from dateutil import parser
from weblate.trans.util import get_clean_env
class RepositoryException(Exception):
......@@ -38,7 +39,6 @@ class Repository(object):
- repository configuration (SubProject.configure_repo)
- branch configuration (SubProject.configure_branch)
- needs merge/push (SubProject.git_needs_merge/push)
- get object hash (Translation.get_git_blob_hash)
- commit (Translation.__git_commit)
- configuration (Translation.__configure_committer)
......@@ -64,6 +64,7 @@ class Repository(object):
process = subprocess.Popen(
args,
cwd=cwd,
env=get_clean_env(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
......@@ -143,6 +144,20 @@ class Repository(object):
"""
raise NotImplementedError()
def needs_merge(self, branch):
"""
Checks whether repository needs merge with upstream
(is missing some revisions).
"""
raise NotImplementedError()
def needs_push(self, branch):
"""
Checks whether repository needs push to upstream
(has additional revisions).
"""
raise NotImplementedError()
def get_revision_info(self, revision):
"""
Returns dictionary with detailed revision information.
......@@ -221,3 +236,25 @@ class GitRepository(Repository):
result['summary'] = message[0]
return result
def _log_revisions(self, refspec):
"""
Returns revisin log for given refspec.
"""
return self._execute(
['log', '--oneline', refspec, '--']
)
def needs_merge(self, branch):
"""
Checks whether repository needs merge with upstream
(is missing some revisions).
"""
return self._log_revisions('..origin/{0}'.format(branch)) != ''
def needs_push(self, branch):
"""
Checks whether repository needs push to upstream
(has additional revisions).
"""
return self._log_revisions('origin/{0}..'.format(branch)) != ''
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment