Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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.")
Ejemplo n.º 3
0
 def match(file, variables):
     c = common.replace_variables(s.replace("%file%", pipes.quote(file)), variables)
     try: return subprocess.Popen(c, shell = True).wait() == 0
     except: pass
     return False