Beispiel #1
0
    def _get_sorteddict(self, object, dictwithhash=False, hash_method=None, hash_files=True):
        if isinstance(object, dict):
            out = {}
            for key, val in sorted(object.items()):
                if isdefined(val):
                    out[key] = self._get_sorteddict(val, dictwithhash, hash_method=hash_method, hash_files=hash_files)
        elif isinstance(object, (list, tuple)):
            out = []
            for val in object:
                if isdefined(val):
                    out.append(self._get_sorteddict(val, dictwithhash, hash_method=hash_method, hash_files=hash_files))
            if isinstance(object, tuple):
                out = tuple(out)
        else:
            if isdefined(object):
                if hash_files and isinstance(object, str) and os.path.isfile(object):
                    if hash_method == None:
                        hash_method = config.get("execution", "hash_method")

                    if hash_method.lower() == "timestamp":
                        hash = hash_timestamp(object)
                    elif hash_method.lower() == "content":
                        hash = hash_infile(object)
                    else:
                        raise Exception("Unknown hash method: %s" % hash_method)
                    if dictwithhash:
                        out = (object, hash)
                    else:
                        out = hash
                elif isinstance(object, float):
                    out = "%.10f" % object
                else:
                    out = object
        return out
Beispiel #2
0
 def _get_sorteddict(self, object, dictwithhash=False):
     if isinstance(object, dict):
         out = {}
         for key, val in sorted(object.items()):
             if isdefined(val):
                 out[key] = self._get_sorteddict(val, dictwithhash)
     elif isinstance(object, (list,tuple)):
         out = []
         for val in object:
             if isdefined(val):
                 out.append(self._get_sorteddict(val, dictwithhash))
         if isinstance(object, tuple):
             out = tuple(out)
     else:
         if isdefined(object):
             if isinstance(object, str) and os.path.isfile(object):
                 if config.get('execution', 'hash_method').lower() == 'timestamp':
                     hash = hash_timestamp(object)
                 elif config.get('execution', 'hash_method').lower() == 'content':
                     hash = hash_infile(object)
                 else:
                     raise Exception("Unknown hash method: %s" % config.get('execution', 'hash_method'))
                 if dictwithhash:
                     out = (object, hash)
                 else:
                     out = hash
             elif isinstance(object, float):
                 out = '%.10f'%object
             else:
                 out = object
     return out
Beispiel #3
0
 def _hash_infile(self, adict, key):
     """ Inject file hashes into adict[key]"""
     stuff = adict[key]
     if not is_container(stuff):
         stuff = [stuff]
     file_list = []
     for afile in stuff:
         if is_container(afile):
             hashlist = self._hash_infile({"infiles": afile}, "infiles")
             hash = [val[1] for val in hashlist]
         else:
             if config.get("execution", "hash_method").lower() == "timestamp":
                 hash = hash_timestamp(afile)
             elif config.get("execution", "hash_method").lower() == "content":
                 hash = hash_infile(afile)
             else:
                 raise Exception("Unknown hash method: %s" % config.get("execution", "hash_method"))
         file_list.append((afile, hash))
     return file_list