Changes

Jump to: navigation, search

OPS435 Python/assignment 1 fall2022

414 bytes added, 14:09, 24 September 2022
Required Functions
== Required Functions ==
You will need to complete the functions inside the provided file called <code>duim.py</code>. The provided <code>checkA2checkA1.py</code> will be used to test these functions.
* 1. <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 subprocess.Popenor os.popen.
** '-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>not</u> contain newline characters.
* 2. <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 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>max_length</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 '' characters should <u>not</u> be part of the output, they are here to indicate that this is a string!</b>
* 3. <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 dictionary that you return should have the full directory name as <i>key</i>, and the number of bytes in the directory as the <i>value</i>. This value should be an integer. For example, using the example of <b>/usr/local/lib</b>, the function would return:
{'/usr/local/lib/heroku': 164028, '/usr/local/lib/python2.7': 11072, ...}
4. <code>get_max</code> should take a dictionary and the target directory as arguments, and it should return the total size of the target directory as an integer.
** The dictionary returned by <code>create_dir_dict</code> will be used for this function. When calculating the percentage for each subdirectory, you will need the total size of the target directory as the denominator. This function will return that value.
** There are many approaches you can take to get this number. Some approaches won't require the target directory as an argument, but pass it in anyway.
== Additional Functions ==

Navigation menu