def find_path(text, line, begidx, endidx, \
dir_only=False, files_only=False, exe_only=False,\
py_only=False, uploads=False, all_dir=False):
cur_dir = os.getcwd()
before_arg = line.rfind(" ", 0, begidx)
if before_arg == -1:
return # arg not found
fixed = line[before_arg+1:begidx] # fixed portion of the arg
arg = line[before_arg+1:endidx]
if uploads:
os.chdir(uploads_path)
pattern = arg + '*'
completions = []
for path in glob.glob(pattern):
if dir_only:
if os.path.isdir(path):
path = append_slash_if_dir(path)
completions.append(path.replace(fixed, "", 1))
elif files_only:
if not os.path.isdir(path):
completions.append(path.replace(fixed, "", 1))
elif exe_only:
if not os.path.isdir(path):
if path.endswith('.exe') or path.endswith('.py'):
completions.append(path.replace(fixed, "", 1))
elif py_only:
if not os.path.isdir(path):
if path.endswith('.py'):
completions.append(path.replace(fixed, "", 1))
elif all_dir:
if os.path.isdir(path):
path = append_slash_if_dir(path)
completions.append(path.replace(fixed, "", 1))
os.chdir(cur_dir)
return completions
评论列表
文章目录