[damned-lies] Generalized pathlib.Path usage



commit 8f01d0c37a44a505373babacd20d4c449ea55b8f
Author: Claude Paroz <claude 2xlibre net>
Date:   Wed Mar 17 20:47:35 2021 +0100

    Generalized pathlib.Path usage

 common/views.py                               |  3 +--
 damnedlies/settings.py                        | 25 +++++++++++--------------
 damnedlies/settings_tests.py                  |  6 ++----
 damnedlies/urls.py                            |  4 +---
 stats/management/commands/compile-trans.py    | 19 +++++++++----------
 stats/management/commands/update-trans.py     | 26 ++++++++++++--------------
 stats/migrations/0017_pofile_path_relative.py |  2 +-
 stats/models.py                               | 18 ++++++++++--------
 stats/repos.py                                |  2 +-
 stats/tests/tests.py                          | 13 ++++++++-----
 stats/tests/utils.py                          |  9 +++++----
 stats/utils.py                                | 10 +++++-----
 vertimus/models.py                            |  6 ++----
 vertimus/tests/tests.py                       | 16 ++++++----------
 vertimus/views.py                             |  2 +-
 15 files changed, 75 insertions(+), 86 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index 2c6beff6..fa825e19 100644
--- a/common/views.py
+++ b/common/views.py
@@ -1,4 +1,3 @@
-from pathlib import Path
 from smtplib import SMTPException
 from threading import Thread
 
@@ -134,7 +133,7 @@ def pull_code(request):
 
 
 def pull_code_real():
-    cwd = Path(settings.BASE_DIR) / 'damnedlies'
+    cwd = settings.BASE_DIR / 'damnedlies'
     run_shell_command(['git', 'pull', '--rebase'], cwd=cwd)
     call_command('compile-trans', verbosity=0)
     run_shell_command(['touch', 'wsgi.py'], cwd=cwd)
diff --git a/damnedlies/settings.py b/damnedlies/settings.py
index bf3697bf..d0e56263 100644
--- a/damnedlies/settings.py
+++ b/damnedlies/settings.py
@@ -1,5 +1,7 @@
 # Django settings for djamnedlies project.
 import os
+from pathlib import Path
+
 from django.conf import global_settings
 gettext_noop = lambda s: s
 
@@ -7,7 +9,7 @@ DEBUG = True
 STATIC_SERVE = True
 USE_DEBUG_TOOLBAR = False
 
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+BASE_DIR = Path(__file__).resolve().parent.parent
 
 ADMINS = (
     ('Your Name', 'your_address example org'),
@@ -16,7 +18,7 @@ ADMINS = (
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',
-        'NAME'  : os.path.join(BASE_DIR, 'database.db'),
+        'NAME': BASE_DIR / 'database.db',
     }
 }
 # Please refer to the README file to create an UTF-8 database with MySQL.
@@ -51,28 +53,23 @@ LANGUAGES = global_settings.LANGUAGES + [
     ('ku', gettext_noop('Kurdish')),
 ]
 
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
 USE_I18N = True
 USE_L10N = True
-LOCALE_PATHS = (
-    os.path.join(BASE_DIR, 'locale'),
-)
+LOCALE_PATHS = [BASE_DIR / 'locale']
 
 # Absolute path to the directory that holds media.
-MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
+MEDIA_ROOT = BASE_DIR / 'media'
 
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
+# URL that handles the media served from MEDIA_ROOT.
 MEDIA_URL = '/media/'
 
-STATIC_ROOT = os.path.join(BASE_DIR, 'static')
+STATIC_ROOT = BASE_DIR / 'static'
 
 STATIC_URL = '/static/'
 
 # Local directory path for VCS checkout
-SCRATCHDIR = ""
-POTDIR = os.path.join(SCRATCHDIR, "POT")
+SCRATCHDIR = Path()
+POTDIR = SCRATCHDIR / "POT"
 
 # The regex is used to determine if the module is in the standard VCS of the project
 VCS_HOME_REGEX = r"gitlab\.gnome\.org"
