Example #1
0
class DirCompletion(cmd.Cmd):

    ulfs = UnixLikeFileSystem()
    dc = DirectoryCompletion(ulfs)

    def do_exit(self, args):
        sys.exit(0)

    def _listdir(self, args):
        if os.path.isdir(args):
            return os.listdir(args)
        else:
            return [args]

    def _ls(self, args):
        try:
            return self._listdir(args)
        except:
            return []

    def do_ls(self, args):
        print()
        print(" ".join(self._ls(args)))

    def complete_ls(self, text, line, begidx, endidx):
        #print
        result = []

        cur_input_line = line.split()
        cur_path = "."
        if (len(cur_input_line) == 2):
            cur_path = cur_input_line[1]
            #print "cur_path:", cur_path

        result = self.dc.parse_text_line(text, cur_path, os.getcwd())

        return result
Example #2
0
    def get_dirname(self, path):
        if self.check_absolute(path):
            # if it is the absolute path,
            # return dirname
            if path.endswith(self.fs.seq):
                path = os.path.normpath(path) + self.fs.seq
            else:
                path = os.path.normpath(os.path.dirname(path)) + self.fs.seq
        path = path.replace("//", "/")
        return path

    def get_filename(self, path, dirname):
        if self.check_absolute(path):
            if path.endswith(self.fs.seq):
                path = ""
            else:
                path = os.path.normpath(os.path.basename(path))
        path = path.replace("//", "/")
        return path


if __name__ == "__main__":
    from DIRAC.DataManagementSystem.Client.CmdDirCompletion.AbstractFileSystem import UnixLikeFileSystem

    ulfs = UnixLikeFileSystem()
    dc = DirectoryCompletion(ulfs)

    print(dc.parse_text_line("ls", "/bin/", "/home/ihep"))
    print(dc.parse_text_line(".vim", "", "/home/ihep"))
    print(dc.parse_text_line("", "", "/home/ihep"))