Пример #1
0
    def __init__(self,
                 filename=None,
                 minLength=-1,
                 commentString=None,
                 minNF=-1,
                 skipHeaderLines=0,
                 separator=None):

        _AwkLike.__init__(self,
                          minLength=minLength,
                          commentString=commentString,
                          minNF=minNF,
                          skipHeaderLines=skipHeaderLines,
                          separator=separator)
        self.f = None

        if filename == None:
            self.f = sys.stdin
            self.FILENAME = 'stdin'  # pylint: disable=C0103
        else:
            self.FILENAME = filename
            if not os.path.exists(filename):
                ntu.nTerror('AwkLike: Failed to find file "%s"' % filename)
                self.f = None
            else:
                self.f = open(filename, 'r')
Пример #2
0
 def close(self):
     """internal routine"""
     if self.FILENAME is None:
         ntu.nTerror('AwkLike.close: Cannot close file')
         return
     if self.f is None:
         ntu.nTerror('AwkLike.close: Cannot close "%s"', self.FILENAME)
         return
     if self.f is not sys.stdin:
         self.f.close()
     self.f = None
Пример #3
0
 def close(self):
     """internal routine"""
     if self.FILENAME is None:
         ntu.nTerror('AwkLike.close: Cannot close file')
         return
     if self.f is None:
         ntu.nTerror('AwkLike.close: Cannot close "%s"', self.FILENAME)
         return
     if self.f is not sys.stdin:
         self.f.close()
     self.f = None
Пример #4
0
 def float(self, field):
     """Return field converted to float or NaN on error """
     try:
         return float(self[field])
     except ValueError:
         ntu.nTerror(
             'AwkLike: expected float for "%s" (file: %s, line %d: "%s")',
             self[field], self.FILENAME, self.NR, self[0])
     except IndexError:
         ntu.nTerror(
             'AwkLike: invalid field number "%d" (file: %s, line %d: "%s")',
             field, self.FILENAME, self.NR, self[0])
     return fpconst.NaN
Пример #5
0
    def __init__(self, filename=None, minLength=-1, commentString=None, minNF=-1,
                 skipHeaderLines=0, separator=None):

        _AwkLike.__init__(self, minLength=minLength, commentString=commentString, minNF=minNF,
                          skipHeaderLines=skipHeaderLines, separator=separator)
        self.f = None

        if filename is None:
            self.f = sys.stdin
            self.FILENAME = 'stdin'  # pylint: disable=C0103
        else:
            self.FILENAME = filename
            if not os.path.exists(filename):
                ntu.nTerror('AwkLike: Failed to find file "%s"' % filename)
                self.f = None
            else:
                self.f = open(filename, 'r')
Пример #6
0
 def float(self, field):
     """Return field converted to float or NaN on error """
     try:
         return float(self[field])
     except ValueError:
         ntu.nTerror('AwkLike: expected float for "%s" (file: %s, line %d: "%s")',
                     self[field],
                     self.FILENAME,
                     self.NR,
                     self[0]
                     )
     except IndexError:
         ntu.nTerror('AwkLike: invalid field number "%d" (file: %s, line %d: "%s")',
                     field,
                     self.FILENAME,
                     self.NR,
                     self[0]
                     )
     return fpconst.NaN
Пример #7
0
    pluginCodeModulePackage = None
    try:
        # JFD changed from default to zero which means to only try absolute imports.
        pluginCodeModulePackage = __import__(pluginCodeModule, globals(), locals(), [pluginName])
        isInstalled = True
        ntu.nTdebug("importPlugin: Installed plugin: [%s]" % pluginName)
    except ImportWarning:
        ntu.nTdebug(
            "importPlugin: Skipping import of an optional plugin: [%s] (please recode to use SkipTest)" % pluginName
        )
        isInstalled = False
    except SkipTest:
        ntu.nTdebug("importPlugin: Skipping import of an optional plugin: [%s]" % pluginName)
    except:
        ntu.nTtracebackError()
        ntu.nTerror("importPlugin: Failed to import pluginCodeModule: [%s]" % pluginName)
        return None
    # end try

    pluginModule = None
    if isInstalled:
        if not hasattr(pluginCodeModulePackage, pluginName):
            ntu.nTerror(
                "importPlugin: Expected an attribute pluginName: "
                + pluginName
                + " for package: "
                + repr(pluginCodeModulePackage)
            )
            return None
        pluginModule = getattr(pluginCodeModulePackage, pluginName)
        # end if