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 argument_file
In the command line above, option means one of the options described below, and argument_file means the chosen argument file
, which can have any arbitrary name.
The program must check that argument argument_file 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 argument_file and option arguments are given below.
File argument_file 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 1 and 10000000.
Fundamental note : your program is not expected to verify that file argument_file 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, 1251
application, SPROcp1, C++ Compiler, 25477
system, BRCMbnxe, Broadcom NIC Driver, 5423
newcat, madeup, a made up line, 100000
application, ecj, Eclipse JDT,75443
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 argument_file 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: 207594
In the case in which file argument_file is empty, your program must print:
Total size in kilobytes: 0
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 -1 ecj argument file
Expected output:
Package: ecj
Category: application
Description: Eclipse JDT
Size in kilobytes: 75443
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 -1 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 argument_file (this option doesn't exist)
python pkginfo.py a (it misses the argument file)
python pkginfo.py -l argument_file (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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!