Jump to: navigation, search

OPS435 Assignment 2 for Section C

1,227 bytes removed, 24 March
Assignment 2 - Usage Report
=Assignment 2 - Usage Report=
'''Weight:''' 1015% of the overall grade
'''Due Date:''' Please follow the three stages of submission schedule:
* Complete the algorithm document requirements for this assignment script the first milestone and push to GitHub by November 27April 4, 2020 and submit on Blackboard 2021 by 11:59 PM,* Complete the your Python script and push to Github GitHub by December 11April 18, 2020 2021 at 11:59 PM, and* Copy your Python script into a Word document and submit to Blackboard by December 11April 18, 2020 2021 at 11:59 PM.
== Tasks for this assignment ==
In this assignment, your should preform the following activities:
# Complete a detail algorithm for producing monthly usage reports by user or by remote host based on the information stored in any given files generated from the 'last' command. # Once you have complete the detail algorithm, you should then <b>design the structure of your python script</b> by identifying the appropriate python objects, functions and modules to be used for each task in your algorithm and the main control logic. Make sure to identify the followings:## input data, ## computation tasks, and ## outputs.# implement your computational solution using a single python script. You can use any built-in functions and functions from the python modules list in the "Allowed Python Modules" section below to implement your solution. # Test and review your working python code to see whether you can improve the interface of each function to facilitate better code re-use (this process is called <b>refactoring</b>).
== Allowed Python Modules ==
* the <b>os, sys</b> modules
* the <b>argparse</b> module
* The <b>timedatetime</b> module
* The <b>subprocess</b> module
** [ Argparse Tutorial] - should read this first.
== Instructions ==
Accept the Assignment #2 via the link on Blackboard, and clone the Github repository on a Linux machine of your choosing. Rename Your code should only be located in the file "" to "a2_<your myseneca username>.py, just as we did in Assignment 1. You may also want to create a symbolic link using <code>ln -s a2_<myseneca_id>.py</code> to save time.
=== Program Name and valid command line arguments ===
Name your Python3 script as <code>a2_[student_id].py</code>. Your script must accept one or more "file name" as its command line parameters and other optional parameters as shown below. Your python script should produce the following usage text when run with the --help option:
[eric@centos7 a1]$ python3 ./ -h
usage: [-h] [-l {user,host}] [-r RHOST] [-t {daily,monthly}]
[-u USER] [-s] [-v]
-v, --verbose turn on output verbosity
Copyright 2020 2021 - Eric Brauer
Compare the usage output you have now with the one above. There is one option missing, you will need to change the <code>argparse</code> function to implement it.
You will that there is an 'args' object in Once the <code>parse_command_args()</code> function is called, it will return an args object. The command line arguments will be stored as attributes of that object. <b>Do not use sys.argv to parse arguments.</b>
If there is only one file name provided at the command line, read the login/logout records from the contents of the given file. If the file name is "online", get the record on the system your script is being execute using the Linux command "last -iwF". The format of each line in the file should be the same as the output of 'last -Fiw'. Filter out incomplete login/logout record (hints: check for the number of fields in each record).
All your Python codes for this assignment must be placed in a <font color='red'><b><u>single source file</u></b></font>. Please include the following declaration by <b><u>you</u></b> as the <font color='blue'><b>script level docstring</b></font> in your Python source code file (replace [Student_id] with your Seneca email user name, and "Student Name" with your own name):
<source>OPS435 Assignment 2 - Fall 2020Winter 2021
Author: "Student Name"
<li> Read the rest of this document, try and understand what is expected.
<li> Use the invite link posted to Blackboard to accept the assignment, and clone the repo to a Linux machine.
<li> Copy into a2_<myseneca_id>.py. Replace with your Myseneca username.
<li> Run the script itself. Investigate argparse. <b>In the main block, print(args).</b> Experiment with the various options.
<li> Read the usage output in the docs, what option must you implement? Go ahead and implement it. <b>Commit the change.</b>

Navigation menu