'Execute each import job, in order'

def execute_import_task(self, task):

    start = datetime.now()
    if (task[0] == 1):
        s3db = current.s3db
        response = current.response
        errorString = 'prepopulate    error:    file    %s    missing'
        view = response.view
        prefix = task[1]
        name = task[2]
        tablename = ('%s_%s' % (prefix, name))
        if (tablename in self.alternateTables):
            details = self.alternateTables[tablename]
            if ('tablename' in details):
                tablename = details['tablename']
            s3db.table(tablename)
            if ('loader' in details):
                loader = details['loader']
                if (loader is not None):
                    loader()
            if ('prefix' in details):
                prefix = details['prefix']
            if ('name' in details):
                name = details['name']
        try:
            resource = s3db.resource(tablename)
        except AttributeError:
            self.errorList.append(('WARNING:    Unable    to    find    table    %s    import    job    skipped' % tablename))
            return
        filename = task[3]
        if (filename[:7] == 'http://'):
            req = urllib2.Request(url=filename)
            try:
                f = urllib2.urlopen(req)
            except urllib2.HTTPError as e:
                self.errorList.append(('Could    not    access    %s:    %s' % (filename, e.read())))
                return
            except:
                self.errorList.append((errorString % filename))
                return
            else:
                csv = f
        else:
            try:
                csv = open(filename, 'r')
            except IOError:
                self.errorList.append((errorString % filename))
                return
        try:
            S = open(task[4], 'r')
        except IOError:
            self.errorList.append((errorString % task[4]))
            return
        else:
            S.close()
        if (tablename not in self.customised):
            customise = current.deployment_settings.customise_resource(tablename)
            if customise:
                request = S3Request(prefix, name, current.request)
                customise(request, tablename)
                self.customised.append(tablename)
        extra_data = None
        if task[5]:
            try:
                extradata = self.unescape(task[5], {"'": '"'})
                extradata = json.loads(extradata)
                extra_data = extradata
            except:
                self.errorList.append(('WARNING:5th    parameter    invalid,    parameter    %s    ignored' % task[5]))
        auth = current.auth
        auth.rollback = True
        try:
            resource.import_xml(csv, format='csv', stylesheet=task[4], extra_data=extra_data)
        except SyntaxError as e:
            self.errorList.append(('WARNING:    import    error    -    %s    (file:    %s,    stylesheet:    %s)' % (e, filename, task[4])))
            auth.rollback = False
            return
        if (not resource.error):
            current.db.commit()
        else:
            error = resource.error
            self.errorList.append(('%s    -    %s:    %s' % (task[3], resource.tablename, error)))
            errors = current.xml.collect_errors(resource)
            if errors:
                self.errorList.extend(errors)
            current.db.rollback()
        auth.rollback = False
        response.view = view
        end = datetime.now()
        duration = (end - start)
        csvName = task[3][(task[3].rfind('/') + 1):]
        try:
            duration = '{:.2f}'.format((duration.total_seconds() / 60))
            msg = ('%s    import    job    completed    in    %s    mins' % (csvName, duration))
        except AttributeError:
            msg = ('%s    import    job    completed    in    %s' % (csvName, duration))
        self.resultList.append(msg)
        current.log.debug(msg)
