smb2-quota: Simplify code logic for quota entries.
Subsystems (2)
PATCH 1/1 smb2-quota: Simplify code logic for quota entries.
This patch changes the program name from smb2quota to smb2-quota and uses a simple code logic for quota entries.
Signed-off-by Kenneth D'souza <[email protected]>
Signed-off-by Ronnie Sahlberg <[email protected]>
--- smb2quota.py => smb2-quota.py | 19 +++++++------------ smb2quota.rst => smb2-quota.rst | 8 ++++---- 2 files changed, 11 insertions(+), 16 deletions(-) rename smb2quota.py => smb2-quota.py (91%) rename smb2quota.rst => smb2-quota.rst (89%)
smb2-quota.py renamed from smb2quota.py +7 -12
@@ -1,7 +1,7 @@ #!/usr/bin/env python # coding: utf-8 # -# smb2quota is a cmdline tool to display quota information for the +# smb2-quota is a cmdline tool to display quota information for the # Linux SMB client file system (CIFS) # # Copyright (C) Ronnie Sahlberg ([email protected]) 2019
@@ -34,7 +34,7 @@ ENDC = '\033[m' # Rest to defaults def usage(): print("Usage: %s [-h] <options> <filename>" % sys.argv[0]) - print("Try 'smb2quota -h' for more information") + print("Try 'smb2-quota -h' for more information") sys.exit()
@@ -120,18 +120,13 @@ class QuotaEntry: class Quota: def __init__(self, buf, flag): self.quota = [] - s = struct.unpack_from('<I', buf, 0)[0] - while s: - qe = QuotaEntry(buf[0:s], flag) + while buf: + qe = QuotaEntry(buf, flag) self.quota.append(qe) - buf = buf[s:] - a = s s = struct.unpack_from('<I', buf, 0)[0] if s == 0: - s = a # Use the last value of s and process it. - qe = QuotaEntry(buf[0:s], flag) - self.quota.append(qe) break + buf = buf[s:] def __str__(self): s = ''
@@ -158,7 +153,7 @@ def parser_check(path, flag): fcntl.ioctl(f, CIFS_QUERY_INFO, buf, 1) os.close(f) if flag == 0: - print(BBOLD + " %-7s | %-7s | %-7s | %-7s | %-12s | %s " + ENDC) % (titleused, titlelim, titlethr, titlepercent, titlestatus, titlesid) + print((BBOLD + " %-7s | %-7s | %-7s | %-7s | %-12s | %s " + ENDC) % (titleused, titlelim, titlethr, titlepercent, titlestatus, titlesid)) q = Quota(buf[24:24 + struct.unpack_from('<I', buf, 16)[0]], flag) print(q) except IOError as reason:
@@ -171,7 +166,7 @@ def main(): if len(sys.argv) < 2: usage() - parser = argparse.ArgumentParser(description="Please specify an action to perform.", prog="smb2quota") + parser = argparse.ArgumentParser(description="Please specify an action to perform.", prog="smb2-quota") parser.add_argument("-t", "--tabular", action="store_true", help="print quota information in tabular format") parser.add_argument("-c", "--csv", action="store_true", help="print quota information in csv format") parser.add_argument("-l", "--list", action="store_true", help="print quota information in list format")
smb2-quota.rst renamed from smb2quota.rst +4 -4
@@ -1,5 +1,5 @@ ============ -smb2quota +smb2-quota ============ -----------------------------------------------------------------------------------------------------
@@ -11,7 +11,7 @@ Userspace helper to display quota information for the Linux SMB client file syst SYNOPSIS ******** - smb2quota [-h] {options} {file system object} + smb2-quota [-h] {options} {file system object} *********** DESCRIPTION
@@ -19,7 +19,7 @@ DESCRIPTION This tool is part of the cifs-utils suite. -`smb2quota` is a userspace helper program for the Linux SMB +`smb2-quota` is a userspace helper program for the Linux SMB client file system (CIFS). This tool works by making an CIFS_QUERY_INFO IOCTL call to the Linux
@@ -49,7 +49,7 @@ SID,Amount Used,Quota Limit,Warning Level NOTES ***** -Kernel support for smb2quota requires the CIFS_QUERY_INFO +Kernel support for smb2-quota requires the CIFS_QUERY_INFO IOCTL which was initially introduced in the 4.20 kernel and is only implemented for mount points using SMB2 or above (see mount.cifs(8) `vers` option).
Signature · 1 line
2.21.0
Pavel Shilovsky
Appliedчт, 21 нояб. 2019 г. в 07:11, Kenneth D'souza <[email protected]>:
Quoted 120 lines
This patch changes the program name from smb2quota to smb2-quota and uses a simple code logic for quota entries.
Signed-off-by Kenneth D'souza <[email protected]>Signed-off-by Ronnie Sahlberg <[email protected]>--- smb2quota.py => smb2-quota.py | 19 +++++++------------ smb2quota.rst => smb2-quota.rst | 8 ++++---- 2 files changed, 11 insertions(+), 16 deletions(-) rename smb2quota.py => smb2-quota.py (91%) rename smb2quota.rst => smb2-quota.rst (89%)smb2-quota.py renamed from smb2quota.py +7
-12@@ -1,7 +1,7 @@ #!/usr/bin/env python # coding: utf-8 # -# smb2quota is a cmdline tool to display quota information for the +# smb2-quota is a cmdline tool to display quota information for the # Linux SMB client file system (CIFS) # # Copyright (C) Ronnie Sahlberg ([email protected]) 2019@@ -34,7 +34,7 @@ ENDC = '\033[m' # Rest to defaults def usage(): print("Usage: %s [-h] <options> <filename>" % sys.argv[0]) - print("Try 'smb2quota -h' for more information") + print("Try 'smb2-quota -h' for more information") sys.exit()@@ -120,18 +120,13 @@ class QuotaEntry: class Quota: def __init__(self, buf, flag): self.quota = [] - s = struct.unpack_from('<I', buf, 0)[0] - while s: - qe = QuotaEntry(buf[0:s], flag) + while buf: + qe = QuotaEntry(buf, flag) self.quota.append(qe) - buf = buf[s:] - a = s s = struct.unpack_from('<I', buf, 0)[0] if s == 0: - s = a # Use the last value of s and process it. - qe = QuotaEntry(buf[0:s], flag) - self.quota.append(qe) break + buf = buf[s:] def __str__(self): s = ''@@ -158,7 +153,7 @@ def parser_check(path, flag): fcntl.ioctl(f, CIFS_QUERY_INFO, buf, 1) os.close(f) if flag == 0: - print(BBOLD + " %-7s | %-7s | %-7s | %-7s | %-12s | %s " + ENDC) % (titleused, titlelim, titlethr, titlepercent, titlestatus, titlesid) + print((BBOLD + " %-7s | %-7s | %-7s | %-7s | %-12s | %s " + ENDC) % (titleused, titlelim, titlethr, titlepercent, titlestatus, titlesid)) q = Quota(buf[24:24 + struct.unpack_from('<I', buf, 16)[0]], flag) print(q) except IOError as reason:@@ -171,7 +166,7 @@ def main(): if len(sys.argv) < 2: usage() - parser = argparse.ArgumentParser(description="Please specify an action to perform.", prog="smb2quota") + parser = argparse.ArgumentParser(description="Please specify an action to perform.", prog="smb2-quota") parser.add_argument("-t", "--tabular", action="store_true", help="print quota information in tabular format") parser.add_argument("-c", "--csv", action="store_true", help="print quota information in csv format") parser.add_argument("-l", "--list", action="store_true", help="print quota information in list format")smb2-quota.rst renamed from smb2quota.rst +4
-5@@ -1,5 +1,5 @@ ============ -smb2quota +smb2-quota ============ -----------------------------------------------------------------------------------------------------@@ -11,7 +11,7 @@ Userspace helper to display quota information for the Linux SMB client file syst SYNOPSIS ******** - smb2quota [-h] {options} {file system object} + smb2-quota [-h] {options} {file system object} *********** DESCRIPTION@@ -19,7 +19,7 @@ DESCRIPTION This tool is part of the cifs-utils suite. -`smb2quota` is a userspace helper program for the Linux SMB +`smb2-quota` is a userspace helper program for the Linux SMB client file system (CIFS). This tool works by making an CIFS_QUERY_INFO IOCTL call to the Linux@@ -49,7 +49,7 @@ SID,Amount Used,Quota Limit,Warning Level NOTES ***** -Kernel support for smb2quota requires the CIFS_QUERY_INFO +Kernel support for smb2-quota requires the CIFS_QUERY_INFO IOCTL which was initially introduced in the 4.20 kernel and is only implemented for mount points using SMB2 or above (see mount.cifs(8) `vers` option). --
Quoted 2 lines
2.21.0
Merged, thanks.
--
Best regards,
Pavel Shilovsky