Add export-rattail
command, plus ProductImage support for Rattail->Rattail
This commit is contained in:
parent
6c697c1bd1
commit
7c481d3481
|
@ -194,6 +194,32 @@ class ImportSubcommand(Subcommand):
|
||||||
log.info("transaction was committed")
|
log.info("transaction was committed")
|
||||||
|
|
||||||
|
|
||||||
|
class ExportRattail(ImportSubcommand):
|
||||||
|
"""
|
||||||
|
Export data to another Rattail database
|
||||||
|
"""
|
||||||
|
name = 'export-rattail'
|
||||||
|
description = __doc__.strip()
|
||||||
|
default_handler_spec = 'rattail.importing.rattail:FromRattailToRattailExport'
|
||||||
|
|
||||||
|
def get_handler_factory(self):
|
||||||
|
spec = self.config.get('rattail.exporting', 'rattail.handler',
|
||||||
|
default=self.default_handler_spec)
|
||||||
|
return load_object(spec)
|
||||||
|
|
||||||
|
def add_parser_args(self, parser):
|
||||||
|
super(ExportRattail, self).add_parser_args(parser)
|
||||||
|
parser.add_argument('--dbkey', metavar='KEY', default='host',
|
||||||
|
help="Config key for database engine to be used as the \"target\" "
|
||||||
|
"Rattail system, i.e. where data will be exported. This key must "
|
||||||
|
"be defined in the [rattail.db] section of your config file.")
|
||||||
|
|
||||||
|
def get_handler_kwargs(self, **kwargs):
|
||||||
|
if 'args' in kwargs:
|
||||||
|
kwargs['dbkey'] = kwargs['args'].dbkey
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class ImportToRattail(ImportSubcommand):
|
class ImportToRattail(ImportSubcommand):
|
||||||
"""
|
"""
|
||||||
Generic base class for commands which import *to* a Rattail system.
|
Generic base class for commands which import *to* a Rattail system.
|
||||||
|
@ -215,7 +241,7 @@ class ImportRattail(ImportToRattail):
|
||||||
name = 'import-rattail'
|
name = 'import-rattail'
|
||||||
description = __doc__.strip()
|
description = __doc__.strip()
|
||||||
handler_key = 'rattail'
|
handler_key = 'rattail'
|
||||||
default_handler_spec = 'rattail.importing.rattail:FromRattailToRattail'
|
default_handler_spec = 'rattail.importing.rattail:FromRattailToRattailImport'
|
||||||
|
|
||||||
def add_parser_args(self, parser):
|
def add_parser_args(self, parser):
|
||||||
super(ImportRattail, self).add_parser_args(parser)
|
super(ImportRattail, self).add_parser_args(parser)
|
||||||
|
|
|
@ -53,19 +53,10 @@ class ToRattailHandler(ToSQLAlchemyHandler):
|
||||||
return Session()
|
return Session()
|
||||||
|
|
||||||
|
|
||||||
class FromRattailToRattail(FromRattailHandler, ToRattailHandler):
|
class FromRattailToRattailBase(object):
|
||||||
"""
|
"""
|
||||||
Handler for Rattail -> Rattail data import.
|
Common base class for Rattail -> Rattail data import/export handlers.
|
||||||
"""
|
"""
|
||||||
local_title = "Rattail (local)"
|
|
||||||
dbkey = 'host'
|
|
||||||
|
|
||||||
@property
|
|
||||||
def host_title(self):
|
|
||||||
return "Rattail ({})".format(self.dbkey)
|
|
||||||
|
|
||||||
def make_host_session(self):
|
|
||||||
return Session(bind=self.config.rattail_engines[self.dbkey])
|
|
||||||
|
|
||||||
def get_importers(self):
|
def get_importers(self):
|
||||||
importers = OrderedDict()
|
importers = OrderedDict()
|
||||||
|
@ -108,15 +99,49 @@ class FromRattailToRattail(FromRattailHandler, ToRattailHandler):
|
||||||
importers['ProductCode'] = ProductCodeImporter
|
importers['ProductCode'] = ProductCodeImporter
|
||||||
importers['ProductCost'] = ProductCostImporter
|
importers['ProductCost'] = ProductCostImporter
|
||||||
importers['ProductPrice'] = ProductPriceImporter
|
importers['ProductPrice'] = ProductPriceImporter
|
||||||
|
importers['ProductImage'] = ProductImageImporter
|
||||||
return importers
|
return importers
|
||||||
|
|
||||||
def get_default_keys(self):
|
def get_default_keys(self):
|
||||||
keys = self.get_importer_keys()
|
keys = self.get_importer_keys()
|
||||||
if 'AdminUser' in keys:
|
if 'AdminUser' in keys:
|
||||||
keys.remove('AdminUser')
|
keys.remove('AdminUser')
|
||||||
|
keys.remove('ProductImage')
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
|
|
||||||
|
class FromRattailToRattailImport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
|
||||||
|
"""
|
||||||
|
Handler for Rattail -> Rattail data import.
|
||||||
|
"""
|
||||||
|
local_title = "Rattail (local)"
|
||||||
|
dbkey = 'host'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def host_title(self):
|
||||||
|
return "Rattail ({})".format(self.dbkey)
|
||||||
|
|
||||||
|
def make_host_session(self):
|
||||||
|
return Session(bind=self.config.rattail_engines[self.dbkey])
|
||||||
|
|
||||||
|
# TODO: deprecate/remove this?
|
||||||
|
FromRattailToRattail = FromRattailToRattailImport
|
||||||
|
|
||||||
|
|
||||||
|
class FromRattailToRattailExport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
|
||||||
|
"""
|
||||||
|
Handler for Rattail -> Rattail data import.
|
||||||
|
"""
|
||||||
|
host_title = "Rattail (default)"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def local_title(self):
|
||||||
|
return "Rattail ({})".format(self.dbkey)
|
||||||
|
|
||||||
|
def make_session(self):
|
||||||
|
return Session(bind=self.config.rattail_engines[self.dbkey])
|
||||||
|
|
||||||
|
|
||||||
class FromRattail(FromSQLAlchemy):
|
class FromRattail(FromSQLAlchemy):
|
||||||
"""
|
"""
|
||||||
Base class for Rattail -> Rattail data importers.
|
Base class for Rattail -> Rattail data importers.
|
||||||
|
@ -272,7 +297,16 @@ class BrandImporter(FromRattail, model.BrandImporter):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ProductImporter(FromRattail, model.ProductImporter):
|
class ProductImporter(FromRattail, model.ProductImporter):
|
||||||
pass
|
|
||||||
|
# TODO...
|
||||||
|
@property
|
||||||
|
def simple_fields(self):
|
||||||
|
fields = super(ProductImporter, self).simple_fields
|
||||||
|
fields.remove('unit_uuid')
|
||||||
|
fields.remove('regular_price_uuid')
|
||||||
|
fields.remove('current_price_uuid')
|
||||||
|
return fields
|
||||||
|
|
||||||
|
|
||||||
class ProductCodeImporter(FromRattail, model.ProductCodeImporter):
|
class ProductCodeImporter(FromRattail, model.ProductCodeImporter):
|
||||||
pass
|
pass
|
||||||
|
@ -282,3 +316,6 @@ class ProductCostImporter(FromRattail, model.ProductCostImporter):
|
||||||
|
|
||||||
class ProductPriceImporter(FromRattail, model.ProductPriceImporter):
|
class ProductPriceImporter(FromRattail, model.ProductPriceImporter):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ProductImageImporter(FromRattail, model.ProductImageImporter):
|
||||||
|
pass
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -218,6 +218,7 @@ datasync = rattail.commands.core:DataSync
|
||||||
date-organize = rattail.commands.core:DateOrganize
|
date-organize = rattail.commands.core:DateOrganize
|
||||||
dbsync = rattail.commands.core:DatabaseSyncCommand
|
dbsync = rattail.commands.core:DatabaseSyncCommand
|
||||||
dump = rattail.commands.core:Dump
|
dump = rattail.commands.core:Dump
|
||||||
|
export-rattail = rattail.commands.importing:ExportRattail
|
||||||
filemon = rattail.commands.core:FileMonitorCommand
|
filemon = rattail.commands.core:FileMonitorCommand
|
||||||
import-csv = rattail.commands.core:ImportCSV
|
import-csv = rattail.commands.core:ImportCSV
|
||||||
import-rattail = rattail.commands.importing:ImportRattail
|
import-rattail = rattail.commands.importing:ImportRattail
|
||||||
|
|
Loading…
Reference in a new issue