update module3.ipynb
This commit is contained in:
parent
a40cbfc5fb
commit
f5dc54d19f
362
module3.ipynb
362
module3.ipynb
@ -1696,7 +1696,367 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Another Rebasing Example\n",
|
"# Another Rebasing Example\n",
|
||||||
"\n"
|
"\n",
|
||||||
|
"This reading contains the code used in the instructional videos from [**Another rebasing example**<svg aria-labelledby=\"cds-react-aria3604314262-:r6r8:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r6r8:\"><title id=\"cds-react-aria3604314262-:r6r8:-title\">Opens in a new tab</title></svg>](https://www.coursera.org/learn/introduction-git-github/lecture/jipZ8/another-rebasing-example)\n",
|
||||||
|
"\n",
|
||||||
|
"## Introduction\n",
|
||||||
|
"\n",
|
||||||
|
"This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n",
|
||||||
|
"\n",
|
||||||
|
"You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"atom all\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"\n",
|
||||||
|
"import socket\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"\n",
|
||||||
|
"def check\\_root\\_full():\n",
|
||||||
|
"\n",
|
||||||
|
" \"\"\"Returns True if the root partition is full, False otherwise.\"\"\"\n",
|
||||||
|
"\n",
|
||||||
|
" return check\\_disk\\_full(disk=\"/\", min\\_gb=2, min\\_percent=10)\n",
|
||||||
|
"\n",
|
||||||
|
"def check\\_no\\_network():\n",
|
||||||
|
"\n",
|
||||||
|
" \"\"\"Returns True if it fails to resolve Google's URL, False otherwise.\"\"\" \n",
|
||||||
|
"\n",
|
||||||
|
" try:\n",
|
||||||
|
"\n",
|
||||||
|
" socket.gethostbyname(\"www.google.com\")\n",
|
||||||
|
"\n",
|
||||||
|
" return False\n",
|
||||||
|
"\n",
|
||||||
|
" except:\n",
|
||||||
|
"\n",
|
||||||
|
" return True\n",
|
||||||
|
"\n",
|
||||||
|
"def main():\n",
|
||||||
|
"\n",
|
||||||
|
" checks = \\[\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_reboot, \"Pending Reboot.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_root\\_full, \"Root partition full\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_no\\_network, \"No working network.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" \\]\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"git commit \\-a \\-m 'Add a simple network connectivity check'\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"\\[master aa8da6f\\] Add a simple network connectivity check\n",
|
||||||
|
"\n",
|
||||||
|
" 1 file changed, 10 insertions(+), 1 deletion(-)\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"git fetch\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"remote: Enumerating objects: 6, done.\n",
|
||||||
|
"\n",
|
||||||
|
"remote: Counting objects: 100% (6/6), done.\n",
|
||||||
|
"\n",
|
||||||
|
"remote: Compressing objects: 100% (4/4), done.\n",
|
||||||
|
"\n",
|
||||||
|
"remote: Total 5 (delta 1), reused 5 (delta 1), pack-reused 0\n",
|
||||||
|
"\n",
|
||||||
|
"Unpacking objects: 100% (5/5), done.\n",
|
||||||
|
"\n",
|
||||||
|
"From https://github.com/redquinoa/health-checks\n",
|
||||||
|
"\n",
|
||||||
|
" f5813b1...d8c8fcd master -> origin/master \n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"git rebase origin/master\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"First, rewinding head to replay your work on top of it...\n",
|
||||||
|
"\n",
|
||||||
|
"Applying: Add a simple network connectivity check\n",
|
||||||
|
"\n",
|
||||||
|
"Using index info to reconstruct a base tree...\n",
|
||||||
|
"\n",
|
||||||
|
"A all\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"Falling back to patching base and 3-way merge...\n",
|
||||||
|
"\n",
|
||||||
|
"Auto-merging health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"CONFLICT (content): Merge conflict in health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"error: Failed to merge in the changes.\n",
|
||||||
|
"\n",
|
||||||
|
"Patch failed at 0001 Add a simple network connectivity check\n",
|
||||||
|
"\n",
|
||||||
|
"hint: Use 'git am --show-current-patch' to see the failed patch\n",
|
||||||
|
"\n",
|
||||||
|
"Resolve all conflicts manually, mark them as resolved with\n",
|
||||||
|
"\n",
|
||||||
|
"\"git add/rm <conflicted\\_files>\", then run \"git rebase --continue\".\n",
|
||||||
|
"\n",
|
||||||
|
"You can instead skip this commit: run \"git rebase --skip\".\n",
|
||||||
|
"\n",
|
||||||
|
"To abort and get back to the state before \"git rebase\", run \"git rebase --abort\".\n",
|
||||||
|
"\n",
|
||||||
|
"1\n",
|
||||||
|
"```bash\n",
|
||||||
|
"atom health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"\n",
|
||||||
|
"<<<<<<< HEAD:health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"def check\\_cpu\\_constrained():\n",
|
||||||
|
"\n",
|
||||||
|
" \"\"\"Returns True if the cpu is having too much usage, False otherwise.\"\"\"\n",
|
||||||
|
"\n",
|
||||||
|
" return psutil.cpu\\_percent(1) > 75\n",
|
||||||
|
"\n",
|
||||||
|
"def main():\n",
|
||||||
|
"\n",
|
||||||
|
" checks = \\[\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_reboot, \"Pending Reboot.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_root\\_full, \"Root partition full\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_cpu\\_constrained, \"CPU load too high.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" \\]\n",
|
||||||
|
"\n",
|
||||||
|
" everything\\_ok = True\n",
|
||||||
|
"\n",
|
||||||
|
"\\=======\n",
|
||||||
|
"\n",
|
||||||
|
"def check\\_no\\_network():\n",
|
||||||
|
"\n",
|
||||||
|
" \"\"\"Returns True if it fails to resolve Google's URL, False otherwise.\"\"\"\n",
|
||||||
|
"\n",
|
||||||
|
" try:\n",
|
||||||
|
"\n",
|
||||||
|
" socket.gethostbyname(\"google.com\")\n",
|
||||||
|
"\n",
|
||||||
|
" return False\n",
|
||||||
|
"\n",
|
||||||
|
" except:\n",
|
||||||
|
"\n",
|
||||||
|
" return True\n",
|
||||||
|
"\n",
|
||||||
|
"\\>>>>>>> Add a simple network connectivity check:all\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"def main():\n",
|
||||||
|
"\n",
|
||||||
|
" checks = \\[\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_reboot, \"Pending Reboot.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_root\\_full, \"Root partition full\"),\n",
|
||||||
|
"\n",
|
||||||
|
"<<<<<<< HEAD:health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_cpu\\_constrained, \"CPU load too high.\"),\n",
|
||||||
|
"\n",
|
||||||
|
"\\=======\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_no\\_network, \"No working network.\"),\n",
|
||||||
|
"\n",
|
||||||
|
"\\>>>>>>> Add a simple network connectivity check:all\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
" \\]\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"(...)\n",
|
||||||
|
"\n",
|
||||||
|
"def check\\_cpu\\_constrained():\n",
|
||||||
|
"\n",
|
||||||
|
" \"\"\"Returns True if the cpu is having too much usage, False otherwise.\"\"\"\n",
|
||||||
|
"\n",
|
||||||
|
" return psutil.cpu\\_percent(1) > 75\n",
|
||||||
|
"\n",
|
||||||
|
"def main():\n",
|
||||||
|
"\n",
|
||||||
|
" checks = \\[\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_reboot, \"Pending Reboot.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_root\\_full, \"Root partition full\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_cpu\\_constrained, \"CPU load too high.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" \\]\n",
|
||||||
|
"\n",
|
||||||
|
" everything\\_ok = True\n",
|
||||||
|
"\n",
|
||||||
|
"def check\\_no\\_network():\n",
|
||||||
|
"\n",
|
||||||
|
" \"\"\"Returns True if it fails to resolve Google's URL, False otherwise.\"\"\"\n",
|
||||||
|
"\n",
|
||||||
|
" try:\n",
|
||||||
|
"\n",
|
||||||
|
" socket.gethostbyname(\"google.com\")\n",
|
||||||
|
"\n",
|
||||||
|
" return False\n",
|
||||||
|
"\n",
|
||||||
|
" except:\n",
|
||||||
|
"\n",
|
||||||
|
" return True\n",
|
||||||
|
"\n",
|
||||||
|
"def main():\n",
|
||||||
|
"\n",
|
||||||
|
" checks = \\[\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_reboot, \"Pending Reboot.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_root\\_full, \"Root partition full\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_cpu\\_constrained, \"CPU load too high.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" (check\\_no\\_network, \"No working network.\"),\n",
|
||||||
|
"\n",
|
||||||
|
" \\]\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"./health\\_checks.py \n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"Traceback (most recent call last: \n",
|
||||||
|
"\n",
|
||||||
|
" File \".health\\_checks.py\", line 61, in <module>\n",
|
||||||
|
"\n",
|
||||||
|
" main()\n",
|
||||||
|
"\n",
|
||||||
|
" File \".health\\_checks.py\", line 49, in main\n",
|
||||||
|
"\n",
|
||||||
|
" If check():\n",
|
||||||
|
"\n",
|
||||||
|
" File \".health\\_checks.py\", line 30, in check\\_cpu\\_constrained\n",
|
||||||
|
"\n",
|
||||||
|
" Return psutil.cpu\\_percent(1) >75\n",
|
||||||
|
"\n",
|
||||||
|
"NameError: name ‘psutil’ is not defined\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"atom health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"import os\n",
|
||||||
|
"\n",
|
||||||
|
"import shutil\n",
|
||||||
|
"\n",
|
||||||
|
"import sys\n",
|
||||||
|
"\n",
|
||||||
|
"import socket\n",
|
||||||
|
"\n",
|
||||||
|
"import psutil\n",
|
||||||
|
"\n",
|
||||||
|
"(...)\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"./health\\_checks.py \n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"Everything ok.\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"git add health\\_checks.py \n",
|
||||||
|
"\n",
|
||||||
|
"git rebase \\--continue\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"Applying: Add a simple network connectivity check\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"git log \\--graph \\--oneline\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 160b5f3 (HEAD -> master) Add a simple network connectivity check\n",
|
||||||
|
"\n",
|
||||||
|
"\\* b52b7a2 (origin/master, origin/HEAD) Add cpu\\_constrained check\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 9fc7275 Rename all\\_checks.py to health\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"\\* f5813b1 Allow printing more than one error message\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 18257a0 Iterate over a list of checks and messages to avoid code duplication\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 5d2e3eb Create wrapper function for check\\_disk\\_full\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 0789f64 Add reference to all\\_checks.py to README \n",
|
||||||
|
"\n",
|
||||||
|
"\\* 58351ff Merge branch 'master' of https://github.com/redquinoa/health-checks\n",
|
||||||
|
"\n",
|
||||||
|
"|\\\\ \n",
|
||||||
|
"\n",
|
||||||
|
"| \\* a2dc118 Reorder conditional to match parameter order\n",
|
||||||
|
"\n",
|
||||||
|
"\\* | 03d23d0 Rename min\\_absolute to min\\_gb, use parameter names\n",
|
||||||
|
"\n",
|
||||||
|
"|/ \n",
|
||||||
|
"\n",
|
||||||
|
"\\* 922d659 Add disk full check to all\\_checks.py\n",
|
||||||
|
"\n",
|
||||||
|
"\\* b62dc2e Add initial files for the checks\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 807cb50 Add one more line to README.md\n",
|
||||||
|
"\n",
|
||||||
|
"\\* 3d9f86c Initial commit\n",
|
||||||
|
"\n",
|
||||||
|
"```bash\n",
|
||||||
|
"git push\n",
|
||||||
|
"```\n",
|
||||||
|
"\n",
|
||||||
|
"**Code output:**\n",
|
||||||
|
"\n",
|
||||||
|
"Username for 'https://github.com': redquinoa\n",
|
||||||
|
"\n",
|
||||||
|
"Password for 'https://redquinoa@github.com': \n",
|
||||||
|
"\n",
|
||||||
|
"Enumerating objects: 5, done.\n",
|
||||||
|
"\n",
|
||||||
|
"Counting objects: 100% (5/5), done.\n",
|
||||||
|
"\n",
|
||||||
|
"Delta compression using up to 4 threads\n",
|
||||||
|
"\n",
|
||||||
|
"Compressing objects: 100% (3/3), done.\n",
|
||||||
|
"\n",
|
||||||
|
"Writing objects: 100% (3/3), 501 bytes | 501.00 KiB/s, done.\n",
|
||||||
|
"\n",
|
||||||
|
"Total 3 (delta 2), reused 0 (delta 0)\n",
|
||||||
|
"\n",
|
||||||
|
"remote: Resolving deltas: 100% (2/2), completed with 2 local objects.\n",
|
||||||
|
"\n",
|
||||||
|
"To https://github.com/redquinoa/health-checks.git\n",
|
||||||
|
"\n",
|
||||||
|
" b52b7a2..160b5f3 master -> master"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user