pushing using magit yay

This commit is contained in:
samialazar 2020-05-22 16:35:56 +02:00
parent d2e57f15f2
commit b4071ec660
14 changed files with 355 additions and 0 deletions

View File

@ -0,0 +1,8 @@
n
print("Hello World!")
print("Hello Again")
print("I like typing this.")
print("This is fun.")
print('Yay! Printing.')
print("I'd much rather you 'not'.")
print('I "said" do not touch this.')

View File

@ -0,0 +1 @@
sami@afro-linux-lenovo-b50-30.19806:1589891645

View File

@ -0,0 +1,18 @@
from sys import argv
script, filename = argv
txt = open(filename)
print(f"Here's your file {filename}:")
print(txt.read())
print("Type the filename again:")
file_again = input("> ")
txt_again = open(file_again)
print(txt_again.read())

View File

@ -0,0 +1,41 @@
from sys import argv
script, filename = argv
print(f"We're going to erase {filename}.")
print("If you don't want that, hit CTRL-C (^C).")
print("If you do want that, hit RETURN.")
input("?")
print("Opening the file...")
target = open(filename, 'w')
print("Truncating the file.
target.truncate()
Goodbye!")
print("Now I'm going to ask you for three lines.")
line1 = input("line 1: ")
line2 = input("line 2: ")
line3 = input("line 3: ")
print("I'm going to write these to the file.")
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
print("And finally, we close it.")
target.close()

View File

@ -0,0 +1,28 @@
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print(f"Copying from {from_file} to {to_file}")
# we could do these two on one line, how?
in_file = open(from_file)
indata = in_file.read()
print(f"The input file is {len(indata)} bytes long")
print(f"Does the output file exist? {exists(to_file)}")
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()
out_file = open(to_file, 'w')
out_file.write(indata)
print("Alright, all done.")
out_file.close()
in_file.close()

View File

@ -0,0 +1,25 @@
# this one is like your scripts with argv
def print_two(*args):
arg1, arg2 = args
print(f"arg1: {arg1}, arg2: {arg2}")
# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
print(f"arg1: {arg1}, arg2: {arg2}")
# this just takes one argument
def print_one(arg1):
print(f"arg1: {arg1}")
# this one takes no arguments
def print_none():
print("I got nothin'.")
print_two("Zed","Shaw")
print_two_again("Zed","Shaw")
print_one("First!")
print_none()

View File

@ -0,0 +1,26 @@
def cheese_and_crackers(cheese_count, boxes_of_crackers):
print(f"You have {cheese_count} cheeses!")
print(f"You have {boxes_of_crackers} boxes of crackers!")
print("Man that's enough for a party!")
print("Get a blanket.\n")
print("We can just give the function numbers directly:")
cheese_and_crackers(20, 30)
print("OR, we can use variables from our script:")
amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese, amount_of_crackers)
print("We can even do math inside too:")
cheese_and_crackers(10 + 20, 5 + 6)
print("And we can combine the two, variables and math:")
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)

View File

@ -0,0 +1,46 @@
from sys import argv
script, input_file = argv
def print_all(f):
print(f.read())
def rewind(f):
f.seek(0)
def print_a_line(line_count, f):
print(line_count, f.readline())
current_file = open(input_file)
print("First let's print the whole file:\n")
print_all(current_file)
print("Now let's rewind, kind of like a tape.")
rewind(current_file)
print("Let's print three lines:")
current_line = 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)

View File

@ -0,0 +1,39 @@
def add(a, b):
print(f"ADDING {a} + {b}")
return a + b
def subtract(a, b):
print(f"SUBTRACTING {a} - {b}")
return a - b
def multiply(a, b):
print(f"MULTIPLYING {a} * {b}")
return a * b
def divide(a, b):
print(f"DIVIDING {a} / {b}")
return a / b
print("Let's do some math with just functions!")
age = add(30, 5)
height = subtract(78, 4)
weight = multiply(90, 2)
iq = divide(100, 2)
print(f"Age: {age}, Height: {height}, Weight: {weight}, IQ: {iq}")
# A puzzle for the extra credit, type it in anyway.
print("Here is a puzzle.")
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
print("That becomes: ", what, "Can you do it by hand?")

View File

@ -0,0 +1,5 @@
* What Do Know SO far?
** print : The print function in Python is a function that outputs to your console window whatever you say you want to print out.
**

View File

