def check_critical_file(mypath, logger): # mypath = os.path.join(os.getcwd(),"critical") onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ] pp.pprint(onlyfiles) result = {} total = len(onlyfiles) index = 0 print("Total Files: %d" % total) for file in onlyfiles: try: print("{0:.2%}".format(index / total)) index += 1 logger.info("Checking file %s" % file) d = DalGraph(file=os.path.join(mypath,file), logger=logger) critical = d.critical_aprox() logger.info("File %s is %r" %(file, critical)) result[file] = critical except: result[file] = "Invalid File" pp.pprint(result) logger.info("Results:") logger.info("-----------------") for file, critical in result.items(): logger.info("File %s is %r" %(file, critical)) logger.info("-----------------") send_email(CRITICAL_MESSAGE, TO_ADDRESS)
def consume(lock, graphs, done, critical): while done.empty(): try: g = graphs.get(block=True, timeout=5) d = DalGraph(graph=g, logger=LOGGER) if d.critical_aprox(): f = File(DIRECTORY, G=g, logger=LOGGER) fp = f.save() if fp is not None: critical.put(fp) except Empty: #print("Empty") pass return
def testCriticalAprox(self): # is_critical graphs g = nx.Graph() g.add_node(0) g = join(g, g) g = join(g, g) d = DalGraph(g) result = d.critical_aprox() self.assertEqual(result, True) g = make_wheel(6) d = DalGraph(g) result = d.critical_aprox() self.assertEqual(result, True) d = DalGraph(make_cycle(5)) result = d.critical_aprox() self.assertEqual(result, True) # test non is_critical d = DalGraph(make_claw()) result = d.critical_aprox() self.assertEqual(result, False) d = DalGraph(make_co_claw()) result = d.critical_aprox() self.assertEqual(result, False)