def match_file(self, file, matching_dir = False, depth = 0): ftable = self.get_weighted_table(file) if len(ftable) == 0: if not matching_dir: self.exec_unmatched(file) else: return False elif self.strict(): if len(ftable) == 1: match = ftable[0] self.exec_matched(file, match, depth = depth) else: common.warning("Conflict: Disregarding matches for %s. " "Strictness is set and there are %d matches" % (file, len(ftable))) else: match = ftable[0] self.exec_matched(file, match, depth = depth) if self.symlink(): bms = pybookmark.get_bookmark(match[0], self.bookmarks) if len(bms) != 1 and os.path.isdir(match[0]): dir = match[0] else: dir = bms[0][1] for m in ftable[1:]: self.exec_latter(os.path.join(dir, file), m, depth = depth)
def parse_line(self, line): line = str.strip(line) if line == "" or line[0] == "#": return i = line.find("set ") if i == 0: if not self.rules_started: return self.parse_variable_assignment(line[4:]) else: common.error("Error: variable assignments after rules.") i = line.find(" matches ") if i != -1: bm = line[:i] if self.is_valid_bookmark(bm): self.parse_rule(bm, line[i + 9:]) self.rules_started = True elif os.path.isdir(bm): common.debug("%s is a directory." % bm) self.parse_rule(os.path.realpath(bm), line[i + 9:]) self.rules_started = True else: common.warning("Unknown tag '%s'. Ignoring rule: %s" % (bm, line)) else: common.warning("Invalid syntax: %s" % line)
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.")