Helper classes and functions for importing ASCII data.
Removes any ASCII import configuration file(s) of the given type and with the given description.
This function is meant to clean up after having performed an automated ASCII import, which presumably would have created an import configuration file. However, it will also remove any configuration files which have been created manually, if the parameters happen to match. Please be careful!
Returns the next available file path to use when dynamically generating an ASCII config selection file. See cam32.ascii.config_ascii_import() for more info.
This rather complex beast will dynamically generate a config file for use with CAM32’s ASCII data importer.
| Parameters: |
|
|---|
The meaning and contents of the config dictionary parameter is dependent on which import_type is passed.
Each key in the dictionary should be one of the predefined fields which may be assigned to within the import process itself. (See the source code for the full list of fields allowed for each config type.)
Each value in the dictionary should be a tuple containing the offset and length of the field’s data as it exists in the data file to be imported.
The only (required) exception to the above statements regarding the config parameter is for when import_type is cam32.ASCII_IMPORT_MULTIVENDOR and is as follows: A key of 'VendorNumber' must exist, and its value should be the vendor number for which the multi-vendor data is to be imported. This is because CAM32’s ASCII data importer can only import multi-vendor data for one vendor at a time.
Any extra keys in the config parameter will be ignored.
A tuple containing the path to the created config file and a suggested path to the data file (which you should then create and populate) are returned.
Note
It perhaps goes without saying that the data file which you then generate must behave and conform exactly to the config parameter which you have provided!
An example since this is so chaotic a methodology:
config = {
'ITEM NUMBER' : (1, 6),
'VENDOR NUMBER' : (8, 4),
}
config_path, data_path = cam32.config.config_ascii_import(cam32.ASCII_IMPORT_INVENTORY, "Import Test", config)
session = cam32.Session()
item = session.InventoryItem(32342)
f = open(data_path, 'w')
print >> f, "%6u %4u" % (item.item_number, item.vendor_number)
f.close()
Notice that the item number field is defined to begin at position 1 of the line and extend for 6 characters. The vendor number begins at position 8 and extends for 4 characters. Therefore the format string which is printed to the data file follows the same convention. (Of course this example generates ASCII data as it already existed in CAM32, so the import would not do anything essentially.)
CAM32’s ASCII importer could then be launched immediately, and after it closes you’re free to (and probably should) delete the generated config file:
cam32.app.import_data_files()
import os
os.remove(config_path)
os.remove(data_path) # unless you're not done with your ASCII file...