@ -0,0 +1,43 @@
*** cdist #6: Glueing it together
**** Lecture content
***** Objective
- Apply learnings from the previous cdist sessions
***** Steps 1: *__all_in_one* (1.25h)
- Create a new type named *__all_in_one*
- Decide yourself whether it is a singleton or not
- Reason why in your cdist.org file
- It should work on alpine, debian and fedora
- It accepts the following parameters:
- *--with-x* (boolean)
- *--extra-packages* (optional multiple)
- On Alpine, it should install netcat-openbsd and tshark
- On Debian, it should install netcat tshark
- On Fedora, it should install nmap-ncat wireshark-cli
- On all operating systems install socat sipcalc sudo
- If the detected operating system is neither
Alpine/Debian/Fedora, output an error message and abort the
manifest with exit code 1
- Additionally install all packages specified by the *--extra-packages* parameter
***** Steps 2: *__firewall* (1.25h)
- Create a new type *__my_firewall*
- Add a *type explorer* to find out whether nft is present on
the target system
- Add a required parameter named *file*
- If the type explorer does not detect nft on the target system,
abort with an error message
- Deploy the specified file to */etc/my-nftables*
- Add a *type explorer* that reads the current nft rules
- If the rules are different on the target host, apply the new
ruleset by generating code in *gencode-remote*
- If the filename specified by the *file* parameter is *-* (the
minus sign), then the type should read from *stdin*
***** Step 3: manifest (0.5h)
- Create a new manifest in the folder that contains the initial manifest
- Name the new manifest *firewall*
- Source the *firewall* manifest in the *initial* manifest
- In the *firewall* manifest, match on *localhost*
- Install nftables
- Use the *__firewall* type
- Use correct *require* parameter to ensure that nftables is
installed before the *__firewall* type is run

View File

@ -0,0 +1,42 @@
*** cdist #6: Glueing it together
**** Lecture content
***** Objective
- Apply learnings from the previous cdist sessions
***** Steps 1: *__all_in_one* (1.25h)
- Create a new type named *__all_in_one*
- Decide yourself whether it is a singleton or not
- Reason why in your cdist.org file
- It should work on alpine, debian and fedora
- It accepts the following parameters:
- *--with-x* (boolean)
- *--extra-packages* (optional multiple)
- On Alpine, it should install netcat-openbsd and tshark
- On Debian, it should install netcat tshark
- On Fedora, it should install nmap-ncat wireshark-cli
- On all operating systems install socat sipcalc sudo
- If the detected operating system is neither
Alpine/Debian/Fedora, output an error message and abort the
manifest with exit code 1
- Additionally install all packages specified by the *--extra-packages* parameter
***** Steps 2: *__firewall* (1.25h)
- Create a new type *__my_firewall*
- Add a *type explorer* to find out whether nft is present on
the target system
- Add a required parameter named *file*
- If the type explorer does not detect nft on the target system,
abort with an error message
- Deploy the specified file to */etc/my-nftables*
- Add a *type explorer* that reads the current nft rules
- If the rules are different on the target host, apply the new
ruleset by generating code in *gencode-remote*
- If the filename specified by the *file* parameter is *-* (the
minus sign), then the type should read from *stdin*
***** Step 3: manifest (0.5h)
- Create a new manifest in the folder that contains the initial manifest
- Name the new manifest *firewall*
- Source the *firewall* manifest in the *initial* manifest
- In the *firewall* manifest, match on *localhost*
- Install nftables
- Use the *__firewall* type
- Use correct *require* parameter to ensure that nftables is
installed before the *__firewall* type is run

View File

@ -0,0 +1,33 @@
*** cdist #3: type parameters
**** Lecture content
***** Create a new type named *__colourful_file*
- The objective is to create a type that creates colourful file
- The content of the file should be "colour=...", where "..." is
a colour specified by a parameter
- Add an *optional parameter* named *colour*
- Use the **__file** type inside your type to create a file
- Use the *$__object_id* variable inside your type
***** Extend your type to be more colourful
- Modify the *optional parameter* to be able to be specified
*multiple times*
- For each time it is specified, add a line "colour=..." to the file
***** Create a new type *__my_dotfiles*
- Objective is to manage the dotfiles in your home directory
- Make it a *singleton* type
- Create a sub directory *files* in the type
- Add your .emacs config to the files folder
- Add a *for* loop to your type to deploy .[A-z]* to your home directory
- Add a .bashrc or .zshrc to the files folder (depending on your shell)
- In the initial manifest, add __my_dotfiles when the target
host is localhost
***** As usual commit all changes to your ungleich-learning-circle repo
* Defining parameters
** Every type consists of required, optional and boolean parameters, which
must each be declared in a newline separated file in parameter/required,