Exemplo n.º 1
0
def getRange(s):
    if myFile.hasAccess(s):
        f = myFile.openFile(s, "r")
        lst = []
        for l in f:
            lst.extend([int(x) for x in l.replace("\n", "").split()])
        f.close()
        return lst
    else:
        (start, _, end) = s.partition(":")
        return range(int(start), int(end) + 1)
Exemplo n.º 2
0
 def putValue(typ, authorisedVals, v):
     # instantiate the value depending on the type
     if typ == bool:
         # Type booleen
         res = {"false": False, "true": True}[v.lower()]
     elif typ == file:
         # Type 'fichier': test of presence
         v = os.path.expanduser(v)
         if not myFile.hasAccess(v):
             error_usage("File '%s' innaccessible" % v)
         else:
             res = v
     elif isinstance(typ, enum.Enum):
         try:
             res = getattr(typ, v)
         except AttributeError:
             error_usage("'%s' is not among %s" % (v, typ._keys))
     else:
         # otherwise the builder is used
         res = typ(v)
         if isinstance(authorisedVals, list) and (res not in authorisedVals):
             # non authorised parameter value
             error_usage("'%s' is not among %s" % (res, myFile.myTSV.printLine(authorisedVals, "/")))
     return res