Make converters dynamically loadable in autoimport

Adds 1 restriction to the HHC sub classes, the classname must be the
same as the filename - ToFpdb.py

FulltiltToFpdb.py must contain a hhc class named Fulltilt
EverleafToFpdb.py must contain a hhc class named Everleaf
This commit is contained in:
Worros
2009-03-14 05:00:12 +09:00
parent 875f218379
commit 6ebab06981
4 changed files with 19 additions and 48 deletions
+13 -14
View File
@@ -33,8 +33,6 @@ import fpdb_simple
import fpdb_db
import fpdb_parse_logic
import Configuration
import EverleafToFpdb
import FulltiltToFpdb
# database interface modules
try:
@@ -238,21 +236,22 @@ class Importer:
except:
out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file))
# someone can just create their own python module for it
if filter in ("EverleafToFpdb","Everleaf"):
conv = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path)
elif filter == "FulltiltToFpdb":
conv = FulltiltToFpdb.FullTilt(in_path = file, out_path = out_path)
filter_name = filter.replace("ToFpdb", "")
mod = __import__(filter)
obj = getattr(mod, filter_name, None)
if callable(obj):
conv = obj(in_path = file, out_path = out_path)
if(conv.getStatus()):
(stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site)
else:
# conversion didn't work
# TODO: appropriate response?
return (0, 0, 0, 1, 0)
else:
print "Unknown filter ", filter
print "Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter)
return
if(conv.getStatus()):
(stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site)
else:
# conversion didn't work
# TODO: appropriate response?
return (0, 0, 0, 1, 0)
#This will barf if conv.getStatus != True
return (stored, duplicates, partial, errors, ttime)