How to get rid of global variables gl_args and gl_hashType, while preserving all the functionality of the program. Hint: Use python to add arguments and return values to functions to pass the necessary variables in and out.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How to get rid of global variables gl_args and gl_hashType, while preserving all the functionality of the program.
Hint: Use python to add arguments and return values to functions to pass the necessary variables in and out.

def ParseCommandLine():
parser = argparse. ArgumentParser('Python file system hashing p-fish')
parser.add_argument ('-v', "--verbose", help="allows progress messages to be displayed", action='store_true')
# setup a group where the selection is mutually exclusive and required.
group = parser.add_mutually_exclusive_group (required=True)
group.add_argument('--md5'
help = 'specifies MD5 algorithm',
group.add_argument('--sha256' help = 'specifies SHA256 algorithm',
group.add_argument('--sha512',
action='store_true')
action='store_true')
action='store_true')
group.add_argument ('--sha224'
help = 'specifies SHA512 algorithm',
help = 'specifies SHA224 algorithm'
action='store_true')
group.add_argument ('--sha384', help = 'specifies SHA384 algorithm', action='store_true')
parser.add_argument ('-d', '--rootPath', type= ValidateDirectory, required=True, help="specify the root path for hashing")
parser.add_argument ('-r', '--reportPath', type= ValidateDirectorywritable, required=True, help="specify the path for reports and logs will be written")
global gl_args
global gl_hashType
gl_args = parser.parse_args()
if gl_args.md5:
gl_hashType = 'MD5'
elif gl_args.sha256:
gl_hashType = 'SHA256'
elif gl_args.sha512:
gl_hashType = 'SHA512'
elif gl_args.sha224:
gl_hashType = 'SHA224'
elif gl_args.sha384:
gl_hashType = 'SHA384'
"
# create a global object to hold the validated arguments, these will be available then
# to all the Functions within the _pfish.py module
else:
"
return
gl_hashType = "Unknown"
logging.error('Unknown Hash Type Specified')
DisplayMessage("Command line processed: Successfully")
Transcribed Image Text:def ParseCommandLine(): parser = argparse. ArgumentParser('Python file system hashing p-fish') parser.add_argument ('-v', "--verbose", help="allows progress messages to be displayed", action='store_true') # setup a group where the selection is mutually exclusive and required. group = parser.add_mutually_exclusive_group (required=True) group.add_argument('--md5' help = 'specifies MD5 algorithm', group.add_argument('--sha256' help = 'specifies SHA256 algorithm', group.add_argument('--sha512', action='store_true') action='store_true') action='store_true') group.add_argument ('--sha224' help = 'specifies SHA512 algorithm', help = 'specifies SHA224 algorithm' action='store_true') group.add_argument ('--sha384', help = 'specifies SHA384 algorithm', action='store_true') parser.add_argument ('-d', '--rootPath', type= ValidateDirectory, required=True, help="specify the root path for hashing") parser.add_argument ('-r', '--reportPath', type= ValidateDirectorywritable, required=True, help="specify the path for reports and logs will be written") global gl_args global gl_hashType gl_args = parser.parse_args() if gl_args.md5: gl_hashType = 'MD5' elif gl_args.sha256: gl_hashType = 'SHA256' elif gl_args.sha512: gl_hashType = 'SHA512' elif gl_args.sha224: gl_hashType = 'SHA224' elif gl_args.sha384: gl_hashType = 'SHA384' " # create a global object to hold the validated arguments, these will be available then # to all the Functions within the _pfish.py module else: " return gl_hashType = "Unknown" logging.error('Unknown Hash Type Specified') DisplayMessage("Command line processed: Successfully")
def DisplayMessage (msg):
if gl_args. verbose:
print (msg)
return
Transcribed Image Text:def DisplayMessage (msg): if gl_args. verbose: print (msg) return
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education