[damned-lies] Make BuildTranslatedDocsView.build_docs less dependent on class state
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Make BuildTranslatedDocsView.build_docs less dependent on class state
- Date: Sat, 6 Oct 2018 10:16:45 +0000 (UTC)
commit 78295f22625b027204b497c74e635b70d34f00ea
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Oct 6 12:15:49 2018 +0200
Make BuildTranslatedDocsView.build_docs less dependent on class state
vertimus/views.py | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/vertimus/views.py b/vertimus/views.py
index 2dbdc6a4..fff6c8ac 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -294,26 +294,26 @@ class QualityCheckView(PoFileActionBase):
class BuildTranslatedDocsView(PoFileActionBase):
def post(self, request, *args, **kwargs):
- self.pofile = self.get_po_file()
- if self.pofile is None:
+ pofile = self.get_po_file()
+ if pofile is None:
raise Http404('No target po file for this action')
- self.html_dir = Path(settings.SCRATCHDIR, 'HTML', str(self.kwargs['action_pk']))
- if self.html_dir.exists():
+ html_dir = Path(settings.SCRATCHDIR, 'HTML', str(self.kwargs['action_pk']))
+ if html_dir.exists():
# If the build already ran, redirect to the static results
return HttpResponseRedirect(self.action.build_url)
state = self.action.state_db
with ModuleLock(state.branch.module):
state.branch.checkout()
- error_message = self.build_docs(state)
+ error_message = self.build_docs(state, pofile, html_dir)
if error_message:
messages.error(request, error_message)
return HttpResponseRedirect(state.get_absolute_url())
return HttpResponseRedirect(self.action.build_url)
- def build_docs(self, state):
+ def build_docs(self, state, po_file, html_dir):
"""
Try building translated docs, return an error message or an empty string
on success.
@@ -327,7 +327,7 @@ class BuildTranslatedDocsView(PoFileActionBase):
with tempfile.NamedTemporaryFile(suffix='.gmo') as gmo, \
tempfile.TemporaryDirectory() as build_dir:
result = subprocess.run([
- 'msgfmt', self.pofile, '-o', os.path.join(gmo.name)
+ 'msgfmt', po_file, '-o', os.path.join(gmo.name)
], stderr=subprocess.PIPE)
if result.returncode != 0:
return build_error % {
@@ -346,26 +346,26 @@ class BuildTranslatedDocsView(PoFileActionBase):
}
# Now build the html version
- if not self.html_dir.exists():
- self.html_dir.mkdir(parents=True)
+ if not html_dir.exists():
+ html_dir.mkdir(parents=True)
if doc_format.format == 'mallard':
# With mallard, specifying the directory is enough.
build_ref = [str(build_dir)]
else:
build_ref = [os.path.join(build_dir, s.name) for s in sources]
cmd = [
- 'yelp-build', 'html', '-o', str(self.html_dir),
+ 'yelp-build', 'html', '-o', str(html_dir),
'-p', str(doc_format.vcs_path / 'C'),
*build_ref
]
result = subprocess.run(cmd, cwd=str(build_dir), stderr=subprocess.PIPE)
if result.returncode != 0:
- shutil.rmtree(str(self.html_dir))
+ shutil.rmtree(str(html_dir))
return build_error % {
'program': 'yelp-build', 'err': result.stderr.decode()
}
- if not (self.html_dir / 'index.html').exists():
+ if not (html_dir / 'index.html').exists():
# Create an index.html symlink to the base html doc if needed
try:
doc = parse(build_ref[0])
@@ -374,5 +374,5 @@ class BuildTranslatedDocsView(PoFileActionBase):
pass
else:
html_name = '%s.html' % base_name
- (self.html_dir / 'index.html').symlink_to(self.html_dir / html_name)
+ (html_dir / 'index.html').symlink_to(html_dir / html_name)
return ''
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]