Open main menu

CDOT Wiki β

Changes

OPS445 Online Lab1

2,177 bytes added, 20:33, 2 May 2023
Option 1: Create a Linux Virtual Machine
= Unit Feedback Script : CheckLabX.py =
<blockquote style="margin-left:35px;">{{Admon/important|style="padding-left:25px"|Unit Feedback Scripts|Each '''Part''' (within an 'Investigation) is referred to as a '''Unit'''. Each Unit will require that the student download and run a '''Unit Feedback Script''', which provides the OPS435 OPS445 student "real-time feedback" of their completed work.<br>This feedback is not considered to be perfect or fool-proof; however, it may provide feedback (hints) in case a student gets stuck or experiences an error when performing administration tasks or when creating their Python scripts. These unit feedback scripts can also be used to confirm that the student's Python script is on the right track, and provide a consistent record of their Python scripting progress throughout their labs.}}</blockquote>
= Investigation 1 - Set Up A Development Environment =
== Task 1: Create a Linux Virtual Machine ==
In order to proceed in the course you're going to need a Linux-based development environment. The requirements for this development environment are:
:* it has a text editor with modern development tools installed. (syntax highlighting, linting, etc.)
You have options in how you set this up. If the computer you will be using for this course is powerful and has at least 16 GB of RAM, you will probably want to set up a Virtual Machine. == Option 1: Create a Linux Virtual Machine == We will demonstrate the steps for setting up a Fedora Virtual Machine with Visual Studio Code installed. A [https://youtu.be/Zxt2BKq-vIw short video] is available to walk you through the process.
:* Install Virtual Machine Software such as VMWare Workstation.
:* Download the Fedora Workstation ISO file from [https://download.fedoraproject.org/pub/fedora/linux/releases/34/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-34-1.2.iso The Fedora Website].
:* Enter your name, and a password. Don't forget this password, as you will need it to become root.
== Task 2: = Verify Python ===
Fedora should have the required software (with the exception of VS Code) already installed. We will verify this before moving on.
:* Run '''sudo dnf update''' to update the system software.
== Task 3: = Install Visual Studio Code and Extensions ===
Visual Studio Code has an excellent Debugger for Python, and so it is the recommended editor for this course. However, you may use a different editor at your discretion. Pycharm Community also has a very good debugger, works on Fedora, and is free for students.
:* Launch Visual Studio Code. Click 'Activities' and type 'code', you should see the launcher for Visual Studio Code appear.
:* Now install the Python extension. Press Control+Shift+x to open Extensions in the sidebar. (Or click on the Extensions icon on left side of the window).
:* Type 'Python' into the search bar, and click 'Install' when you find the extension created by Microsoft. You may wish to explore other extensions to customize your workspace. == Option 2: Use WSL == If your computer has less than 16 GB of RAM and has problems running a full virtual machine, you may choose to use Windows Subsystem for Linux (WSL) instead. This will provide a minimal Linux environment. A [https://youtu.be/FXLrigSSlXI short video] is available to view.:* Open "Windows Store".:* Search for "Ubuntu" and install the app that is published by Canonical.:* Launch Ubuntu from the Start Menu. You will have a terminal-based Linux interface only. To access your Windows files, type <code>cd /mnt/c</code>. This will get you to the top of your Windows C drive.
=== Verify Python on Ubuntu === Ubuntu should have the required software (with the exception of VS Code) already installed. We will verify this before moving on.:* Enter the command '''python3 --version''' and verify that the installed version is at least '''python 3.4'''. If no version of Python is installed, run '''sudo apt install python3'''.:* Enter the command '''git --version''' and verify that the installed version is at least '''git 1.2'''. If no version of Python is installed, run '''sudo apt install git'''.:* Run '''sudo apt update && sudo apt upgrade''' to update the system software.  === Verify Python on Windows ===:* Open your Windows command prompt and type '''python --version'''. If no version of Python is installed, it should give you instructions in how to install it, or go to [https://www.python.org/downloads/ the Python Homepage]. === Install VS Code ===:* Follow the instructions to [https://code.visualstudio.com/download install VS Code on Windows]. Now you will be able to complete most tasks on Windows, and switch to a minimal Linux environment when needed. == Task 4: Verify The Python Interpreter ==
'''A few background information about the Python programming language
* The Python Interpreter understanding the Python language and this is why we are going to learn this programming language in this course.
* To exit from the interactive Python shell, press Ctrl+d.
== Task 5 - : Create directory structure for Labs and Assignments ==
=== Create directory structure using BASH commands===
:* Lets setup and reserve the following directories for storing and organizing files for labs and assignments. Execute the following commands at the command prompt:
<pre>
mkdir ~/ops445
mkdir ~/ops445/lab1
mkdir ~/ops445/lab2
mkdir ~/ops445/lab3
mkdir ~/ops445/lab7
mkdir ~/ops445/lab8
mkdir ~/ops445/lab9
mkdir ~/ops445/a1
mkdir ~/ops445/a2
Matrix can not provide a graphical user interface, but it is a useful alterntative for Python development and testing. We will recommend that you use Matrix for '''Lab 8 and 9''', once you have become familiar with the fundamentals on your virtual machine.
 
If you connect to the VPN using your host Windows machine, you should be able to connect using your Linux virtual machine as well. If you are running natively, you should talk to your instructor for other options.
== Part I - Python Versions on Matrix ==
:* You can access the Python Interpreter on Matrix from a Linux machine or a Windows 10 machine.
=== Login to matrix.senecacollege.ca from a Linux machine ===
:<font color='red'>The latest version of the openconnect client is need to connect to the Seneca VPN. We are working on the instructions on how to do that. In the mean time, please use the Windows 10 as described below to connect to matrix.</font>
:* To login to matrix.senecacollege.ca you must have a active Seneca user account.
:* The following is a screen shot showing the login from a CentOS Linux (host or vm) system with an active Seneca user name: <br /><br />[[image:centos_ssh.png|Ssh to matrix from Linux]]
:* Compare the list of keywords and symbols for Python version 2 and version 3. Which keyword(s) is/are remove from version 2 in version 3?
= Investigation 3 = Part II - git and github.com ===== Task 1: Create a Github.com account ===
:* Start your web browser and go to github.com and use your own email to sign up for a new github account if you don't already have one. <br /><b>[Note: Please be aware that Seneca's spam filter block email from github.com by default, if you use your Seneca email to sign up for an account on github.com, you might have to re-configure your email spam filter to allow confirmation email from github.com to reach your inbox.]</b>
=== Task 2: Add your public key to Github ===:Follow the Github guide [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account here] to add your public key to your profile::* Add one public key for each computer/VM you will be using for the course. :* Run <code>ls -la ~/.ssh</code> and look for a public key file such as <b>id_rsa.pub</b>. If no file exists, generate a new keypair using <code>ssh-keygen</code>.:* Use <code>cat <public key filename></code> to display the contents of the public key, and then select and copy the text.:* Open Github in your web browser. Log in, select <b>Settings</b> -> <b>SSH and GPG Keys</b>. Create new key, and paste your public key contents into the text box.:You will now have permission to clone repositories using <b>SSH</b>. === Task 3: Create a project and make a pull request on GitHub ===
:Follow the Github "Hello World Guide" [https://guides.github.com/activities/hello-world/ here] to perform the following activities:
:* Create a repository
: Please make the following <font color='red'>changes</font> when following the guide:
:* name the new repository using your <b><u>Seneca user name</u></b> instead of "hello-world".
:* add your full name, and OPS435 OPS445 section to the README file, do not post any other personal information there. == Task 3: Clone a Github.com repository into a new directory on a Linux system ==: You can do the following steps either on matrix.senecacollege.ca or on your CentOS 7 vm::* login to matrix.senecacollege.ca or your CentOS 7 vm:* create a directory named ops445/lab1 under your home directory:* change your working directory to ~/ops445/lab1:* run the following git command to clone the repository you created in Task 2 on github.com<pre> git clone https://github.com/[your_github_user_name]/[your_seneca_user_name]</pre>:for example, if your github user name is <b>rc2030</b>, and your seneca user name is <b>rchan</b>, the git command to clone the repository you created in Task 2 should be:<pre> git clone https://github.com/rc2030/rchan</pre>:* change your working directory to your cloned git repository, which should be ~/ops445/lab1/[your_seneca_user_name]:* run the following two commands and capture their output to the named files:<pre> git log > ~/ops445/lab1/gitlog.txt</pre> <pre> tree -a > ~/ops445/lab1/repo_tree.txt</pre>:* Make sure that gitlog.txt and repo_tree.txt are not empty and are under the ~/ops445/lab1 directory. Review and study the contents of gitlog.txt and repo_tree.txt :*Download the check script and check your work. Enter the following commands from the bash shell.<source lang="bash"> cd ~/ops445/lab1/ pwd #confirm that you are in the right directory ls -l lab1a.py #confirm that you have the directory for you github repo, the files gitlog.txt and repo_tree.txt ls CheckLab1.py || wget https://ict.senecacollege.ca/~raymond.chan/ops445/labs/LabCheckScripts/CheckLab1.py python3 ./CheckLab1.py -f -v lab0a</source> 
=== Task 4: Clone a Github.com repository into a new directory on a Linux system ===
If your professor is asking you to submit labs on GitHub, follow their instructions now to clone the lab1 repository.
Otherwise, download the sample.py script from https://github.com/ahadalioglu/ops445-lab1 repository to ~/ops445/lab1 directory
=== Verify the directory structure created ===
:* Download the sample.py script from https://github.com/rayfreeping/ops435-lab1 repository to ~/ops445/lab1 directory
:* Study and Explore the sample.py python script and identify the following sections:
:** the shebang line
:** the script level doctstringdocstring
:** the import section to import functions from the standard library module
:** the function definition section
:* Also identify the following items appear in the sample.py script:
:** the Python keywords
:** the decision code segementsegment
:** the looping code segment
:** the run time error (exception) handling code segment
:** <source>python3 sample.py 2>/dev/null</source>
:** <source>python3 sample.py test 2>/dev/null </source>
:*Download the check script and check your work. Enter the following commands from the bash shell.<source lang="bash">
cd ~/ops445/lab1/
pwd #confirm that you are in the right directory
ls -l ~/ops435/ #confirm that you have create the directory structure under ~/ops445
ls CheckLab1.py || wget https://ict.senecacollege.ca/~raymond.chan/ops445/labs/LabCheckScripts/CheckLab1.py
python3 ./CheckLab1.py -f -v lab0b
</source>
= Investigation 3 - exploring and using Python's built-in functions =
== Part I - Interactive (leaninglearning) mode: using the Python Interactive Shell ==
:* In this mode, you can instruct the Python Interpreter to execute python statement or python expression one at a time, call a function, or display the representation of a python data object.
:* To start the Python version 3 Interactive shell, type the command <source>[raymonderic.chanbrauer@mtrx-node05pd lab1]$ python3</source> at the Linux command prompt.
:* You should get a startup message similar to the following:<source>
[raymonderic.chanbrauer@mtrx-node05pd lab1]$ python3
Python 3.6.8 (default, Apr 2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linuxLinux
Type "help", "copyright", "credits" or "license" for more information.
>>>
print('Hello world')
</source>
<li style="margin-left:25px;">Another way of running a Python program is executing it directly, e.g.: <source>./lab1a.py</source>Note that the file will need execute permissions even though you ran it just fine earlier. Why is that? <li style/ol> =====Submitting Your Lab Work Through GitHub=="margin-left:25px;">Download the check script and check ===If you cloned your work. Enter lab through GitHub, perform the following commands from the bash shell.now:<source lang="bash">
cd ~/ops445/lab1/
pwd #confirm that you are in the right directory
ls lab1a.py #confirm that you have the lab1a.py script in your directory
ls CheckLab1.py || wget https://ict.senecacollege.ca/~raymond.chan/ops445/labs/LabCheckScripts/CheckLab1.py
python3 ./CheckLab1.py -f -v lab1a
</source>
Before moving on to the next step make sure you identify any and all errors in "lab1a.py". When the check script tells you everything is "ok", you may commit your changes.<li stylesource lang="marginbash"> git add lab1a.py git commit -leftm "Added lab1a" git push</source>Your first script is now submitted. The process for each part of the lab will be similar. =====Submitting Your Lab Work Through Blackboard=====If you did not clone your lab through GitHub, you may download the check script by following these steps:25px;Download the check script and check your work. Enter the following commands from the bash shell.<source lang="bash"> cd ~/ops445/lab1/ pwd #confirm that you are in the right directory ls lab1a.py #confirm that you have the lab1a.py script in your directory ls CheckLab1.py || wget 'https://github.com/senecaops445/lab1-template/blob/master/CheckLab1.py?raw=true' -O CheckLab1.py python3 ./CheckLab1.py -f -v lab1a</source>Before moving on to the next step make sure you identify any and all errors in "lab1a.py". When the check script tells you everything is "ok", you may proceed to the next step.</ol>
= Investigation 4 - exploring Python's built-in Data Objects =
cd ~/ops445/lab1/
pwd #confirm that you are in the right directory
ls CheckLab1.py || wget 'https://ictgithub.senecacollege.cacom/~raymond.chansenecaops445/ops435lab1-template/labsblob/CheckScriptsmaster/CheckLab1.py?raw=true' -O CheckLab1.py
python3 ./CheckLab1.py -f -v lab1b
</source></li>
<li style="margin-left:25px;"> Before proceeding, make certain that you identify any and all errors in "lab1b.py". When the check script tells you everything is "ok", you may proceed to the next step.</li><li style="margin-lef:25px;"> If using GitHub, repeat the steps to commit your lab1b.py file.</ol>
== Integer Objects==
cd ~/ops445/lab1/
pwd #confirm that you are in the right directory
ls CheckLab1.py || wget 'https://ictgithub.senecacollege.cacom/~raymond.chansenecaops445/ops435lab1-template/labsblob/LabCheckScriptsmaster/CheckLab1.py?raw=true' -O CheckLab1.py
python3 ./CheckLab1.py -f -v lab1c
</source></li>
<li style="margin-left:25px;">Before moving on to the next step make sure you identify any and all errors in "lab1c.py". When the check script tells you everything is "ok", you may proceed to the next step. Add lab1c.py to the repo and commit the change.</li>
</ol>
cd ~/ops445/lab1/
pwd #confirm that you are in the right directory
ls CheckLab1.py || wget 'https://ictgithub.senecacollege.cacom/senecaops445/~raymond.chanlab1-template/ops435blob/master/LabCheckScripts/CheckLab1.py?raw=true' -O CheckLab1.py
python3 ./CheckLab1.py -f -v lab1d
</source>Before moving on to the next step make sure you identify any and all errors in "lab1d.py".<br><br></li>
<li style="margin-left:25px;">When the check script tells you everything is "ok", you may proceed to the next step. Add your file to the repo, and make a commit.<br><br></li>
</ol>
=LAB 1 SIGN-OFF = Again, you will be asked to submit the lab in one of two ways: ==Upload the following files individually to Blackboard==
:'''Run the CheckLab1.py script and capture the result'''
<source>python3 ./CheckLab1.py -f -v &> lab1_[seneca_id]lab1_yoursenecaid.txt</source>
: Submit the following files individually to Blackboard:
::<span style="color:green;font-size:1.5em;">&#x2713;</span> <code>lab1_[seneca_id]lab1_yoursenecaid.txt</code>::<span style="color:green;font-size:1.5em;">&#x2713;</span> <code>gitlog.txt, repo_tree.txt, lab1a.py, lab1b.py , lab1c.py, lab1d.py</code> ==Complete the GitHub Submission==:'''Run the CheckLab1.py script and capture the result'''<source>python3 ./CheckLab1.py -f -v &> lab1_yoursenecaid.txtgit add lab1_yoursenecaid.txtgit commit -m "completed lab"git push</source>
= Lab Review =
:# How do you execute a Python script when you are within the interactive <u>python3</u> shell? (Hint: make use of a function provided by the os python module.)
:# How do you execute a Python script when you are in the <u>Bash</u> Shell (i.e. NOT within the python3 shell)?
:# Write the pipeline command to check if the CheckLab1.py checking script exists, and download it from the location:<br>https://ict.senecacollege.ca/~raymonderic.chanbrauer/ops445/labs/LabCheckScripts/CheckLab1.py