Difference between revisions of "OPS435 Assignment 1 for Section C"

From CDOT Wiki
Jump to: navigation, search
(Created page with "Category:OPS435-PythonCategory:rchan = Overview = When making back up of data files or log files, it is a very common practice to name the backup directories and/or fi...")
 
(Second Milestone (due February 21))
 
(33 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:OPS435-Python]][[Category:rchan]]
+
[[Category:OPS435-Python]][[Category:ebrauer]]
= Overview =
+
= Overview: du Improved =
When making back up of data files or log files, it is a very common practice to name the backup directories and/or files based on the date the backup was done. In order to restore or locate the directory/file, we often need to find out the backup date from today's date.
+
<code>du</code> is a tool for inspecting directories. It will return the contents of a directory along with how much drive space they are using. However, it can be parse its output quickly, as it usually returns file sizes as a number of bytes:
  
The computational task for this assignment is to design an algorithm and write a python script according to your algorithm with appropriate functions. The script should take two dates in the "DD-MM-YYYY" format and return the number of days from the first to the second date. That is, if the user enters "18-06-2020" and "25-06-2020", the script will return "7". Similarly, if the target date is in the past, the script will return a negative number.
+
<code><b>user@host ~ $ du --max-depth 1 /usr/local/lib</b></code>
 +
<pre>
 +
164028 /usr/local/lib/heroku
 +
11072 /usr/local/lib/python2.7
 +
92608 /usr/local/lib/node_modules
 +
8 /usr/local/lib/python3.8
 +
267720 /usr/local/lib
 +
</pre>
 +
