Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support slash in file path in reduce command #129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions wagtail_wordpress_import/management/commands/reduce_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def register_all_namespaces(filename):
for ns in namespaces:
ET.register_namespace(ns, namespaces[ns])

def generate_stats_file(file_path, type_stats):
stats_filename = f"stats-{file_path.split('/')[-1]}.json"
f = open(stats_filename, "w")
f.write(json.dumps(type_stats, indent=2))
return stats_filename

class Command(BaseCommand):

Expand Down Expand Up @@ -106,11 +111,9 @@ def handle(self, *args, **options):
self.stdout.write(f"\n[{status_list}]")

# stats to file
f = open(f"stats-{file_path}.json", "w")
f.write(json.dumps(type_stats, indent=2))

stats_filename = generate_stats_file(file_path, type_stats)
self.stdout.write(
self.style.SUCCESS(f"\nStats file is here: stats-{file_path}.json")
self.style.SUCCESS(f"\nStats file is here: {stats_filename}")
)

self.stdout.write(
Expand Down
9 changes: 8 additions & 1 deletion wagtail_wordpress_import/test/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.core.management import CommandError, call_command
from django.test import TestCase, override_settings
from wagtail.core.models import Page
from wagtail_wordpress_import.management.commands.reduce_xml import Command as ReduceCmd
from wagtail_wordpress_import.management.commands.reduce_xml import Command as ReduceCmd, generate_stats_file
from wagtail_wordpress_import.xml_boilerplate import (
build_xml_stream,
generate_temporary_file,
Expand Down Expand Up @@ -153,3 +153,10 @@ def test_get_xml_file(self):
build_xml_stream(xml_tags_fragment="").read()
)
self.assertEqual(built_file, cmd.get_xml_file(built_file))

def test_xml_reduce_generate_stats(self):
fabienheureux marked this conversation as resolved.
Show resolved Hide resolved
stats_filename = generate_stats_file("/folder/test.xml", {})
self.assertEqual(stats_filename, "stats-test.xml.json")

stats_filename = generate_stats_file("test.xml", {})
self.assertEqual(stats_filename, "stats-test.xml.json")