나는 파일을 검색하고 사용 권한을 나열하는 python 스크립트 중 하나를 사용하고있었습니다. 나는 여전히 파이썬에서 학습자이며,이 코드를 공부하는 동안 다음과 같은 질문을 발견했다 :파일을 검색 할 Python 스크립트
아래 라인에서 의미는 무엇입니까? "mode = stat.SIMODE (os.lstat (file) [ stat.ST_MODE]) "? "모드"로 반환되는 값은입니까? 권한 정보를 어떻게 제공합니까? 누군가가 이것을 설명 할 수 있다면 고맙겠습니다.
또한이 세그먼트 내의 루프가 중첩 된 방식으로 파일 이름 및 관련 사용 권한을 표시하는 데 필요한 출력을 얻는 방법을 이해해야합니다.
여기서 "레벨"의 의미는 무엇입니까?
위의 질문에 답하고 관련 지침을 제공 할 수 있다면 매우 감사드립니다. 미리 감사드립니다.
전체 코드는 다음과 같습니다
import stat, sys, os, string, commands
try:
#run a 'find' command and assign results to a variable
pattern = raw_input("Enter the file pattern to search for:\n")
commandString = "find " + pattern
commandOutput = commands.getoutput(commandString)
findResults = string.split(commandOutput, "\n")
#output find results, along with permissions
print "Files:"
print commandOutput
print "================================"
for file in findResults:
mode=stat.S_IMODE(os.lstat(file)[stat.ST_MODE])
print "\nPermissions for file ", file, ":"
for level in "USR", "GRP", "OTH":
for perm in "R", "W", "X":
if mode & getattr(stat,"S_I"+perm+level):
print level, " has ", perm, " permission"
else:
print level, " does NOT have ", perm, " permission"
except:
print "There was a problem - check the message above"
@ Ignacio 안녕하세요, 기본적으로, 내가 굵은 글씨로 강조 표시된 줄과 관련된 답변을 찾고 있습니다. stat.S_IMODE에 대한 python 문서를 살펴 보았지만 더 많은 설명이 필요했습니다. – Nura