|
|
@@ -3,16 +3,32 @@ |
|
|
|
# For license information, please see license.txt |
|
|
|
|
|
|
|
from __future__ import unicode_literals |
|
|
|
import frappe |
|
|
|
from frappe.model.document import Document |
|
|
|
from frappe import _ |
|
|
|
from .connectors.postgres import PostGresConnection |
|
|
|
from .connectors.frappe_connection import FrappeConnection |
|
|
|
|
|
|
|
class DataMigrationConnector(Document): |
|
|
|
def validate(self): |
|
|
|
if not (self.python_module or self.connector_type): |
|
|
|
frappe.throw(_('Enter python module or select connector type')) |
|
|
|
|
|
|
|
if self.python_module: |
|
|
|
try: |
|
|
|
frappe.get_module(self.python_module) |
|
|
|
except: |
|
|
|
frappe.throw(frappe._('Invalid module path')) |
|
|
|
|
|
|
|
def get_connection(self): |
|
|
|
if self.connector_type == 'Frappe': |
|
|
|
self.connection = FrappeConnection(self) |
|
|
|
elif self.connector_type == 'PostGres': |
|
|
|
self.connection = PostGresConnection(self.as_dict()) |
|
|
|
if self.python_module: |
|
|
|
module = frappe.get_module(self.python_module) |
|
|
|
return module.get_connection(self) |
|
|
|
else: |
|
|
|
if self.connector_type == 'Frappe': |
|
|
|
self.connection = FrappeConnection(self) |
|
|
|
elif self.connector_type == 'PostGres': |
|
|
|
self.connection = PostGresConnection(self.as_dict()) |
|
|
|
|
|
|
|
return self.connection |
|
|
|
|
|
|
|