@@ -92,7 +89,7 @@ SECRET_KEY = ''
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [os.path.join(BASE_DIR, 'templates')],
+        'DIRS': [BASE_DIR / 'templates'],
         'OPTIONS': {
             'context_processors': [
                 # Default list:
diff --git a/damnedlies/settings_tests.py b/damnedlies/settings_tests.py
index 04f1d7ea..702e3d94 100644
--- a/damnedlies/settings_tests.py
+++ b/damnedlies/settings_tests.py
@@ -1,9 +1,7 @@
-import os
-
 from .settings import *
 
 SECRET_KEY = 'shRc(?sk+sW3Wqn-lBvs=r52a@#hgC9g'
 
-SCRATCHDIR = os.path.join(BASE_DIR, 'scratch')
-POTDIR = os.path.join(SCRATCHDIR, "POT")
+SCRATCHDIR = BASE_DIR / 'scratch'
+POTDIR = SCRATCHDIR / 'POT'
 GETTEXT_ITS_DATA = {}
diff --git a/damnedlies/urls.py b/damnedlies/urls.py
index 42fa8b37..8a394245 100644
--- a/damnedlies/urls.py
+++ b/damnedlies/urls.py
@@ -1,5 +1,3 @@
-import os
-
 from django.conf import settings
 from django.contrib import admin
 from django.contrib.auth import views as auth_views
@@ -127,5 +125,5 @@ if settings.STATIC_SERVE:
              kwargs={'document_root': settings.POTDIR}),
         path('HTML/<path:path>',
              serve,
-             kwargs={'document_root': os.path.join(settings.SCRATCHDIR, 'HTML')}),
+             kwargs={'document_root': settings.SCRATCHDIR / 'HTML'}),
     ]
diff --git a/stats/management/commands/compile-trans.py b/stats/management/commands/compile-trans.py
index f737c006..28f639ee 100644
--- a/stats/management/commands/compile-trans.py
+++ b/stats/management/commands/compile-trans.py
@@ -1,4 +1,3 @@
-import os
 import shutil
 
 from django.conf import settings
@@ -15,17 +14,17 @@ class Command(BaseCommand):
 
     def handle(self, **options):
         # Copy all po/ll.po files in locale/ll/LC_MESSAGES/django.po
-        podir = os.path.join(settings.BASE_DIR, 'po')
-        for pofile in os.listdir(podir):
-            if pofile[-3:] != ".po":
+        podir = settings.BASE_DIR / 'po'
+        for pofile in podir.iterdir():
+            if pofile.suffix != ".po":
                 continue
