Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Description: This project focuses on automating command execution in Python to facilitate the seamless execution of various tasks, providing a foundation for automation testing scenarios
Description:
This project focuses on automating command execution in Python to facilitate the seamless execution of various tasks, providing a foundation for automation testing scenarios across different environments. The resulting software can be employed to run predefined scripts, checking for specific behaviors and ensuring the robustness of the tested systems.
Components:
Command Implementation:
Mvlast :
Moves the most recent file from the source directory to the destination directory.
Categorize :
Splits files in the given directory into two types:
An inner directory with files less than a specified
An inner directory with files more than the specified
Count :
Counts the number of files in the specified directory.
Delete :
Deletes a specified file from the specified directory.
Rename :
Renames a file in the specified directory.
List :
Lists all files and directories in the specified directory.
Sort :
Sorts the files in the specified directory based on the specified criteria.
Supported criteria: "name", "date", "size".
Main ClassScript:
Implements a class that reads predefined scripts based on the above commands and parsesexecutes them. The class utilizes the code for command execution from the first step.
Configuration:
Utilizes a Python JSON configuration file configjson that contains essential values for running the application:
Thresholdsize: Value needed by the Categorize command.
Maxcommands: Maximum number of commands that should be executed per script.
Maxlogfiles: Maximum number of files in the log directory; older files are deleted if the limit is exceeded.
Samedir: Specifies whether PASSED and FAILED should be placed in the same directory or in internal pass and fail subdirectories.
Output: Supports two types of results CSV and log files. If CSV is chosen, the output consists of two columns, each statement with the result. If log is chosen, each statement with its result is printed in the file.
Option Parser:
Utilizes the Python argparse module for specifying input script file and output log result.
Logging:
Utilizes the Python logging module for debugging and producing the final script result. No print statements are used.
Output:
Csv: if csv if chosen, the output should be columns, each statement with the result include a pass or fail word in the name of the file.
Log: print each statement with its result in the file include a pass or fail word in the name of the file.
Example:
You have the following script.txt file of commands:
Mvlast
Count
Delete filetodelete.txt
Categorize
Mvlast: Move the most recent file from MovFrom to MovTo.
Count: Count the number of files in MyDirectoryToCount.
Delete: Delete the file named filetodelete.txt from the Directory.
Categorize: Categorize files in Test into two inner directories based on the threshold size specified in the configuration.
You also need to have configuration.json file that looks like:
"Thresholdsize": KB
"Maxcommands":
"Maxlogfiles":
"Samedir": false,
"Output": csv
Thresholdsize: The threshold size used by the Categorize command.
Maxcommands: The maximum number of commands to be executed per script.
Maxlogfiles: The maximum number of log files; older files are deleted if the limit is exceeded.
Samedir: Whether PASSED or FAILED should be placed in the same directory or not.
Output: The desired output format, which is set to csv in this case.
Usage of the Python parser:
python scriptexecutor.py i script.txt o output.log
i script.txt: Specifies the input script file path as script.txt
o output.log: Specifies the output log file path as output.log
Hints
Check Factory design pattern in python to help you structure commands codes. Remember you have several types of a command.
For each run, create a python dictionary and save the result of each command on the run, at the end, parse the dictionary to provide your final log
Check how to parse json files in python very easy and straightforward.
Check logging library in python, very simple and provides a better way to control logs
Check python option parser to createfando
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started