Class s.i.c.CSVImporter(object):

Part of stoqlib.importers.csvimporter View In Hierarchy

Known subclasses: stoqlib.importers.branchimporter.BranchImporter, stoqlib.importers.clientimporter.ClientImporter, stoqlib.importers.creditproviderimporter.CreditProviderImporter, stoqlib.importers.employeeimporter.EmployeeImporter, stoqlib.importers.invoiceimporter.InvoiceImporter, stoqlib.importers.productimporter.ProductImporter, stoqlib.importers.purchaseimporter.PurchaseImporter, stoqlib.importers.saleimporter.SaleImporter, stoqlib.importers.serviceimporter.ServiceImporter, stoqlib.importers.supplierimporter.SupplierImporter, stoqlib.importers.transferimporter.TransferImporter, stoqlib.importers.transporterimporter.TransporterImporter

Class to assist the process of importing csv files.
Class Variablesfieldsfield names, a list of strings
optional_fieldsoptional field names, a list of strings
dialectoptional, csv dialect, defaults to excel
Method __init__ Create a new CSVImporter object.
Method feed_file Feeds csv data from filename to the importer
Method feed Feeds csv data from an iterable
Method parse_date Undocumented
Method parse_multi Undocumented
Method set_lines_per_commit Sets the number of lines which should be parsed between commits.
Method set_dry Tells the CSVImporter to run in dry mode, eg without committing
Class Method get_by_type Gets an importers class, instantiates it returns it
Method process_one Processes one line in a csv file, you can access the columns
Method read This can be overridden by as subclass which wishes to specialize
Method before_start This is called before all the lines are parsed but
Method when_done This is called after all the lines are parsed but
def __init__(self, lines=500, dry=False):
Create a new CSVImporter object.
Parameterslinessee set_lines_per_commit
drysee set_dry
def feed_file(self, filename, skip=0):
Feeds csv data from filename to the importer
Parametersfilenamefilename
skipoptional, number of rows to initially skip
def feed(self, iterable, filename='<stdin>', skip=0):
Feeds csv data from an iterable
Parametersiterablean iterable
filenameoptinal, name of input file
skipoptional, number of rows to initially skip
def parse_date(self, data):
Undocumented
def parse_multi(self, domain_class, field, trans):
Undocumented
def set_lines_per_commit(self, lines):
Sets the number of lines which should be parsed between commits. Defaults to 500. -1 means that the whole file should be parsed before committing
Parameterslinesnumber of lines or
def set_dry(self, dry):
Tells the CSVImporter to run in dry mode, eg without committing anything.
Parametersdrydry mode
@classmethod
def get_by_type(cls, importer_type):
Gets an importers class, instantiates it returns it
Parametersimporter_typean importer (type: string )
(type: CSVImporter subclass )
Returnsan importer instance
def process_one(self, row, fields, trans):
Processes one line in a csv file, you can access the columns using attributes on the data object.
Parametersrowobject representing a row in the input
fieldsa list of fields set in data
transa database transaction
def read(self, iterable):
This can be overridden by as subclass which wishes to specialize the CSV reader.
Parametersiterablea sequence of lines which are going to be read
Returnsa sequence of parsed items
def before_start(self, trans):
This is called before all the lines are parsed but after creating a transaction.
def when_done(self, trans):
This is called after all the lines are parsed but before committing.
API Documentation for Stoqlib, generated by pydoctor at 2009-07-14 16:00:32.