def do_check(self): ### get files now = datetime.now() self._last_check = now ret = {} slist = self.ingest_package.get_store_list(elements = self.source["elements"]) for filnam in slist: basename = os.path.basename(filnam) if len(basename)>0: if "transferred_files" not in ret: ret["transferred_files"] = [] indivpkg = self.ingest_package.__class__(storename = filnam) indivpkg.deliver_from_warehouse(move = "_ingested") ret["transferred_files"].append(filnam) ## RUN COMMANDS # if document is a known type (see warehouse_daemon.py in lookups) xfers = None if "transferred_files" in ret: xfers = ret["transferred_files"] if xfers: if "commands" in self.source: commands = self.source["commands"] for command in commands: patt = command["file_pattern"] for filename in xfers: if re.match(patt, filename): if False: # if command["clean_working_directory"]: # @@WARN: possibly dangerous, Ideally isolate # the daemon with it's own account/permisions rmcontents = os.getcwd() shutil.rmtree(rmcontents) os.mkdir(rmcontent) for command_line in command["command_lines"]: vargs = {"dataset": os.path.basename(filename), "context": ConfigSpace.get_current_default_context() } command_line = command_line.format(**vargs) print tc.colored("-"*(len(command_line)+len("running:")+2), None, "on_green") print tc.colored("running:", None, "on_green"), "%s" % command_line print tc.colored("-"*(len(command_line)+len("running:")+2), None, "on_green") cmdparts = command_line.split() # check parts you want to glob convparts = [] for part in cmdparts: if "*" in part: convparts.extend(glob(part)) else: convparts.append(part) exit_code = subprocess.call(convparts) print " exit_code = %s" % exit_code if command["clean_working_directory"]: # @@WARN: possibly dangerous, Ideally isolate # the daemon with it's own account/permisions rmcontents = os.getcwd() clear_directory(rmcontents) if not ret: return None else: return ret