mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-06 05:01:10 -07:00
Add comments.
This commit is contained in:
parent
d3100f6178
commit
1fdfd128ba
2 changed files with 28 additions and 4 deletions
|
@ -82,7 +82,7 @@ class DBConnection(object):
|
||||||
" Mode : {1}\n"
|
" Mode : {1}\n"
|
||||||
" Owner: {2}\n"
|
" Owner: {2}\n"
|
||||||
" Group: {3}\n"
|
" Group: {3}\n"
|
||||||
"===========================================".format(path, mode[-3:], owner, group),
|
"===========================================".format(path, mode, owner, group),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.connection.row_factory = Row
|
self.connection.row_factory = Row
|
||||||
|
|
|
@ -28,36 +28,60 @@ except ImportError:
|
||||||
|
|
||||||
def mode(path):
|
def mode(path):
|
||||||
"""Get permissions."""
|
"""Get permissions."""
|
||||||
return oct(os.stat(path).st_mode & 0o777)
|
stat_result = os.stat(path) # Get information from path
|
||||||
|
permissions_mask = 0o777 # Set mask for permissions info
|
||||||
|
|
||||||
|
# Get only the permissions part of st_mode as an integer
|
||||||
|
int_mode = stat_result.st_mode & permissions_mask
|
||||||
|
oct_mode = oct(int_mode) # Convert to octal representation
|
||||||
|
|
||||||
|
return oct_mode[2:] # Return mode but strip octal prefix
|
||||||
|
|
||||||
|
|
||||||
def nt_ownership(path):
|
def nt_ownership(path):
|
||||||
"""Get the owner and group for a file or directory."""
|
"""Get the owner and group for a file or directory."""
|
||||||
def fully_qualified_name(sid):
|
def fully_qualified_name(sid):
|
||||||
"""Return a fully qualified account name."""
|
"""Return a fully qualified account name."""
|
||||||
|
# Look up the account information for the given SID
|
||||||
|
# https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-lookupaccountsida
|
||||||
name, domain, _acct_type = LookupAccountSid(None, sid)
|
name, domain, _acct_type = LookupAccountSid(None, sid)
|
||||||
|
# Return account information formatted as DOMAIN\ACCOUNT_NAME
|
||||||
return '{}\\{}'.format(domain, name)
|
return '{}\\{}'.format(domain, name)
|
||||||
|
|
||||||
|
# Get the Windows security descriptor for the path
|
||||||
|
# https://learn.microsoft.com/en-us/windows/win32/api/aclapi/nf-aclapi-getnamedsecurityinfoa
|
||||||
security_descriptor = GetNamedSecurityInfo(
|
security_descriptor = GetNamedSecurityInfo(
|
||||||
os.fspath(path),
|
path, # Name of the item to query
|
||||||
SE_FILE_OBJECT,
|
SE_FILE_OBJECT, # Type of item to query (file or directory)
|
||||||
|
# Add OWNER and GROUP security information to result
|
||||||
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION,
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION,
|
||||||
)
|
)
|
||||||
|
# Get the Security Identifier for the owner and group from the security descriptor
|
||||||
|
# https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-getsecuritydescriptorowner
|
||||||
|
# https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-getsecuritydescriptorgroup
|
||||||
owner_sid = security_descriptor.GetSecurityDescriptorOwner()
|
owner_sid = security_descriptor.GetSecurityDescriptorOwner()
|
||||||
group_sid = security_descriptor.GetSecurityDescriptorGroup()
|
group_sid = security_descriptor.GetSecurityDescriptorGroup()
|
||||||
|
|
||||||
|
# Get the fully qualified account name (e.g. DOMAIN\ACCOUNT_NAME)
|
||||||
owner = fully_qualified_name(owner_sid)
|
owner = fully_qualified_name(owner_sid)
|
||||||
group = fully_qualified_name(group_sid)
|
group = fully_qualified_name(group_sid)
|
||||||
|
|
||||||
return owner, group
|
return owner, group
|
||||||
|
|
||||||
|
|
||||||
def posix_ownership(path):
|
def posix_ownership(path):
|
||||||
"""Get the owner and group for a file or directory."""
|
"""Get the owner and group for a file or directory."""
|
||||||
|
# Get path information
|
||||||
stat_result = os.stat(path)
|
stat_result = os.stat(path)
|
||||||
|
|
||||||
|
# Get account name from path stat result
|
||||||
owner = pwd.getpwuid(stat_result.st_uid)
|
owner = pwd.getpwuid(stat_result.st_uid)
|
||||||
group = grp.getgrgid(stat_result.st_gid)
|
group = grp.getgrgid(stat_result.st_gid)
|
||||||
|
|
||||||
return owner, group
|
return owner, group
|
||||||
|
|
||||||
|
|
||||||
|
# Select the ownership function appropriate for the platform
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
ownership = nt_ownership
|
ownership = nt_ownership
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue