Question: Title: pkginfo with Python In this assignment, you will write a Python program loosely inspired by Unix command pkginfo ( a command available in a
Title: pkginfo with Python
In this assignment, you will write a Python program loosely inspired by Unix command pkginfo a command available in a few versions of Unix Your Python program will read a file containing information about the installed software packages and will generate output depending on the command line.
These are the specifications for your Python program:
It must be named pkginfo.py
It must be invoked as:
python pkginfo.py option argumentfile
In the command line above, option means one of the options described below, and argumentfile means the chosen argument file
which can have any arbitrary name.
The program must check that argument argumentfile exists, is a file and is readable. If not, it must print an error message to
the standard output and exit. The specifications for the argumentfile and option arguments are given below.
File argumentfile can have any arbitrary name. It must be a file of text with the following format:
a The file consists of an arbitrary number of lines including possibly, zero lines
b Each line must contain four fields separated by commas.
c The four fields are: category, name, description,size in kilobytes.
d The category and name fields are each a string of characters of arbitrary yet reasonably limited length. Acceptable characters include: lower and upper case letters, digits, underscore, dot.
e The description field is a string of characters of arbitrary yet reasonably limited length. Acceptable characters include: lower and upper case letters, digits, underscore, dot, space.
f The size in kilobytes field is an integer limited between and
Fundamental note : your program is not expected to verify that file argumentfile complies with the above specifications. It will only be tested with compliant files.
The following example should be regarded as the reference specification for the format of file argument file:
system, SUNWdoc, Documentation Tools,
application, SPROcp C Compiler,
system, BRCMbnxe, Broadcom NIC Driver,
newcat, madeup, a made up line,
application, ecj, Eclipse JDT
Your program can be invoked with option: a In this case, it must print the names of the installed packages in the order in which they appear in the argument file, in this format:
Installed packages:
first name in appearance order second name in appearance order
last name in appearance order
Example with the example argument file given above:
Command line:
python pkginfo.py a argument file
Expected output:
Installed packages:
SUNWdoc
SPROcpl
BRCMbnxe
madeup
ecj
In the case in which file argumentfile is empty, your program must instead only print:
No packages installed
Your program can be invoked with option: s In this case, it must print the total size in kilobytes of all the installed packages, in this format:
Total size in kilobytes: total size in kilobytes of all the installed packages
Example with the example argument file given above:
Command line:
python pkginfo.py s argument file
Expected output:
Total size in kilobytes:
In the case in which file argumentfile is empty, your program must print:
Total size in kilobytes:
Your program can be invoked with option: I name. The name argument has the same format as the name field in the argument file. In this case, your program must search for a package with that name in the argument file, and if it finds it print its information in this format:
Package: name
Category: category
Description: description
Size in kilobytes: size in kilobytes
Example with the example argument file given above:
Command line:
python pkginfo.py ecj argument file
Expected output:
Package: ecj
Category: application
Description: Eclipse JDT
Size in kilobytes:
In the case in which a package with name name is not present in argument file, your program must print:
No installed package with this name
Example with the example argument file given above:
Command line:
python plginfo.py not there argument file
Expected output:
No installed package with this name
Your program can be invoked with option: v In this case, it must only print your name, surname, student ID and date of completion of your assignment, in a format of your choice.
Please note that argument arqument file is still required.
No options can be used simultaneously. This means that your program can only be invoked with one of the options at a time.
If your program is invoked with any other syntax than those specified above, it must print a message of your choice to the standard output and exit.
Examples of incorrect syntax:
python pkginfo.py Z argumentfile this option doesn't exist
python pkginfo.py a it misses the argument file
python pkginfo.py l argumentfile it misses an argument
The program works correctly with any valid file and for all options,
but its execution experiences some minor problems.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
