diff --git a/README.md b/README.md index 4506e9a..ffe3ab2 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,6 @@ List of available configuration options: | `SQLALCHEMY_DATABASE_URI` | Database connection string. e.g: `postgresql://user:password@localhost/photowall` | | `DEBUG` | Enable/disable debug mode | | `API_KEYS` | A list of api keys that are used to authenticate to the API. If this list is empty authentication will be disabled. | -| `ESALES_URL` | URL to the eSales server. If its a cloud cluster it has the format `username:password` | -| `ESALES_IMPORT_DIR` | XML-files that should be imported to eSales are temporarily stored in this directory. e.g: `/tmp/esales` | `BERNARD_QUEUE_URL` | URL to Bernard queue (used for running Photowall background tasks) ## Getting started @@ -44,10 +42,6 @@ Starting the application: `$ python manage.py runserver` -Running the eSales import - -`$ python manage.py run_esales_import` - ## Testing To run unit tests: diff --git a/api/core.py b/api/core.py index 88e6b94..474f8de 100644 --- a/api/core.py +++ b/api/core.py @@ -1,5 +1,5 @@ from flask import Flask, jsonify, Response, request -from api.extensions import db, esales, bernard +from api.extensions import db, bernard from api.validators import ValidationError @@ -8,7 +8,6 @@ def create_app(config_name="config"): app.config.from_object(config_name) db.init_app(app) - esales.init_app(app) bernard.init_app(app) # register errors handlers diff --git a/api/extensions.py b/api/extensions.py index 28006f3..8590b8f 100644 --- a/api/extensions.py +++ b/api/extensions.py @@ -1,8 +1,6 @@ from flask_sqlalchemy import SQLAlchemy -from esales.flask_esales import Esales from api.lib.bernard import Bernard db = SQLAlchemy() -esales = Esales() bernard = Bernard() diff --git a/api/lib/bernard.py b/api/lib/bernard.py index c52f0cf..fdfe7a6 100644 --- a/api/lib/bernard.py +++ b/api/lib/bernard.py @@ -5,7 +5,7 @@ import json class Bernard(object): def __init__(self, app=None): - self.sqs = boto3.client("sqs", region_name='eu-west-1') + self.sqs = boto3.client("sqs", region_name="eu-west-1") if app: self.init_app(app) diff --git a/api/resources/designers.py b/api/resources/designers.py index 78d7c60..55c9788 100644 --- a/api/resources/designers.py +++ b/api/resources/designers.py @@ -1,5 +1,5 @@ from flask import Blueprint, request, jsonify -from api import db, tasks +from api import db from api.models import Designer from api.helpers import pagination_to_dict, check_api_key from api.validators import validate_jsonschema @@ -58,5 +58,5 @@ def update(id): setattr(designer, k, v) db.session.add(designer) db.session.commit() - tasks.esales.update_designer(designer) + return jsonify(designer.to_json()) diff --git a/api/tasks/__init__.py b/api/tasks/__init__.py deleted file mode 100644 index 0d97ab5..0000000 --- a/api/tasks/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import esales diff --git a/api/tasks/esales.py b/api/tasks/esales.py deleted file mode 100644 index c259591..0000000 --- a/api/tasks/esales.py +++ /dev/null @@ -1,29 +0,0 @@ -# coding=utf-8 -from flask import current_app -from api.models.locale import Locale -from esales.models import Category, CategoryTree -from esales.utils import ImportFile - - -def update_designer(designer): - category = Category( - "root/designers/{}".format(designer.path), - display_name=designer.name, - visible_search=designer.visible_search, - visible_list=designer.visible_list, - visible_productpage=designer.visible_productpage, - visible_designerpage=designer.visible_designerpage, - exclude_from_overview=designer.exclude_from_overview, - send_to_bottom=designer.send_to_bottom, - no_follow=designer.no_follow, - hidden=1, - path="/designers/{}".format(designer.path), - ) - importfile = ImportFile() - for locale in Locale.query.all(): - tree = CategoryTree("categories_{}".format(locale.value)) - tree.add_category(category) - importfile.add_operation("update", tree) - - directory = current_app.config.get("ESALES_IMPORT_DIR") - importfile.write(directory) diff --git a/config.sample.py b/config.sample.py index ddcd4ed..912d02d 100644 --- a/config.sample.py +++ b/config.sample.py @@ -2,6 +2,4 @@ SQLALCHEMY_DATABASE_URI = 'postgresql://user:password@host/db_name' SQLALCHEMY_TRACK_MODIFICATIONS = True DEBUG = True API_KEYS = ['secretkey'] -ESALES_URL = 'username:password' -ESALES_IMPORT_DIR = '/tmp/esales' BERNARD_QUEUE_URL = 'https://sqs.eu-west-1.amazonaws.com//' diff --git a/esales/__init__.py b/esales/__init__.py deleted file mode 100644 index 758589f..0000000 --- a/esales/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .cluster import Cluster diff --git a/esales/cluster.py b/esales/cluster.py deleted file mode 100644 index cc586a5..0000000 --- a/esales/cluster.py +++ /dev/null @@ -1,52 +0,0 @@ -# coding=utf-8 -import glob -import os -import sys -import subprocess -import logging - -logger = logging.getLogger("esales") - - -class CommandException(Exception): - pass - - -class Cluster(object): - - def __init__(self, url=None): - self.url = url - - def run_command(self, command): - """ execute a command against the esales cluster """ - try: - # find the location of the jar file (provided by apptus) that is - # used to execute the commands - jar = os.path.abspath(os.path.dirname( - __file__) + "/command/command.jar") - subprocess.check_output( - "java -jar {0} {1}".format(jar, command).split(), stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - message = "Could not execute command {0}. Error: {1}".format( - command, e.output) - logger.error(message) - raise CommandException(message) - except OSError: - sys.exit("Java not found on this system") - - def import_products_and_categories(self, pattern): - """ imports products and categories into the eSales cluster """ - i = 0 - for f in sorted(glob.iglob(pattern)): - if os.path.isfile(f): - logger.info("Importing {}".format(f)) - try: - self.run_command("import -p {0} {1}".format(self.url, f)) - i += 1 - except CommandException as e: - logger.error("Failed to import {}".format(f)) - finally: - os.remove(f) - - logger.info("Imported {} file(s)".format(i)) - return i diff --git a/esales/command/command.jar b/esales/command/command.jar deleted file mode 100755 index eea6f6d..0000000 Binary files a/esales/command/command.jar and /dev/null differ diff --git a/esales/command/system/esales_common-3.25.0.jar b/esales/command/system/esales_common-3.25.0.jar deleted file mode 100755 index cf86e80..0000000 Binary files a/esales/command/system/esales_common-3.25.0.jar and /dev/null differ diff --git a/esales/command/system/esales_connector_api-3.25.0.jar b/esales/command/system/esales_connector_api-3.25.0.jar deleted file mode 100755 index 63680ee..0000000 Binary files a/esales/command/system/esales_connector_api-3.25.0.jar and /dev/null differ diff --git a/esales/flask_esales.py b/esales/flask_esales.py deleted file mode 100644 index 2ea37c1..0000000 --- a/esales/flask_esales.py +++ /dev/null @@ -1,15 +0,0 @@ -from .cluster import Cluster - - -class Esales(object): - - def __init__(self, app=None): - self.cluster = Cluster() - - if app: - self.init_app(app) - - def init_app(self, app): - if not 'ESALES_URL' in app.config: - raise Exception('ESALES_URL missing in config') - self.cluster.url = app.config.get('ESALES_URL') diff --git a/esales/models.py b/esales/models.py deleted file mode 100644 index 0a502cd..0000000 --- a/esales/models.py +++ /dev/null @@ -1,45 +0,0 @@ -# coding=utf-8 -from xml.etree.cElementTree import Element, SubElement - - -class Category(object): - """ represents an eSales category """ - - def __init__(self, key, display_name=None, **kwargs): - self.key = key - self.display_name = display_name - self.attributes = {} - for k, v in kwargs.items(): - self.attributes[k] = v - - @property - def etree(self): - root = Element("category", key=self.key) - if self.display_name: - SubElement(root, "display_name").text = self.display_name - if self.attributes: - attributes = SubElement(root, "attributes") - for k, v in self.attributes.items(): - SubElement(attributes, k).text = str(v) - - return root - - -class CategoryTree(object): - """represents an eSales CategoryTree""" - - def __init__(self, product_attribute): - self.categories = [] - self.product_attribute = product_attribute - - def add_category(self, category): - self.categories.append(category) - - @property - def etree(self): - root = Element("category_tree", - product_attribute=self.product_attribute) - for category in self.categories: - root.append(category.etree) - - return root diff --git a/esales/utils.py b/esales/utils.py deleted file mode 100644 index 0481df3..0000000 --- a/esales/utils.py +++ /dev/null @@ -1,35 +0,0 @@ -# coding=utf-8 -import os -import uuid -import time -from xml.etree.cElementTree import ElementTree, Element, SubElement, dump - - -class ImportFile(object): - - def __init__(self): - self.operations = [] - - def add_operation(self, operation, model): - assert operation in ["create", "update", "delete"] - self.operations.append((operation, model)) - - @property - def etree(self): - root = Element("operations") - for name, model in self.operations: - operation = SubElement(root, name) - operation.append(model.etree) - return root - - def dump_xml(self): - return dump(self.etree) - - def write(self, directory, filename=None): - if not os.path.exists(directory): - os.makedirs(directory) - if not filename: - filename = "{}.xml".format(time.time()) - xml = ElementTree(self.etree) - xml.write("{}/{}".format(directory, filename), - encoding="UTF-8", xml_declaration=True) diff --git a/manage.py b/manage.py index 12940a0..f0293a4 100644 --- a/manage.py +++ b/manage.py @@ -1,5 +1,5 @@ from flask.ext.script import Manager, prompt_bool -from api import create_app, db, esales +from api import create_app, db from api.models import Designer app = create_app() @@ -27,11 +27,5 @@ def seed_db(): db.session.commit() -@manager.command -def run_esales_import(): - print("Importing products and categories into eSales") - pattern = "{}/*.xml".format(app.config.get("ESALES_IMPORT_DIR")) - esales.cluster.import_products_and_categories(pattern) - if __name__ == '__main__': manager.run() diff --git a/tests/config.py b/tests/config.py index d4bc713..951fc73 100644 --- a/tests/config.py +++ b/tests/config.py @@ -2,7 +2,6 @@ SERVER_NAME = "localhost" SQLALCHEMY_DATABASE_URI = "sqlite://" SQLALCHEMY_TRACK_MODIFICATIONS = True PRESERVE_CONTEXT_ON_EXCEPTION = False -ESALES_URL = "" TESTING = True DEBUG = True SQLALCHEMY_ECHO = False diff --git a/tests/resources/test_designers.py b/tests/resources/test_designers.py index 3026ecc..8031fa1 100644 --- a/tests/resources/test_designers.py +++ b/tests/resources/test_designers.py @@ -56,14 +56,3 @@ class TestEndpoints(flask_testing.TestCase): "/designers/", data=json.dumps(data), content_type="application/json" ) self.assert400(response) - - @patch("api.tasks.esales.update_designer") - def test_update_designer(self, esales_update_designer): - designer = self._add_designer("designer1") - data = {"name": "test"} - response = self.client.put( - "/designers/1", data=json.dumps(data), content_type="application/json" - ) - self.assertTrue(esales_update_designer.called) - self.assertEqual("test", response.json["name"]) - self.assertEqual("test", Designer.query.get(1).name)