You will therefore be creating a tool called <b>duim (du improved></b>. Your script will call du and return the contents of a specified directory, and generate a bar graph for each subdirectory. The bar graph will represent the drive space as percent of the total drive space for the specified directory.
 +
An example of the finished code your script might produce is this:
 +
 
 +
<code><b>user@host ~ $ ./duim.py /usr/local/lib</b></code>
 +
<pre>
 +
61 % [============        ] 160.2 MiB /usr/local/lib/heroku
 +
  4 % [=                  ] 10.8 MiB /usr/local/lib/python2.7
 +
34 % [=======            ] 90.4 MiB /usr/local/lib/node_modules
 +
  0 % [                    ] 8.0 kiB /usr/local/lib/python3.8
 +
Total: 261.4 MiB /usr/local/lib
 +
</pre>
  
In addition, if the user enters one date only, then the number returned should be the number of days between today's date and the specified date.  
+
The details of the final output will be up to you, but you will be required to fulfill some specific requirements before completing your script. Read on...
  
 
= Assignment Requirements =
 
= Assignment Requirements =
== The First Milestone (due June 19) ==
+
== Permitted Modules ==
* Before you begin programming, it is important to plan your algorithm. Therefore your first task will be to complete and submit an algorithm document. This document should be named '''algorithm_[student_id].txt'''. This file should be plaintext. The document will contain two sections:
+
<b><font color='blue'>Your python script is allowed to import only the <u>os, subprocess and sys</u> modules from the standard library.</font></b>
  * A description of how the "after()" function works. The "after()" function is provided to you in a1_template.py. Open the file, and use clear English to describe what line of code does in such a way that a competent programmer could reproduce the code without seeing it firsthand.
 
  * You will then apply the same principles to create an algorithm for "before()", and "dbda()". Inside the code, if you are calling another function like "leap_year", you may simply describe what the function will return, and not the operation of the function itself.
 
* This file will be submitted to Blackboard a week after the assignment goes live, and should be your first priority. The object of the milestone is not to have a 100% perfect algorithm, but to plan ahead and anticipate challenges and issues with the assignment. The milestone will also give your professor an opportunity for feedback.
 
* [https://simple.m.wikipedia.org/wiki/Algorithm Here is an basic introduction to Algorithm]
 
* While you are working on the step-by-step instructions, note that there are different number of days in each month and some years have 365 days and some years have 366 days.
 
* You should also do some research to find out when we started using the Calendar in the current form. (This will pose a limit on the validity of your algorithm.)
 
  
== The Assignment (due July 3) ==
+
== Required Functions ==
* As stated before, your code will be inside the file "a1_[studentid].py". The first step will be to clone the Assignment 1 repository. The invite link will be provided to you by your professor. Once you clone the repository, run this command: "cp a1_template.py a1_[studentid].py". (Replace studentid with your myseneca username). Begin writing the content that is required. Additional requirements are outlined below.
+
You will need to complete the functions inside the provided file called <code>duim.py</code>. The provided <code>checkA1.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 subprocess.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.
 +
* <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>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:
 +
    '=====    '
 +
* <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, ...}
 +
 
 +
== Additional Functions ==
 +
You may create any other functions that you think appropriate, especially when you begin to build additional functionality. Part of your evaluation will be on how "re-usable" your functions are, and sensible use of arguments and return values.  
 +
 
 +
== Use of GitHub ==
 +
You will be graded partly on the quality of your Github commits. You may make as many commits as you wish, it will have no impact on your grade. The only exception to this is <b>assignments with very few commits.</b> These will receive low marks for GitHub use and may be flagged for possible academic integrity violations.
 +
<b><font color='blue'>Assignments that do not adhere to these requirements may not be accepted.</font></b>
 +
 
 +
Professionals generally follow these guidelines:
 +
* commit their code after every significant change,
 +
* the code <i>should hopefully</i> run without errors after each commit, and
 +
* every commit has a descriptive commit message.
  
== The Debrief (due July 10) ==
+
After completing each function, make a commit and push your code.  
This document, like the algorithm document, will be submitted to Blackboard one week after the assignment. Answer the following questions:
 
* Research Python modules that you could have used to accomplish the same goals as the today() and leap_year() functions.
 
* Which solution is preferable, in terms of performance? Which solution is preferable, in terms of programmer hours? (which solution would take longer for a programmer to implement?)
 
* Which approach would be preferable in the "real world"? Why is it useful to try creating our own algorithm?
 
* What challenges did you encounter during the assignment, and what resources did you use to solve your issues? (help from classmates, help from Stackoverflow, debuggers, etc.)
 
* Additionally, your professor may have questions specific to your submission. You should answer these questions as well.
 
  
== Assignment Requirements ==
+
After fixing a problem, make a commit and push your code.  
=== Required Modules and Functions ===
 
<b><font color='blue'>Your python script is allowed to import only the <u>os, subprocess and sys</u> modules from the standard library and all the built-in functions.</font></b>
 
  
Based on the algorithm you have designed for this assignment, you should at least have the following four functions defined in your python script (see later section on the purpose of each function) in order to get a passing grade for this assignment:
+
<b><u>GitHub is your backup and your proof of work.</u></b>
* dbda()
 
* after()
 
* before()
 
* today()
 
  
You should also create additional functions to improved the re-usability of your python code by adding the following functions to earn the maximum possible mark for this assignment:
+
These guidelines are not always possible, but you will be expected to follow these guidelines as much as possible. Break your problem into smaller pieces, and work iteratively to solve each small problem. Test your code after each small change you make, and address errors as soon as they arise. It will make your life easier!
* days_in_mon()
 
* leap_year()
 
* valid_date()
 
* usage()
 
  
=== Coding Standard ===
+
== Coding Standard ==
 
Your python script must follow the following coding guide:
 
Your python script must follow the following coding guide:
 
* [https://www.python.org/dev/peps/pep-0008/ PEP-8 -- Style Guide for writing Python Code]
 
* [https://www.python.org/dev/peps/pep-0008/ PEP-8 -- Style Guide for writing Python Code]
 
=== Command Line Argument to be supported ===
 
* You will provided with a file called a1_template.py.
 
* Rename this python script as a1_[student_id].py, where [student_id] is your Seneca email user name.
 
* Your python script must support one or two command line arguments only: both should be valid dates in DD-MM-YYYY format.
 
* If there are no arguments, more than two arguments, or an invalid date, your script should display the correct usage message and exit.
 
  
 
=== Documentation ===
 
=== Documentation ===
 
* Please use python's docstring to document your python script (script level documentation) and each of the functions (function level documentation) you created for this assignment. The docstring should describe 'what' the function does, not 'how' it does.
 
* Please use python's docstring to document your python script (script level documentation) and each of the functions (function level documentation) you created for this assignment. The docstring should describe 'what' the function does, not 'how' it does.
 +
* Your script should also include in-line comments to explain anything that isn't immediately obvious to a beginner programmer. <b><u>It is expected that you will be able to explain how each part of your code works in detail.</u></b>
 
* Refer to the docstring for after() to get an idea of the function docstrings required.
 
* Refer to the docstring for after() to get an idea of the function docstrings required.
  
 
=== Authorship Declaration ===
 
=== Authorship Declaration ===
All your Python code for this assignment must be placed in a <font color='red'><b><u>single source python file</u></b></font>. Please complete the declaration <b><u>as part of the docstring</u></b> in your Python source code file (replace "Student Name" with your own name).
+
All your Python code for this assignment must be placed in the provided Python file called <b>assignment1.py</b>. <u>Do not change the name of this file.</u> Please complete the declaration <b><u>as part of the docstring</u></b> in your Python source code file (replace "Student Name" with your own name).
 +
 
 +
= Submission Guidelines and Process =
 +
 
 +
== Clone Your Repo (ASAP) == 
 +
The first step will be to clone the Assignment 1 repository. The invite link will be provided to you by your professor. The repo will contain a check script, a README file, and the file where you will enter your code.
 +
 
 +
== The First Milestone (due February 14) ==
 +
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 <target_directory></b>.
 +
* <code>percent_to_graph</code> will take two arguments and return a string.
  
=== Github Commits ===
+
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.
You will be graded partly on the quality of your Github commits. Professionals generally follow these guidelines:
+
 
* commit their code after every significant change,  
+
[[File:Scaling-formula.png]]
* the code should run without errors after each commit, and
+
 
* every commit has a descriptive commit message.
+
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.
These guidelines are not always possible, but you will be expected to follow these guidelines as much as possible. Break your problem into smaller pieces, and work iteratively to solve each small problem. Test your code after each small change you make, and address errors as soon as they arise. It will make your life easier!
+
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.
  
== Tests and Test results ==
+
Test your functions with the Python interpreter. Use <code>python3</code>, then:
You must name your python 3 script as <code>a1_[Student_id].py</code>. The following examples assumes that the student_id is rchan.The script should accept two command line arguments, the first one is the date in "YYYY-MM-DD" format, and the second one is the number of day from the given date, a positive value indicates the number of days after the given date, and a negative value indicates the number of days before the given date. There is an optional flag called --step which can be provided at the command line that makes the program print out all dates until the target date. If the "YYYY-MM-DD" format is broken, your script should give an appropriate error message. Invalid months (>12) or invalid days of month(different for each month), should be detected and give appropriate error messages. For examples:
+
    import duim
* <b><code>python3 a1_rchan.py 01-01-2019 02-01-2019</code></b>, and the output should be<br />
+
    duim.percent_to_graph(50, 10)
    1
 
* <b><code>python3 a1_rchan.py 01-01-2019 31-12-2018</code></b>, and the output should be<br />
 
    -1
 
* <b><code>python3 a1_rchan.py 01-06-2020</code></b>, and since today is June 3, the output should be<br />
 
    2
 
* <b><code>python3 a1_rchan.py 01-01-2019 01-01-2020</code></b>, and the output should be<br />
 
    365
 
* <b><code>python3 a1_rchan.py 01-01-2021 01-01-2020 </code></b>, and the output should be<br />
 
    -366
 
* <b><code>python3 a1_rchan.py 01-13-2018</code></b>, and the output should be<br />
 
    Error: wrong month entered
 
* <b><code>python3 a1_rchan.py 99-01-2020 01-01-2020</code></b>, and the output should be<br />
 
    Error: wrong day entered
 
* <b><code>python3 a1_rchan.py 2018 2</code></b>, and the output should be<br />
 
    Error: wrong date entered
 
  
If there is too few or too many command line arguments given, display the proper usage:
+
To test with the check script, run the following:
* <code>Usage: a1_rchan.py DD-MM-YYYY [DD-MM-YYYY] >/code>
 
  
== Script structure and sample template ==
+
<code>python3 checkA1.py -f -v TestPercent</code>
  
The following is a brief description of each function:
+
== Second Milestone (due February 21) ==
 +
For the second milestone you will have one more function 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 a number of bytes.
  
* The dbda() function should be the main function of your script. The dbda() function will take two dates in "DD-MM-YYYY" format, and return an integer that corresponds to the number of days between the given dates. If the start date is earlier than the stop date, the number is positive. If start date is later than the stop date, the number is negative. Your dbda() function should delegate the actual calculation of the target date to either the after() function or the before() function.
+
For example: <code>{'/usr/lib/local': 33400}</code>
* The today() function will be called if the user has not specified a second argument. It will return '''your Linux computer's local time''' in the format DD-MM-YYYY. Hint: you may need to read man pages for a shell command in order to return a usable date. You may also use string formatting to modify output.
+
* The before() function will take a date in "DD-MM-YYYY" format and return the date of the previous day in the same format.
+
** Again, test using your Python interpreter or the check script.
* The after() function will take a date in "DD-MM-YYYY" format and return the date of the next day in the same format. Next paragraph is a sample python code for the after() function. To earn the maximum possible mark for the assignment, you should modify the sample after() function to make use of the days_in_mon() function.
 
* The leap_year() function will take a year in "YYYY" format, and return True if the given year is a leap year, otherwise return False.
 
* The valid_date() function will take a date in "DD-MM-YYYY" format, and return True if the given date is a valid date, otherwise return False plus an appropriate status message. The valid_date() function should make use of the days_in_mon() function.
 
* The days_in_mon() function will take a year in "YYYY" format, and return a dictionary object which contains the total number of days in each month for the given year. The days_in_mon() function should make use of the leap_year() function.
 
* The usage() function will take no argument and return a string describing the usage of the script.
 
  
=== Sample code for the after() function ===
+
To run the check script, enter the following:
<pre>
 
# Return the date in DD-MM-YYYY after the given day
 
#
 
def after(today):
 
    if len(today) != 10:
 
      return '00-00-0000'
 
    else:
 
      str_day, str_month, str_year = today.split('-')
 
      year = int(str_year)
 
      month = int(str_month)
 
      day = int(str_day)
 
  
      lyear = year % 4
+
<code>python checkA1.py -f -v TestDirDict</code>
      if lyear == 0:
 
          feb_max = 29 # this is a leap year
 
      else:
 
          feb_max = 28 # this is not a leap year
 
  
      lyear = year % 100
+
== Minimum Viable Product ==
      if lyear == 0:
+
Once you have achieved the Milestones, you will have to do the following to get a minimum viable product:
          feb_max = 28 # this is not a leap year
+
* In your <code>if __name__ == '__main__'</code> block, you will have to check command line arguments.
 +
** If the user has entered no command line argument, use the current directory.
 +
** If the user has entered more than one argument, or their argument isn't a valid directory, print an error message.
 +
** Otherwise, the argument will be your target directory.
 +
* Call <code>call_du_sub</code> with the target directory.
 +
* Pass the return value from that function to <code>create_dir_dict</code>
 +
* You may wish to create one or more functions to do the following:
 +
** Use the total size of the target directory to calculate percentage.
 +
** For each subdirectory of target directory, you will need to calculate a percentage, using the total of the target directory.
 +
** Once you've calculated percentage, call <code>percent_to_graph</code> with a max_size of your choice.
 +
** For every subdirectory, print <i>at least</i> the percent, the bar graph, and the name of the subdirectory.
 +
** The target directory <b>should not</b> have a bar graph.
  
      lyear = year % 400
+
== Additional Features ==
      if lyear == 0:
 
          feb_max = 29 # this is a leap year
 
  
      tmp_day = day + 1 # next day
+
After completing the above, you are expected to add some additional features. Some improvements you could make are:
  
      mon_max = { 1:31, 2:feb_max, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
+
* Format the output in a way that is easy to read.
      if tmp_day > mon_max[month]:
+
* Add colour to the output.
          to_day = tmp_day % mon_max[month] # if tmp_day > this month's max, reset to 1
+
* Add more error checking, print a usage message to the user.
          tmp_month = month + 1
+
* Convert bytes to a human-readable format. NOTE: This doesn't have to be 100% accurate to get marks.
      else:
+
* Accept more options from the user.
          to_day = tmp_day
+
* Sort the output by percentage, or by filename.
          tmp_month = month + 0
 
  
      if tmp_month > 12:
+
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).
          to_month = 1
 
          year = year + 1
 
      else:
 
          to_month = tmp_month + 0
 
  
      next_date = str(to_day)+"-"+str(to_month).zfill(2)+"-"+str(year).zfill(2)
+
== The Assignment (due March 7, 11:59pm) ==
   
+
* Be sure to make your final commit before the deadline.
      return next_date
+
* Then, copy the contents of your <b>duim.py</b> file into a Word document, and submit it to Blackboard. <i>I will use GitHub to evaluate your deadline, but submitting to Blackboard tells me that you wish to be evaluated.</i>
</pre>
 
  
 
= Rubric =
 
= Rubric =
Line 158: Line 156:
 
| Program Authorship Declaration || 5 ||
 
| Program Authorship Declaration || 5 ||
 
|-
 
|-
| Check script passed || 30 ||
+
| required functions design || 5 ||
 
|-
 
|-
| today() function design || 2 ||
+
| required functions readability || 5 ||
 
|-
 
|-
| before() function design || 5 ||
+
| main loop design || 10 ||
 
|-
 
|-
| dbda() function design || 10 ||
+
| main loop readability || 10 ||
 
|-
 
|-
| script level docstring || 5 ||
+
| output function design || 5 ||
 
|-
 
|-
| leap_year() function design || 2 ||
+
| output function readability || 5 ||
 
|-
 
|-
| valid_date() function design || 5 ||
+
| additional features implemented || 20 ||
 
|-
 
|-
| usage() function design || 1 ||
+
| docstrings and comments || 5 ||
 
|-
 
|-
| First Milestone ||10||
+
| First Milestone || 10 ||
 
|-
 
|-
| Reflection Essay || 10 ||
+
| Second Milestone || 10 ||
 
|-
 
|-
| github.com repository: Commit messages and use ||15||
+
| github.com repository: Commit messages and use || 10 ||
 
|-
 
|-
 
|'''Total''' || 100 ||  
 
|'''Total''' || 100 ||  
Line 185: Line 183:
  
 
= Due Date and Final Submission requirement =
 
= Due Date and Final Submission requirement =
 
Check with your professor for the due date for your section.
 
  
 
Please submit the following files by the due date:
 
Please submit the following files by the due date:
* [ ] your algorithm document, named as 'algorithm_username.txt', to Blackboard.
+
* [ ] your python script, named as 'duim.py', in your repository, and also '''submitted to Blackboard''', by March 7 at 11:59pm.
* [ ] your python script, named as 'a1_[seneca-id].py', should be included in your repository, and also '''submitted to Blackboard.'''
 
* [ ] the output of the checking script checkA1.py, named as 'a1_output.txt', should be included in your repository.
 
* [ ] your debrief document should be submitted to Blackboard.
 

Latest revision as of 13:43, 19 February 2021

Overview: du Improved

du is a tool for inspecting directories. It will return the contents of a directory along with how much drive space they are using. However, it can be parse its output quickly, as it usually returns file sizes as a number of bytes:

user@host ~ $ du --max-depth 1 /usr/local/lib

164028	/usr/local/lib/heroku
11072	/usr/local/lib/python2.7
92608	/usr/local/lib/node_modules
8	/usr/local/lib/python3.8
267720	/usr/local/lib

You will therefore be creating a tool called duim (du improved>. Your script will call du and return the contents of a specified directory, and generate a bar graph for each subdirectory. The bar graph will represent the drive space as percent of the total drive space for the specified directory. An example of the finished code your script might produce is this:

user@host ~ $ ./duim.py /usr/local/lib

 61 % [============        ] 160.2 MiB	/usr/local/lib/heroku
  4 % [=                   ] 10.8 MiB	/usr/local/lib/python2.7
 34 % [=======             ] 90.4 MiB	/usr/local/lib/node_modules
  0 % [                    ] 8.0 kiB	/usr/local/lib/python3.8
Total: 261.4 MiB 	 /usr/local/lib

The details of the final output will be up to you, but you will be required to fulfill some specific requirements before completing your script. Read on...

Assignment Requirements

Permitted Modules

Your python script is allowed to import only the os, subprocess and sys modules from the standard library.

Required Functions

You will need to complete the functions inside the provided file called duim.py. The provided checkA1.py will be used to test these functions.

  • call_du_sub() should take the target directory as an argument and return a list of strings returned by the command du -d 1<target directory>.
    • Use subprocess.Popen.
    • '-d 1' specifies a max depth of 1. Your list shouldn't include files, just a list of subdirectories in the target directory.
    • Your list should not contain newline characters.
  • percent_to_graph() 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 raise ValueError in this case.
    • total chars refers to the total number of characters that the bar graph will be composed of. You can use equal signs = or any other character that makes sense, but the empty space must be composed of spaces, 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 percent_to_graph(50, 10) should return:
   '=====     '
  • create_dir_dict should take a list as the argument, and should return a dictionary.
    • The list can be the list returned by call_du_sub().
    • The dictionary that you return should have the full directory name as key, and the number of bytes in the directory as the value. This value should be an integer. For example, using the example of /usr/local/lib, the function would return:
   {'/usr/local/lib/heroku': 164028, '/usr/local/lib/python2.7': 11072, ...}

Additional Functions

You may create any other functions that you think appropriate, especially when you begin to build additional functionality. Part of your evaluation will be on how "re-usable" your functions are, and sensible use of arguments and return values.

Use of GitHub

You will be graded partly on the quality of your Github commits. You may make as many commits as you wish, it will have no impact on your grade. The only exception to this is assignments with very few commits. These will receive low marks for GitHub use and may be flagged for possible academic integrity violations. Assignments that do not adhere to these requirements may not be accepted.

Professionals generally follow these guidelines:

  • commit their code after every significant change,
  • the code should hopefully run without errors after each commit, and
  • every commit has a descriptive commit message.

After completing each function, make a commit and push your code.

After fixing a problem, make a commit and push your code.

GitHub is your backup and your proof of work.

These guidelines are not always possible, but you will be expected to follow these guidelines as much as possible. Break your problem into smaller pieces, and work iteratively to solve each small problem. Test your code after each small change you make, and address errors as soon as they arise. It will make your life easier!

Coding Standard

Your python script must follow the following coding guide:

Documentation

  • Please use python's docstring to document your python script (script level documentation) and each of the functions (function level documentation) you created for this assignment. The docstring should describe 'what' the function does, not 'how' it does.
  • Your script should also include in-line comments to explain anything that isn't immediately obvious to a beginner programmer. It is expected that you will be able to explain how each part of your code works in detail.
  • Refer to the docstring for after() to get an idea of the function docstrings required.

Authorship Declaration

All your Python code for this assignment must be placed in the provided Python file called assignment1.py. Do not change the name of this file. Please complete the declaration as part of the docstring in your Python source code file (replace "Student Name" with your own name).

Submission Guidelines and Process

Clone Your Repo (ASAP)

The first step will be to clone the Assignment 1 repository. The invite link will be provided to you by your professor. The repo will contain a check script, a README file, and the file where you will enter your code.

The First Milestone (due February 14)

For the first milestone you will have two functions to complete.

  • call_du_sub will take one argument and return a list. The argument is a target directory. The function will use subprocess.Popen to run the command du -d l <target_directory>.
  • percent_to_graph will take two arguments and return a string.

In order to complete percent_to_graph(), it's helpful to know the equation for converting a number from one scale to another.

Scaling-formula.png

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.

Test your functions with the Python interpreter. Use python3, then:

   import duim
   duim.percent_to_graph(50, 10)

To test with the check script, run the following:

python3 checkA1.py -f -v TestPercent

Second Milestone (due February 21)

For the second milestone you will have one more function to complete.

  • create_dir_dict will take your list from call_du_sub and return a dictionary.
    • Every item in your list should create a key in your dictionary.
    • Your dictionary values should be a number of bytes.

For example: {'/usr/lib/local': 33400}

    • Again, test using your Python interpreter or the check script.

To run the check script, enter the following:

python checkA1.py -f -v TestDirDict

Minimum Viable Product

Once you have achieved the Milestones, you will have to do the following to get a minimum viable product:

  • In your if __name__ == '__main__' block, you will have to check command line arguments.
    • If the user has entered no command line argument, use the current directory.
    • If the user has entered more than one argument, or their argument isn't a valid directory, print an error message.
    • Otherwise, the argument will be your target directory.
  • Call call_du_sub with the target directory.
  • Pass the return value from that function to create_dir_dict
  • You may wish to create one or more functions to do the following:
    • Use the total size of the target directory to calculate percentage.
    • For each subdirectory of target directory, you will need to calculate a percentage, using the total of the target directory.
    • Once you've calculated percentage, call percent_to_graph with a max_size of your choice.
    • For every subdirectory, print at least the percent, the bar graph, and the name of the subdirectory.
    • The target directory should not have a bar graph.

Additional Features

After completing the above, you are expected to add some additional features. Some improvements you could make are:

  • Format the output in a way that is easy to read.
  • Add colour to the output.
  • Add more error checking, print a usage message to the user.
  • Convert bytes to a human-readable format. NOTE: This doesn't have to be 100% accurate to get marks.
  • Accept more options from the user.
  • Sort the output by percentage, or by filename.

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 March 7, 11:59pm)

  • Be sure to make your final commit before the deadline.
  • Then, copy the contents of your duim.py file into a Word document, and submit it to Blackboard. I will use GitHub to evaluate your deadline, but submitting to Blackboard tells me that you wish to be evaluated.

Rubric

Task Maximum mark Actual mark
Program Authorship Declaration 5
required functions design 5
required functions readability 5
main loop design 10
main loop readability 10
output function design 5
output function readability 5
additional features implemented 20
docstrings and comments 5
First Milestone 10
Second Milestone 10
github.com repository: Commit messages and use 10
Total 100

Due Date and Final Submission requirement

Please submit the following files by the due date:

  • [ ] your python script, named as 'duim.py', in your repository, and also submitted to Blackboard, by March 7 at 11:59pm.