Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move feed utils to separate file

Krzysztof Wolski772586bcd507
diff --git a/saleor/integrations/management/commands/update_integrations.py b/saleor/integrations/management/commands/update_integrations.py
index 2f42d38e65..414c9f8e3e 100644
--- a/saleor/integrations/management/commands/update_integrations.py
+++ b/saleor/integrations/management/commands/update_integrations.py
@@ -1,14 +1,9 @@
from __future__ import unicode_literals
-try:
- from StringIO import StringIO
-except ImportError:
- from io import StringIO
-
-from django.core.files.storage import default_storage
from django.core.management import CommandError, BaseCommand
from saleor.integrations.feeds import SaleorFeed
+from saleor.integrations import utils
class Command(BaseCommand):
@@ -18,26 +13,10 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('feed_name', nargs='+', type=str)
- @staticmethod
- def get_feed_content(feed, url_name=''):
- feed = feed.get_feed()
- buffer = StringIO()
- feed.write(buffer, 'utf-8')
- return buffer.getvalue()
-
- @staticmethod
- def save_feed(file_path, content):
- with default_storage.open(file_path, 'w') as output_file:
- output_file.write(content)
-
- def update_feed(self, feed):
- content = self.get_feed_content(feed, feed.url)
- self.save_feed(feed.file_path, content)
-
def handle(self, *args, **options):
feed_names = options['feed_name'] or self.feed_classes.keys()
for feed_name in feed_names:
feed = self.feed_classes.get(feed_name)
if feed is None:
raise CommandError('Feed "%s" does not exist' % feed_name)
- self.update_feed(feed())
+ utils.update_feed(feed())
diff --git a/saleor/integrations/utils.py b/saleor/integrations/utils.py
new file mode 100644
index 0000000000..ad8474ad41
--- /dev/null
+++ b/saleor/integrations/utils.py
@@ -0,0 +1,23 @@
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+
+from django.core.files.storage import default_storage
+
+
+def get_feed_content(feed, url_name=''):
+ feed = feed.get_feed()
+ buffer = StringIO()
+ feed.write(buffer, 'utf-8')
+ return buffer.getvalue()
+
+
+def save_feed(file_path, content):
+ with default_storage.open(file_path, 'w') as output_file:
+ output_file.write(content)
+
+
+def update_feed(feed):
+ content = get_feed_content(feed, feed.url)
+ save_feed(feed.file_path, content)