Changes

Jump to: navigation, search

OPS435 Assignment 2 for Section A

1,834 bytes added, 10:56, 15 July 2021
Second Milestone (due August 2)
An example of the finished code your script might produce is this:
<code><b>user@host ~ $ ./duim.py -H /usr/local/lib</b></code>
<pre>
61 % [============ ] 160.2 MiB M /usr/local/lib/heroku 4 % [= ] 10.8 MiB M /usr/local/lib/python2.7 34 % [======= ] 90.4 MiB M /usr/local/lib/node_modules 0 % [ ] 8.0 kiB K /usr/local/lib/python3.8Total: 261.4 MiB M /usr/local/lib
</pre>
Notice that total size of the target directory (/usr/local/lib) is around 260 Megabytes. Of that 260 Megabytes, 160 Megabytes can be found in the heroku subdirectory. 160 MB represents 61% of the total 160 MB. The details percentages don't have to add up to 100%, since with these arguments we are excluding files in the target directory. You may choose to add an option to your script to print files as well.  The bar chart in this example is 20 characters long, but this must be dynamic. The 20 characters does <i>not</i> the square brackets. The resolution of the bar chart must become more accurate as you increase the total size. For example, if the user specifies a length of 100 total characters, in this example 61 of those characters would be equal signs and 39 would be spaces. The output of each subdirectory should include percentage, size in bytes (or Human readable if the user uses the -H option), the bar chart and the name of the subdirectory. Specific formatting of the final output will be up to you, but you should be formatted in such a way that the output is easy to read. (ie. use columns!)  You will be required to fulfill some specific requirements before completing your script. Read on...
= Assignment Requirements =
 
== Starting Code ==
The first step for the assignment will be to accept the assignment using the invite code provided by your instructor. You will need to create a GitHub account to do this. (If you already have a GitHub account, you may use this).
 
In your repository you will find a file called <b>duim.py</b>. This file contains starting code. You will complete the assignment inside duim.py. <b>Do not rename this file or the functions inside, unit tests will fail and you will lose marks!</b>
 
Also in your repository you will find <b>checkA2.py</b>. You can use this check script to check your work.
 
== Permitted Modules ==
<b><font color='blue'>Your python script is allowed to import only the <u>os, subprocess, argparse and sys</u> modules from the standard library.</font></b>
To run the check script, enter the following:
<code>python python3 checkA2.py -f -v TestDirDict</code>
You will be using a module in the standard library called <b>Argparse</b>. This will help handle more complex sets of options and arguments than simply using sys.argv.
<code><b>user@host ~ $ python3 duim.py -h</b></code>
<pre>
usage: duim.py [-h] [-H] [-l LENGTH] [target]
DU Improved -- See Disk Usage Report with bar charts
== Minimum Viable Product ==
Once you have achieved the Milestones, you will have to do the following to get a minimum viable product:
* In your <code>if __name__ == '__main__'</code> block, you will have to check command line argumentscall the parse_command_args function. Experiment with print statements so that you understand how each option and argument are stored.
** If the user has entered more than one argument, or their argument isn't a valid directory, print an error message.
** If the user doesn't specify any target, use the current directory.
* Call <code>call_du_sub</code> with the target directory.
* Pass the return value from that function to <code>create_dir_dict</code>

Navigation menu