-            lang_code = pofile[:-3]
-            localedir = os.path.join(
-                settings.BASE_DIR, 'locale', self.lang_mapping.get(lang_code, lang_code), 'LC_MESSAGES'
+            lang_code = pofile.stem
+            localedir = (
+                settings.BASE_DIR / 'locale' / self.lang_mapping.get(lang_code, lang_code) / 'LC_MESSAGES'
             )
-            if not os.path.isdir(localedir):
-                os.makedirs(localedir)
-            shutil.copy(os.path.join(podir, pofile), os.path.join(localedir, 'django.po'))
+            if not localedir.is_dir():
+                localedir.mkdir(parents=True, exist_ok=True)
+            shutil.copy(pofile, localedir / 'django.po')
 
         # Run compilemessages -l ll
         call_command('compilemessages')
diff --git a/stats/management/commands/update-trans.py b/stats/management/commands/update-trans.py
index 43f3a248..5d092b08 100644
--- a/stats/management/commands/update-trans.py
+++ b/stats/management/commands/update-trans.py
@@ -1,4 +1,3 @@
-import os
 import re
 import shutil
 import itertools
@@ -22,24 +21,23 @@ class Command(BaseCommand):
         #        help="create a pot file"),
 
     def handle(self, **options):
-        os.chdir(settings.BASE_DIR)
         lang_code = options['lang_code']
 
         # Copy po/ll.po in locale/ll/LC_MESSAGES/django.po
-        podir = os.path.abspath('po')
-        localedir = os.path.join(os.path.abspath('locale'), lang_code, 'LC_MESSAGES')
+        podir = settings.BASE_DIR / 'po'
+        localedir = settings.BASE_DIR / 'locale' / lang_code / 'LC_MESSAGES'
         if lang_code != 'en':
-            pofile = os.path.join(podir, '%s.po' % lang_code)
-            if os.path.exists(pofile):
-                if not os.path.isdir(localedir):
-                    os.makedirs(localedir)
-                shutil.copy(pofile, os.path.join(localedir, 'django.po'))
+            pofile = podir / f'{lang_code}.po'
+            if pofile.exists():
+                if not localedir.is_dir():
+                    localedir.mkdir(parents=True, exist_ok=True)
+                shutil.copy(pofile, localedir / 'django.po')
         else:
-            pofile = os.path.join(podir, 'damned-lies.pot')
+            pofile = podir / 'damned-lies.pot'
 
         # Extract DB translatable strings into database-content.py
-        dbfile = os.path.join(os.path.abspath('.'), 'database-content.py')
-        with open(dbfile, 'w') as fh:
+        dbfile = settings.BASE_DIR / 'database-content.py'
+        with dbfile.open('w') as fh:
             for value in itertools.chain(
                 Team.objects.values_list('description', flat=True),
                 Language.objects.exclude(name__exact=F('locale')).values_list('name', flat=True),
@@ -56,9 +54,9 @@ class Command(BaseCommand):
         call_command('makemessages', locale=[lang_code])
 
         # Delete database-content.py
-        os.unlink(dbfile)
+        dbfile.unlink()
 
         # Copy locale/ll/LC_MESSAGES/django.po to po/ll.po
-        shutil.copy(os.path.join(localedir, 'django.po'), pofile)
+        shutil.copy(localedir / 'django.po', pofile)
 
         return "po file for language '%s' updated." % lang_code
diff --git a/stats/migrations/0017_pofile_path_relative.py b/stats/migrations/0017_pofile_path_relative.py
index 48a468eb..1a10aad3 100644
--- a/stats/migrations/0017_pofile_path_relative.py
+++ b/stats/migrations/0017_pofile_path_relative.py
@@ -5,7 +5,7 @@ from django.db import migrations
 
 def strip_path_prefix(apps, schema_editor):
     Statistics = apps.get_model("stats", "Statistics")
-    scratch_dir = os.path.basename(settings.SCRATCHDIR)
+    scratch_dir = os.path.basename(str(settings.SCRATCHDIR))
 
     def strip_path(stat):
         old_path = stat.full_po.path
diff --git a/stats/models.py b/stats/models.py
index 9c88e459..0a119d8c 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -356,7 +356,7 @@ class Branch(models.Model):
             branch_dir = self.module.name
         else:
             branch_dir = self.module.name + "." + self.name_escaped
-        return Path(settings.SCRATCHDIR, self.module.vcs_type, branch_dir)
+        return settings.SCRATCHDIR / self.module.vcs_type / branch_dir
 
     def get_domains(self):
         """
@@ -381,7 +381,7 @@ class Branch(models.Model):
     def output_dir(self, dom_type):
         """ Directory where generated pot and po files are written on local system """
         subdir = {'ui': '', 'doc': 'docs'}[dom_type]
-        dirname = Path(settings.POTDIR, self.module.name + "." + self.name_escaped, subdir)
+        dirname = settings.POTDIR / f'{self.module.name}.{self.name_escaped}' / subdir
         dirname.mkdir(parents=True, exist_ok=True)
         return dirname
 
@@ -1235,7 +1235,7 @@ class PoFile(models.Model):
 
     @property
     def full_path(self):
-        return os.path.join(self.prefix, self.path.lstrip('/'))
+        return self.prefix / self.path.lstrip('/')
 
     def filename(self):
         return os.path.basename(self.path)
@@ -1498,9 +1498,11 @@ class Statistics(models.Model):
         subdir = ""
         if self.domain.dtype == "doc":
             subdir = "docs"
-        path = os.path.join(settings.POTDIR, "%s.%s" % (self.module_name, self.branch.name_escaped),
-            subdir, self.filename(potfile, reduced))
-        if reduced and not os.path.exists(path):
+        path = (
+            settings.POTDIR / f"{self.module_name}.{self.branch.name_escaped}" /
+            subdir / self.filename(potfile, reduced)
+        )
+        if reduced and not path.exists():
             path = self.po_path(potfile=potfile, reduced=False)
         return path
 
@@ -1573,9 +1575,9 @@ class Statistics(models.Model):
             if (self.full_po.fuzzy + self.full_po.untranslated) > 0 and not self.branch.is_archive_only() 
and self.domain.red_filter != '-':
                 # Generate partial_po and store partial stats
                 if self.full_po.path.endswith('.pot'):
-                    part_po_path = Path(self.full_po.full_path[:-3] + "reduced.pot")
+                    part_po_path = self.full_po.full_path.with_suffix(".reduced.pot")
                 else:
-                    part_po_path = Path(self.full_po.full_path[:-3] + ".reduced.po")
+                    part_po_path = self.full_po.full_path.with_suffix(".reduced.po")
                 utils.po_grep(self.full_po.full_path, str(part_po_path), self.domain.red_filter)
                 part_stats = utils.po_file_stats(part_po_path)
                 if (part_stats['translated'] + part_stats['fuzzy'] + part_stats['untranslated'] ==
diff --git a/stats/repos.py b/stats/repos.py
index 3ff79d49..e8679e82 100644
--- a/stats/repos.py
+++ b/stats/repos.py
@@ -153,7 +153,7 @@ class CVSRepo(RepoBase):
             'cvs', '-d%s' % self.branch.module.vcs_root, '-z4', 'co',
             '-d%s' % self.branch.module.name + "." + self.branch.name,
             '-r%s' % self.branch.name, self.module.name
-        ], cwd=os.path.join(settings.SCRATCHDIR, self.branch.module.vcs_type))
+        ], cwd=settings.SCRATCHDIR / self.branch.module.vcs_type)
 
     def update(self):
         run_shell_command(['cvs', '-z4', 'up', '-Pd'], raise_on_error=True, cwd=self.branch.co_path)
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 09e40125..1c687718 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -481,7 +481,7 @@ class ModuleTestCase(TestCase):
         self.assertEqual(self.mod.homepage, "http://git.gnome.org/browse/gnome-hello";)
 
 
-@override_settings(SCRATCHDIR=str(Path(__file__).parent))
+@override_settings(SCRATCHDIR=Path(__file__).parent)
 class TestModuleBase(TestCase):
     @classmethod
     def setUpTestData(cls):
@@ -496,7 +496,7 @@ class TestModuleBase(TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        html_dir = Path(settings.SCRATCHDIR) / 'HTML'
+        html_dir = settings.SCRATCHDIR / 'HTML'
         if html_dir.exists():
             shutil.rmtree(str(html_dir))
         super().tearDownClass()
@@ -545,7 +545,7 @@ class DomainTests(TestModuleBase):
         self.assertEqual(
             domain.get_xgettext_command(self.branch),
             (['xgettext', '--files-from', 'POTFILES.in', '--directory',
-             os.path.join(settings.SCRATCHDIR, 'git', 'testmodule'),
+             str(settings.SCRATCHDIR / 'git' / 'testmodule'),
              '--from-code', 'utf-8',
              '--add-comments', '--output', 'testmodule.pot'] + list(GLIB_PRESET) +
              ['--keyword=Description',
@@ -763,8 +763,10 @@ class StatisticsTests(TestCase):
         ]
         self.assertEqual(sorted(infos)[0].statistics.branch.module.name, 'gnome-hello')
 
+    @test_scratchdir
     def test_empty_pot(self):
         pot_file = Path(__file__).parent / 'empty.pot'
+        shutil.copyfile(pot_file, settings.SCRATCHDIR / 'POT' / 'zenity.master')
         mod = Module.objects.get(name='zenity')
         dom = Domain.objects.create(
             module=mod, name='po2', dtype='ui', description='UI Translations'
@@ -777,6 +779,7 @@ class StatisticsTests(TestCase):
         self.assertEqual(stat.fuzzy(), 0)
         self.assertEqual(stat.untranslated(), 0)
 
+
 class FigureTests(TestCase):
     fixtures = ['sample_data.json']
     def test_figure_view(self):
@@ -880,7 +883,7 @@ class UtilsTests(TestModuleBase):
 
     @test_scratchdir
     def test_insert_locale_in_linguas(self):
-        linguas_path = Path(settings.SCRATCHDIR) / 'git' / 'gnome-hello' / 'po' / 'LINGUAS'
+        linguas_path = settings.SCRATCHDIR / 'git' / 'gnome-hello' / 'po' / 'LINGUAS'
         utils.insert_locale_in_linguas(linguas_path, 'xx')
         self.assertTrue(linguas_path.read_text().endswith('xx\n'))
 
@@ -895,7 +898,7 @@ class UtilsTests(TestModuleBase):
     @test_scratchdir
     def test_po_grep(self):
         # Take it.po, because desktop.in.h strings are not yet translated
-        it_path = os.path.join(settings.SCRATCHDIR, 'git/gnome-hello/po/it.po')
+        it_path = settings.SCRATCHDIR / 'git' / 'gnome-hello' / 'po' / 'it.po'
         temp_file = tempfile.NamedTemporaryFile(delete=False)
         self.addCleanup(os.remove, temp_file.name)
         utils.po_grep(it_path, temp_file.name, 'locations|desktop.in.h')
diff --git a/stats/tests/utils.py b/stats/tests/utils.py
index 0930f4b9..c4b8a88b 100644
--- a/stats/tests/utils.py
+++ b/stats/tests/utils.py
@@ -3,6 +3,7 @@ import shutil
 import tarfile
 import tempfile
 from functools import wraps
+from pathlib import Path
 from unittest.mock import patch
 
 from django.conf import settings
@@ -48,12 +49,12 @@ def test_scratchdir(test_func):
     def decorator(self):
         old_SCRATCHDIR = settings.SCRATCHDIR
         old_POTDIR = settings.POTDIR
-        settings.SCRATCHDIR = os.path.join(tempfile.mkdtemp(), 'scratch')
-        settings.POTDIR = os.path.join(settings.SCRATCHDIR, "POT")
-        os.makedirs(settings.POTDIR)
+        settings.SCRATCHDIR = Path(tempfile.mkdtemp()) / 'scratch'
+        settings.POTDIR = settings.SCRATCHDIR / "POT"
+        settings.POTDIR.mkdir(parents=True)
         tar_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'gnome-hello.tar.gz')
         with tarfile.open(tar_path) as gnome_hello_tar:
-            gnome_hello_tar.extractall(os.path.join(settings.SCRATCHDIR, 'git'))
+            gnome_hello_tar.extractall(settings.SCRATCHDIR / 'git')
         try:
             test_func(self)
         finally:
diff --git a/stats/utils.py b/stats/utils.py
index 31b715a7..9fd4ebd0 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -28,7 +28,7 @@ CHANGED_WITH_ADDITIONS  = 2
 CHANGED_NO_ADDITIONS    = 3
 
 ITSTOOL_PATH = getattr(settings, 'ITSTOOL_PATH', '')
-ITS_DATA_DIR = os.path.join(settings.SCRATCHDIR, 'data', 'its')
+ITS_DATA_DIR = settings.SCRATCHDIR / 'data' / 'its'
 
 # monkey-patch ttk (https://github.com/translate/translate/issues/2129)
 from translate.storage.base import TranslationStore
@@ -389,7 +389,7 @@ def po_grep(in_file, out_file, filter_):
     grepfilter = pogrep.GrepFilter(filter_str, filter_loc, useregexp=True, invertmatch=True, 
keeptranslations=True)
     with open(out_file, "wb") as out:
         try:
-            pogrep.rungrep(in_file, out, None, grepfilter)
+            pogrep.rungrep(str(in_file), out, None, grepfilter)
         except Exception:
             pass
     # command-line variant:
@@ -653,8 +653,8 @@ def collect_its_data():
     """
     from .models import Module, ModuleLock
 
-    if not os.path.exists(ITS_DATA_DIR):
-        os.makedirs(ITS_DATA_DIR)
+    if not ITS_DATA_DIR.exists():
+        ITS_DATA_DIR.mkdirs()
     data_to_collect = getattr(settings, 'GETTEXT_ITS_DATA', {})
     for module_name, files in data_to_collect.items():
         mod = Module.objects.get(name=module_name)
@@ -663,7 +663,7 @@ def collect_its_data():
             branch.checkout()
             for file_path in files:
                 src = branch.co_path / file_path
-                dest = os.path.join(ITS_DATA_DIR, os.path.basename(file_path))
+                dest = ITS_DATA_DIR / os.path.basename(file_path)
                 shutil.copyfile(str(src), dest)
 
 
diff --git a/vertimus/models.py b/vertimus/models.py
index e00a5d16..529bf301 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -391,9 +391,7 @@ class ActionAbstract(models.Model):
 
     @property
     def build_url(self):
-        path = Path(
-            settings.SCRATCHDIR, 'HTML', str(self.pk), 'index.html'
-        )
+        path = settings.SCRATCHDIR / 'HTML' / str(self.pk) / 'index.html'
         return '/' + str(path.relative_to(settings.SCRATCHDIR)) if path.exists() else None
 
     def get_filename(self):
@@ -837,7 +835,7 @@ def delete_action_files(sender, instance, **kwargs):
                  os.remove(instance.merged_file.full_path)
     if os.access(instance.file.path, os.W_OK):
          os.remove(instance.file.path)
-    html_dir = Path(settings.SCRATCHDIR, 'HTML', str(instance.pk))
+    html_dir = settings.SCRATCHDIR / 'HTML' / str(instance.pk)
     if html_dir.exists():
         shutil.rmtree(str(html_dir))
 
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index b5515b12..e857c4e9 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -28,7 +28,7 @@ from vertimus.models import (
 )
 from vertimus.forms import ActionForm
 
-MEDIA_ROOT = tempfile.mkdtemp()
+MEDIA_ROOT = Path(tempfile.mkdtemp())
 
 
 @override_settings(MEDIA_ROOT=MEDIA_ROOT)
@@ -474,7 +474,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
         self.assertEqual(len(mail.outbox), 1)  # Mail sent to mailing list
         mail.outbox = []
 
-        file_path = Path(settings.MEDIA_ROOT, action_file.name)
+        file_path = settings.MEDIA_ROOT / action_file.name
         self.assertTrue(file_path.exists())
 
         action = Action.new_by_name('TC', person=self.pc)
@@ -498,7 +498,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
 
         # Remove test file
         action_archived = ActionArchived.objects.get(comment="Done.")
-        filename_archived = Path(settings.MEDIA_ROOT, action_archived.file.name)
+        filename_archived = settings.MEDIA_ROOT / action_archived.file.name
         action_archived.delete()
         self.assertFalse(filename_archived.exists(), "%s not deleted" % filename_archived)
 
@@ -782,7 +782,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
 class DocsBuildingTests(TeamsAndRolesMixin, TestModuleBase):
     def setUp(self):
         super().setUp()
-        html_dir = Path(settings.SCRATCHDIR) / 'HTML'
+        html_dir = settings.SCRATCHDIR / 'HTML'
         if html_dir.exists():
             shutil.rmtree(str(html_dir))
 
@@ -806,9 +806,7 @@ class DocsBuildingTests(TeamsAndRolesMixin, TestModuleBase):
             response, '/HTML/%d/index.html' % action.pk, fetch_redirect_response=False
         )
         self.assertEqual(action.build_url, '/HTML/%d/index.html' % action.pk)
-        index_file = Path(
-            settings.SCRATCHDIR, 'HTML', str(action.pk), 'index.html'
-        )
+        index_file = settings.SCRATCHDIR / 'HTML' / str(action.pk) / 'index.html'
         with index_file.open('r') as ifile:
             self.assertIn('<h2><span class="title">À propos</span></h2>', ifile.read())
 
@@ -832,8 +830,6 @@ class DocsBuildingTests(TeamsAndRolesMixin, TestModuleBase):
             response, '/HTML/%d/index.html' % action.pk, fetch_redirect_response=False
         )
         self.assertEqual(action.build_url, '/HTML/%d/index.html' % action.pk)
-        index_file = Path(
-            settings.SCRATCHDIR, 'HTML', str(action.pk), 'index.html'
-        )
+        index_file = settings.SCRATCHDIR / 'HTML' / str(action.pk) / 'index.html'
         with index_file.open('r') as ifile:
             self.assertIn('<h2><span class="title">À propos</span></h2>', ifile.read())
diff --git a/vertimus/views.py b/vertimus/views.py
index 7ff78bf9..d9025c25 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -400,7 +400,7 @@ class BuildTranslatedDocsView(PoFileActionBase):
         if pofile is None:
             raise Http404('No target po file for this action')
 
-        html_dir = Path(settings.SCRATCHDIR, 'HTML', str(self.kwargs['action_pk']))
+        html_dir = 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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]