diff options
| author | Paolo Melchiorre <paolo@melchiorre.org> | 2020-05-15 09:40:42 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-05-15 11:30:28 +0200 |
| commit | 0e3b0da2e3ecee05e8b5eee763f444c94280dbcb (patch) | |
| tree | bdc8b0c5523a6ae0bf4631be1eca4068ed2e17c4 | |
| parent | 2e48cf6bd9499f888a6cebf9f18c92717f1df55c (diff) | |
Fixed #31552 -- Added support for LZMA and XZ fixtures to loaddata.
| -rw-r--r-- | django/core/management/commands/loaddata.py | 9 | ||||
| -rw-r--r-- | docs/ref/django-admin.txt | 13 | ||||
| -rw-r--r-- | docs/releases/3.2.txt | 3 | ||||
| -rw-r--r-- | tests/fixtures/fixtures/fixture5.json.lzma | bin | 0 -> 157 bytes | |||
| -rw-r--r-- | tests/fixtures/fixtures/fixture5.json.xz | bin | 0 -> 200 bytes | |||
| -rw-r--r-- | tests/fixtures/tests.py | 20 |
6 files changed, 40 insertions, 5 deletions
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 29f7630ff7..eda3d068af 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -26,6 +26,12 @@ try: except ImportError: has_bz2 = False +try: + import lzma + has_lzma = True +except ImportError: + has_lzma = False + READ_STDIN = '-' @@ -97,6 +103,9 @@ class Command(BaseCommand): } if has_bz2: self.compression_formats['bz2'] = (bz2.BZ2File, 'r') + if has_lzma: + self.compression_formats['lzma'] = (lzma.LZMAFile, 'r') + self.compression_formats['xz'] = (lzma.LZMAFile, 'r') # Django's test suite repeatedly tries to load initial_data fixtures # from apps that don't have any fixtures. Because disabling constraint diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 329cb72215..4cd477b7a8 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -599,13 +599,14 @@ The :djadmin:`dumpdata` command can be used to generate input for ``loaddata``. Compressed fixtures ~~~~~~~~~~~~~~~~~~~ -Fixtures may be compressed in ``zip``, ``gz``, or ``bz2`` format. For example:: +Fixtures may be compressed in ``zip``, ``gz``, ``bz2``, ``lzma``, or ``xz`` +format. For example:: django-admin loaddata mydata.json -would look for any of ``mydata.json``, ``mydata.json.zip``, -``mydata.json.gz``, or ``mydata.json.bz2``. The first file contained within a -zip-compressed archive is used. +would look for any of ``mydata.json``, ``mydata.json.zip``, ``mydata.json.gz``, +``mydata.json.bz2``, ``mydata.json.lzma``, or ``mydata.json.xz``. The first +file contained within a compressed archive is used. Note that if two fixtures with the same name but different fixture type are discovered (for example, if ``mydata.json`` and @@ -619,6 +620,10 @@ installation will be aborted, and any data installed in the call to constraints, so if you use MyISAM, you won't get validation of fixture data, or a rollback if multiple transaction files are found. +.. versionchanged:: 3.2 + + Support for XZ archives (``.xz``) and LZMA archives (``.lzma``) was added. + Database-specific fixtures ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt index 18b1df2836..4ba20c4c09 100644 --- a/docs/releases/3.2.txt +++ b/docs/releases/3.2.txt @@ -154,7 +154,8 @@ Logging Management Commands ~~~~~~~~~~~~~~~~~~~ -* ... +* :djadmin:`loaddata` now supports fixtures stored in XZ archives (``.xz``) and + LZMA archives (``.lzma``). Migrations ~~~~~~~~~~ diff --git a/tests/fixtures/fixtures/fixture5.json.lzma b/tests/fixtures/fixtures/fixture5.json.lzma Binary files differnew file mode 100644 index 0000000000..a41fdaa82f --- /dev/null +++ b/tests/fixtures/fixtures/fixture5.json.lzma diff --git a/tests/fixtures/fixtures/fixture5.json.xz b/tests/fixtures/fixtures/fixture5.json.xz Binary files differnew file mode 100644 index 0000000000..af2e82d5c1 --- /dev/null +++ b/tests/fixtures/fixtures/fixture5.json.xz diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index d46bf65c97..ac96c48734 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -27,6 +27,12 @@ try: except ImportError: HAS_BZ2 = False +try: + import lzma # NOQA + HAS_LZMA = True +except ImportError: + HAS_LZMA = False + class TestCaseFixtureLoadingTests(TestCase): fixtures = ['fixture1.json', 'fixture2.json'] @@ -558,6 +564,20 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): '<Article: WoW subscribers now outnumber readers>', ]) + @unittest.skipUnless(HAS_LZMA, 'No lzma library detected.') + def test_compressed_loading_lzma(self): + management.call_command('loaddata', 'fixture5.json.lzma', verbosity=0) + self.assertQuerysetEqual(Article.objects.all(), [ + '<Article: WoW subscribers now outnumber readers>', + ]) + + @unittest.skipUnless(HAS_LZMA, 'No lzma library detected.') + def test_compressed_loading_xz(self): + management.call_command('loaddata', 'fixture5.json.xz', verbosity=0) + self.assertQuerysetEqual(Article.objects.all(), [ + '<Article: WoW subscribers now outnumber readers>', + ]) + def test_ambiguous_compressed_fixture(self): # The name "fixture5" is ambiguous, so loading raises an error. msg = "Multiple fixtures named 'fixture5'" |
