Changes

Jump to: navigation, search

OPS245 Lab 3

2,782 bytes added, 18:11, 22 January 2021
m
Addign a python investigation
'''Answer the Investigation 3 observations / questions in your lab log book.'''
 
=INVESTIGATION 4: USING LOGICAL STRUCTURES IN PYTHON=
Now that we have added some powerful logical structures to our python scripts, we can make our scripts much more adaptable. Just like we have done in bash, our python scripts can now responde to different situations by executing different code, or repeating the same code several times (e.g. keep asking the user for input until they give us something useful). In this investigation you will write a python script that will prompt a user for a directory to archive, ask them if they want the archive compressed, and (only if they do want compression) what type of compression to apply.
 
<ol>
<li>In your bin directory, create the file tarchiver.py, and populate with our standard beginning:
<code style="color:#3366CC;font-family:courier;font-size:.9em;">
<br>
&#35;!/usr/bin/env python3<br />
 
 
&#35; tarchiver.py<br />
&#35; Purpose: Creates a tar archive of a directory<br />
&#35;<br />
&#35; USAGE: ./tarchiver.py<br />
&#35;<br />
&#35; Author: *** INSERT YOUR NAME ***<br />
&#35; Date: *** CURRENT DATE ***<br />
import os<br />
</code>
</li>
<li>Next, add prompts using the '''input()''' function to ask the user for:
<ul>
<li>The directory they wish to archive.</li>
<li>The name they want to give the archive.</li>
</ul>
Remember to store their responses in variables.</li>
<li>Add a line that uses the values provided by the user to execute a tar command and create and archive of the directory they requested.</li>
<li>Test your script to make sure it works.</li>
<li>Add a third prompt (immediately after the other two prompts and before the tar command), asking the user if they want the archive to be compressed. You'll need an if statement to run your tar command with gzip compression if they answered yes.</li>
<li>Test your script to make sure it works.</li>
<li>Add a fourth prompt asking the user what type of compression they want (present them with gzip, bzip, and xz as options). Note that this prompt should only be shown if the user opted for compression (if they don't want compression, there is no point asking what type they don't want).</li>
<li>Expand the if statement around your actual tar command to use whichever type of compression the user asked for.</li>
<li>Test your script to make sure it works.</li>
<li>Test your script again, but feed it nonsense data (e.g. answer 'very much so' instead of 'y' or 'n' when prompted about compression).</li>
<li>Add loops around your prompts to make the script repeat each prompt until the user gives a response your script can actually use.</li>
<li>Now test your script again, with good data and with nonsense.</li>
<li>When you are confident your script works, you are ready to submit the lab.</li>
</ol>
 
= LAB 3 SIGN-OFF (SHOW INSTRUCTOR) =
# Run the shell script and if any warnings, make fixes and re-run shell script until you receive "congratulations" message.
#Arrange proof of the following on the screen:<br><span style="color:green;font-size:1.5em;">&#x2713;</span> '''centos3''' VM:<blockquote><ul><li> Archived files '''created'''</li><li>Archive files '''restored'''</ul></blockquote><span style="color:green;font-size:1.5em;">&#x2713;</span> '''c7host''' Machine:<blockquote><ul><li> '''One repository added''' for yum</li><li>Run the '''lab3-check.bash''' script (must have all <b><code><span style="color:#66cc00;border:thin solid black;font-size:1.2em;">&nbsp;OK&nbsp;</span></code></b> messages)</li></ul></blockquote><span style="color:green;font-size:1.5em;">&#x2713;</span> '''Lab3''' log-book filled out.
#Upload a screen of the proof from the previous step, along with the file generated by '''lab3-check.bash''' , and your tarchiver.py script to blackboard.
= Practice For Quizzes, Tests, Midterm &amp; Final Exam =
932
edits

Navigation menu