def exec_unmatched(self, file): e = str.strip(self.variables["exec_unmatched"]) if e != "": e = common.replace_variables(e.replace("%file%", os.path.realpath(file).replace("'", "\'")), self.variables) common.info("Executing: %s" % e) subprocess.Popen(e, shell = True) else: common.debug("Nothing to execute for %s. exec_unmatched is empty" % file)
def get_weighted_table(self, file): """Returns sorted [(bookmark, weight)] list. Best match first.""" common.debug("Weighing %s" % file) res = {} for r in self.rules: w = res.get(r.bookmark, 0.0) dw = r.weigh(file, self.variables) res[r.bookmark] = w + dw if dw > 0.0: common.info("Matched %s on %s using %s rule (%s)" % (file, r.bookmark, r.match_token, r.text)) return filter(lambda a: a[1] >= float(self.variables["threshold"]), sorted(res.iteritems(), key=lambda a: a[1], reverse=True))
def _exec_help(self, key, file, match, depth = 0): bms = pybookmark.get_bookmark(match[0], self.bookmarks) if len(bms) != 1 and os.path.isdir(match[0]): bms = [(match[0], match[0])] if len(bms) == 1: x = bms[0] e = self.variables[key] if e != "": file = os.path.realpath(file) dest = self.get_dest_retained_structure(file, os.path.realpath(x[1]), depth, makedir = False) e = e.replace("%file%", pipes.quote(file)) e = e.replace("%bookmark%", pipes.quote(x[0])) e = e.replace("%match%", pipes.quote(dest)) e = common.replace_variables(e, self.variables) common.info("Executing: %s" % e) if self.interactive: t = common.theme no = common.NOCOLOR print print ( "=" * 80) print print ("%s%s%s %s===>%s %s%s%s" % (t[2], file, no, t[1], no, t[3], dest, no)) print ("%sMatched on %s%s" % (t[1], x[0], no)) print ("%sThe following command is about to be executed%s" % (t[1], no)) print print (" ", e) print proceed= raw_input("Proceed? [Y/n/q] ").lower() if proceed == "": proceed = "y" print if proceed[0] == "n": return elif proceed[0] == 'q': os.sys.exit(0) dest = self.get_dest_retained_structure(file, os.path.realpath(x[1]), depth, makedir =True) subprocess.Popen(e, shell = True) else: common.debug("Nothing to execute for %s. %s is empty." % (file, key)) else: common.warning("Bookmark matches too many directories. Can't move file.")