Compare commits
5 Commits
4ada02f510
...
88c498eda4
| Author | SHA1 | Date | |
|---|---|---|---|
| 88c498eda4 | |||
| beb7e700c7 | |||
| 536a220c04 | |||
| 168def1fb4 | |||
| 559721aaf5 |
39
create_systemd_unit/main.py
Normal file
39
create_systemd_unit/main.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#! /usr/bin/env Python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
class create_unit_service():
|
||||||
|
def __init__(self, UnitName = str,systemd_sysfolder = "/etc/systemd/system", execstart = str, systemd_type = "simple") -> None:
|
||||||
|
self.UnitName = UnitName
|
||||||
|
self.systemd_systemfolder = systemd_sysfolder
|
||||||
|
self.execstart = execstart
|
||||||
|
if systemd_type == "simple" or systemd_type == "oneshot":
|
||||||
|
self.systemd_type = systemd_type
|
||||||
|
else:
|
||||||
|
print("Kein richtiger Typ")
|
||||||
|
raise "systemd_type ist nicht richtig"
|
||||||
|
|
||||||
|
def create_unit(self):
|
||||||
|
UnitFile = self.systemd_systemfolder + os.sep + self.UnitName + ".service"
|
||||||
|
if os.path.exists(self.systemd_systemfolder):
|
||||||
|
if os.path.exists(UnitFile):
|
||||||
|
print("Gibt es bereits")
|
||||||
|
else:
|
||||||
|
print("Wird angelegt !!")
|
||||||
|
with open(UnitFile, "w") as ufile:
|
||||||
|
print("[Unit]",
|
||||||
|
"[Service]",
|
||||||
|
"Type=oneshot",
|
||||||
|
"PrivateTmp=yes",
|
||||||
|
"DynamicUser=yes",
|
||||||
|
"ExecStart={my_execStart}".format(my_execStart=self.execstart), file=ufile, sep="\n")
|
||||||
|
os.popen("systemctl daemon-reload")
|
||||||
|
|
||||||
|
def delete_unit(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
new_unit = create_unit_service(UnitName="TestUnit",
|
||||||
|
execstart="""/usr/bin/echo "Ich bin eine TestUnit %p" """,
|
||||||
|
systemd_type="oneshot")
|
||||||
|
new_unit.create_unit()
|
||||||
2
my_movies/add_value.sql
Normal file
2
my_movies/add_value.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
INSERT INTO eggs (cooler_typ, glückszahl)
|
||||||
|
VALUES('{coolertype}', {eine_zahl});
|
||||||
5
my_movies/create_db.sql
Normal file
5
my_movies/create_db.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS eggs(
|
||||||
|
cooler_typ TEXT,
|
||||||
|
glückszahl INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
@@ -3,25 +3,32 @@ import sqlite3, os
|
|||||||
class db_work:
|
class db_work:
|
||||||
def __init__(self,db_file = str ) -> None:
|
def __init__(self,db_file = str ) -> None:
|
||||||
self.db_file = db_file
|
self.db_file = db_file
|
||||||
|
self.script_folder = os.path.dirname(os.path.realpath(__file__))
|
||||||
def create_db(self):
|
def create_db(self):
|
||||||
with sqlite3.connect(self.db_file) as con_db:
|
with sqlite3.connect(self.db_file) as con_db:
|
||||||
cursor = con_db.cursor()
|
cursor = con_db.cursor()
|
||||||
sql_code = '''
|
fd = open(self.script_folder + os.sep + "create_db.sql", "r")
|
||||||
CREATE TABLE IF NOT EXISTS eggs(
|
sql_code = fd.read()
|
||||||
cooler_typ TEXT,
|
#sql_code = '''
|
||||||
glückszahl INTEGER
|
# CREATE TABLE IF NOT EXISTS eggs(
|
||||||
);
|
# cooler_typ TEXT,
|
||||||
'''
|
# glückszahl INTEGER
|
||||||
|
# );
|
||||||
|
# '''
|
||||||
|
|
||||||
cursor.execute(sql_code)
|
cursor.execute(sql_code)
|
||||||
con_db.commit()
|
con_db.commit()
|
||||||
|
|
||||||
def add_value_db(self, cooler_typ = str, glueckszahl = int):
|
def add_value_db(self, cooler_typ = str, glueckszahl = int):
|
||||||
with sqlite3.connect(self.db_file) as con_db:
|
with sqlite3.connect(self.db_file) as con_db:
|
||||||
cursor = con_db.cursor()
|
cursor = con_db.cursor()
|
||||||
sql_code = '''
|
fd = open(self.script_folder + os.sep + "add_value.sql", "r")
|
||||||
INSERT INTO eggs (cooler_typ, glückszahl)
|
sql_code = fd.read().format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
||||||
VALUES('{coolertype}', {eine_zahl});
|
#sql_code = '''
|
||||||
'''.format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
# INSERT INTO eggs (cooler_typ, glückszahl)
|
||||||
|
# VALUES('{coolertype}', {eine_zahl});
|
||||||
|
# '''.format(coolertype=cooler_typ,eine_zahl=glueckszahl)
|
||||||
|
|
||||||
cursor.execute(sql_code)
|
cursor.execute(sql_code)
|
||||||
con_db.commit()
|
con_db.commit()
|
||||||
|
|
||||||
@@ -41,5 +48,5 @@ if __name__ == "__main__":
|
|||||||
db_file_full = script_folder + os.sep + "spam.db"
|
db_file_full = script_folder + os.sep + "spam.db"
|
||||||
my_db = db_work(db_file=db_file_full)
|
my_db = db_work(db_file=db_file_full)
|
||||||
my_db.create_db()
|
my_db.create_db()
|
||||||
my_db.add_value_db(cooler_typ="daniel-2", glueckszahl=42)
|
my_db.add_value_db(cooler_typ="daniel-3", glueckszahl=42)
|
||||||
print(my_db.show_value())
|
print(my_db.show_value())
|
||||||
Binary file not shown.
9
test_skripte/read_logging.py
Normal file
9
test_skripte/read_logging.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
with open("/var/log/pull_and_push.log", "r") as log:
|
||||||
|
for line in log:
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
|
||||||
|
with open("testfile", "w") as test:
|
||||||
|
print("ksskkdk", file=test)
|
||||||
Reference in New Issue
Block a user