def print_provision_ranges(dic, limit_print, dest, samdb_path, invocationid): """ print the differents ranges passed as parameter :param dic: A dictionnary as returned by findprovisionrange :param limit_print: minimum number of object in a range in order to print it :param dest: Destination directory :param samdb_path: Path to the sam.ldb file :param invoicationid: Invocation ID for the current provision """ ldif = "" for id in dic: hash_ts = dic[id] sorted_keys = [] sorted_keys.extend(hash_ts.keys()) sorted_keys.sort() kept_record = [] for k in sorted_keys: obj = hash_ts[k] if obj["num"] > limit_print: dt = _glue.nttime2string(_glue.unix2nttime(k*60)) print "%s # of modification: %d \tmin: %d max: %d" % (dt , obj["num"], obj["min"], obj["max"]) if hash_ts[k]["num"] > 600: kept_record.append(k) # Let's try to concatenate consecutive block if they are in the almost same minutestamp for i in range(0, len(kept_record)): if i != 0: key1 = kept_record[i] key2 = kept_record[i-1] if key1 - key2 == 1: # previous record is just 1 minute away from current if int(hash_ts[key1]["min"]) == int(hash_ts[key2]["max"]) + 1: # Copy the highest USN in the previous record # and mark the current as skipped hash_ts[key2]["max"] = hash_ts[key1]["max"] hash_ts[key1]["skipped"] = True for k in kept_record: obj = hash_ts[k] if obj.get("skipped") == None: ldif = "%slastProvisionUSN: %d-%d;%s\n" % (ldif, obj["min"], obj["max"], id) if ldif != "": if dest == None: dest = "/tmp" file = tempfile.mktemp(dir=dest, prefix="usnprov", suffix=".ldif") print print "To track the USNs modified/created by provision and upgrade proivsion," print " the following ranges are proposed to be added to your provision sam.ldb: \n%s" % ldif print "We recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldb" % file print "You can load this file like this: ldbadd -H %s %s\n"%(str(samdb_path),file) ldif = "dn: @PROVISION\nprovisionnerID: %s\n%s" % (invocationid, ldif) open(file,'w').write(ldif)
def print_provision_ranges(dic, limit_print, dest, samdb_path, invocationid): """ print the differents ranges passed as parameter :param dic: A dictionnary as returned by findprovisionrange :param limit_print: minimum number of object in a range in order to print it :param dest: Destination directory :param samdb_path: Path to the sam.ldb file :param invoicationid: Invocation ID for the current provision """ ldif = "" for id in dic: hash_ts = dic[id] sorted_keys = [] sorted_keys.extend(hash_ts.keys()) sorted_keys.sort() kept_record = [] for k in sorted_keys: obj = hash_ts[k] if obj["num"] > limit_print: dt = _glue.nttime2string(_glue.unix2nttime(k * 60)) print "%s # of modification: %d \tmin: %d max: %d" % ( dt, obj["num"], obj["min"], obj["max"]) if hash_ts[k]["num"] > 600: kept_record.append(k) # Let's try to concatenate consecutive block if they are in the almost same minutestamp for i in range(0, len(kept_record)): if i != 0: key1 = kept_record[i] key2 = kept_record[i - 1] if key1 - key2 == 1: # previous record is just 1 minute away from current if int(hash_ts[key1]["min"]) == int( hash_ts[key2]["max"]) + 1: # Copy the highest USN in the previous record # and mark the current as skipped hash_ts[key2]["max"] = hash_ts[key1]["max"] hash_ts[key1]["skipped"] = True for k in kept_record: obj = hash_ts[k] if obj.get("skipped") is None: ldif = "%slastProvisionUSN: %d-%d;%s\n" % (ldif, obj["min"], obj["max"], id) if ldif != "": file = tempfile.mktemp(dir=dest, prefix="usnprov", suffix=".ldif") print print "To track the USNs modified/created by provision and upgrade proivsion," print " the following ranges are proposed to be added to your provision sam.ldb: \n%s" % ldif print "We recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldb" % file print "You can load this file like this: ldbadd -H %s %s\n" % ( str(samdb_path), file) ldif = "dn: @PROVISION\nprovisionnerID: %s\n%s" % (invocationid, ldif) open(file, 'w').write(ldif)
def test_unix2nttime(self): self.assertEqual(_glue.unix2nttime(1), 116444736010000000)