def parselogs(logpath): eventlog = [] today = datetime.datetime.now().strftime("%Y%m%d") todays_logpath = logpath + today try: shutil.copy(logpath, todays_logpath) if os.path.isfile(todays_logpath): temp = open(logpath, "w") temp.close() with open(todays_logpath, "r") as inputfile: lines = [line.rstrip('\n') for line in inputfile] for line in lines: if "Created directory" in line: split = str.split(line) eventlog.append(split[-1]) else: pass print('contents of eventlog are', eventlog) common_path = os.path.commonpath(eventlog) print('common path for events is', common_path) index_dicoms(common_path) return eventlog except (IOError, OSError, shutil.SameFileError): pass
def idle_switch(self): while True: time.sleep(3) if self.idle_time and time.time() - self.idle_time > self.timeout: # TODO INDEX PARENT WATCHED PATH!! self.paths_to_index = [ path for path in self.event_tracker.keys() ] print("Preparing to index the following paths:") good_paths = [path for path in self.paths_to_index] for path in good_paths: print(path) print("*************INDEXING********************") try: path_to_index = os.path.commonpath(good_paths) except ValueError as err: print("Error with good paths: {}, {}".format( good_paths, err)) path_to_index = '' self.event_tracker = {} print('index_dicoms({})'.format(path_to_index)) if path_to_index is not [] and path_to_index is not '': index_dicoms(path_to_index) # clearing out now indexed paths self.paths_to_index = [] good_paths = [] self.idle_time = None
def handle(self, *args, **options): # start indexing once on launch if am_i_in_docker(): first_index_history = HasBeenIndexed.objects.all() if not first_index_history: for directory in BASE_DICOM_DIR: index_dicoms(directory) first_index = HasBeenIndexed.objects.create( date_indexed=datetime.datetime.now(), directories_indexed=str(BASE_DICOM_DIR)) first_index.save() else: pass current_time = datetime.datetime.now() next_scan_time = current_time + datetime.timedelta(hours=24) print( "Initiating daily indexer, next index will begin after {}".format( next_scan_time)) while True: time.sleep(900) current_time = datetime.datetime.now() if current_time >= next_scan_time: for directory in BASE_DICOM_DIR: index_dicoms(directory) next_scan_time = datetime.datetime.now() + datetime.timedelta( hours=24) print("Next index scheduled to begin after {}".format( next_scan_time)) pass
def handle(self, *args, **options): if options['directory']: index_dicoms(options['directory']) elif not options['directory'] and settings.BASE_DICOM_DIR: print('settings.BASE_DICOM_DIR', settings.BASE_DICOM_DIR) for directory in settings.BASE_DICOM_DIR: print('directory', directory) index_dicoms(directory) else: print( "No directory passed to index, check BASE_DICOM_DIR in ImageSearcher.settings or supply path with -d \ argument")