Open main menu

CDOT Wiki β

Changes

OPS445 Online Assignment 2

515 bytes added, 10:04, 16 November 2022
m
Due Date and Final Submission requirement
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 261 MB. The 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> include 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.
== Starting Code ==
The first step for the assignment will be to accept the assignment using the invite code provided by your instructoron BB. 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>checkA2CheckA2.py</b>. You can use this check script to check your work.
=== Alternative Starting Code ===
<ul>
<li>[https://raw.githubusercontent.com/OPS445-W22/a2/files/duim.py duim.py (starting code) ]</li><li>[https://raw.githubusercontent.com/OPS445-W22/a2/files/CheckA2.py CheckA2.py (check script) ]</li><!-- <li>[https://ict.senecacollege.ca/~eric.brauer/ops445/a2/duim.py duim.py (starting code) ]</li> --><!--li>[https://ict.senecacollege.ca/~eric.brauer/ops445/a2/checkA2CheckA2.py checkA2CheckA2.py (check script) ]</li> -->
</ul>
== Required Functions ==
You will need to complete the functions inside the provided file called <code>duim.py</code>. The provided <code>checkA2CheckA2.py</code> will be used to test these functions.
* <code>call_du_sub()</code> should take the target directory as an argument and return a list of strings returned by the command <b>du -d 1<target directory></b>.** Use <code>subprocess.Popen</code>.
** '-d 1' specifies a <i>max depth</i> of 1. Your list shouldn't include files, just a list of subdirectories in the target directory.
** Your list should <u>notNOT</u> contain newline characters.
* <code>percent_to_graph()</code> should take two arguments: percent and the total chars. It should return a 'bar graph' as a string.
** Your function should check that the a percent argument is a valid number between 0 and 100. It should fail if it isn't. You can <code>raise ValueError</code> in this case.
** <b>total chars</b> refers to the total number of characters that the bar graph will be composed of. You can use equal signs <code>=</code> or any other character that makes sense, but the empty space <b>must be composed of spaces</b>, at least until you have passed the first milestone.
** The string returned by this function should only be composed of these two characters. For example, calling <code>percent_to_graph(50, 10)</code> should return:
'===== '
<b>Please note that the '' single quote characters should <u>notNOT</u> be part of the output, they are here to indicate that this is a string!</b>
* <code>create_dir_dict</code> should take a list as the argument, and should return a dictionary.
** The list can be the list returned by <code>call_du_sub()</code>.
The repo will contain a check script, a README file, and the file where you will enter your code.
== The First Milestone (due November 2125) ==For the first milestone , you will have two functions to complete.* <code>call_du_sub</code> will take one argument and return a list. The argument is a target directory. The function will use <code>subprocess.Popen</code> to run the command <b>du -d l 1 <target_directory></b>.
* <code>percent_to_graph</code> will take two arguments and return a string.
In order to complete <code>percent_to_graph()</code>, it's helpful to know the equation for converting a number from one scale to another.
[[File:Scaling-formula.png|250px]],
<br> or <br> [[File:Scaling-formula-min0.png|250px]]
In this equation, ``x`` refers to your input value percent , and ``y`` will refer to the number of symbols to print. The max of percent is 100 and the min of percent is 0.
Be sure that you are rounding to an integer, and then print that number of symbols to represent the percentage. The number of spaces that you print will be the inverse.
To test with the check script, run the following:
<code>python3 checkA2CheckA2.py -f -v TestPercent</code>
<code>python3 checkA2CheckA2.py -f -v TestDuSub</code>
== Second Milestone (due November 28December 2) ==
For the second milestone you will have two more functions to complete.
* <code>create_dir_dict</code> will take your list from <code>call_du_sub</code> and return a dictionary.
** Every item in your list should create a key in your dictionary.
** Your dictionary values should be integers, representing the number of bytes.
For example: <code>{'/usr/lib/local': 33400}</code>
To run the check script, enter the following:
<code>python3 checkA2CheckA2.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.
Specify the length of the graph. Default is 20.
Copyright 20212022
</pre>
Use the following to test your code:
<code>python3 checkA2CheckA2.py -f -v TestArgs</code>
== Minimum Viable Product ==
* In your <code>if __name__ == '__main__'</code> block, you will have to call 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>
It is expected that the additional features you provided should be useful, non-trivial, they should not require super-user privileges and should not require the installation of additional packages to work. (ie: I shouldn't have to run pip to make your assignment work).
== The Assignment (due December 109, 11:59pm) ==
* Be sure to make your final commit before the deadline. Don't forget to also use <code>git push</code> to push your code into the online repository!
* Then, copy the contents of your <b>duim.py</b> file into a Word documenta2_yoursenecauser.py, and submit it to Blackboardalong with a2_output.txt generated from '''CheckA2.py -f -v''' script. <i>I will use GitHub to evaluate your deadline, but submitting to Blackboard tells me that you wish to be evaluated.</i>
= Rubric =
Please submit the following files by the due date:
* [ ] your Your python script, named as 'duim.py', in your repository, and also '''submitted to Blackboard'''as a2_yoursenecauser.py, by December 10 9 at 11:59pm.* Submit it to Blackboard along with a2_output.txt generated from '''CheckA2.py -f -v''' script. <i>I will use GitHub to evaluate your deadline, but submitting to Blackboard tells me that you wish to be evaluated.</i>
572
edits