[ TAG 164 ][02.09.2021] -Fehlgeschlagen -IAP-20210601-20210722-1145 -RPRCSL_LOGGER
Ich habe die Worksession um ca. [02.10.2021][0000] gestartet. Das ist der Entwicklungsstand von [T163].
import pathlib
def CHECK_STRUCTURE_20211001(log_root="LOGFILES", year="2021", month="10", day="01"):
print("")
print("CHECK_STRUCTURE")
print(f"pathlib.Path.cwd():{pathlib.Path.cwd()}")
print(f"pathlib.Path.home():{pathlib.Path.home()}")
path = pathlib.Path.cwd()
for parent in path.parents:
print(f"parent: {parent}")
print("")
Ausgabe:
---------------------------------------
CHECK_STRUCTURE
pathlib.Path.cwd():E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145
pathlib.Path.home():C:\Users\HP Power Pavilion
parent: E:\2021\Projekte\Python\2021\06_jun
parent: E:\2021\Projekte\Python\2021
parent: E:\2021\Projekte\Python
parent: E:\2021\Projekte
parent: E:\2021
parent: E:\
---------------------------------------
Ich werde noch mal kurz widerholen, worum es hier geht. Der Logger ist nicht in der Lage Verzeichnisse anzulegen. Jeder ALOG wird in einen separaten Prozess gestartet. Jeder gestartete Prozess bekommt Log-File. Diese werden in einer bestimmten Ordnerstruktur archiviert.
Das [loggin]-Modul setzt voraus, dass die Ordnerstruktur, die als Pfad den FileHandler mitgegeben wurde existiert. Sollte die Ordnerstruktur nicht existieren, wird ein Fehler zurückgegeben.
Diese Umstände führen dazu, ein Modul zu entwickeln, der die Aufgabe hat die nötige Ordnerstruktur zu überprüfen und gegebenenfalls anzulegen.
In Python gibt es einige Möglichkeiten Ordnerstrukturen anzulegen. Man kann es mit dem [os]-Modul realisieren oder mit [pathlib]. An [pathlib] gefällt mir persönlich der Umgang mit der Codierung des Pfades. Je nach dem auf welchen Betriebssystem man sich befindet wird der Pfad anders kodiert. Das [pathlib]-Modul löst dieses Problem intern. Je nach Betriebssystem, wo man den Python-Script ausführt, wird die Pfad-Zeichenkette automatisch die richtige Codierung gewählt. Hier sind einige Quellen zum Einarbeiten in das [pathlib]-Modul.
- Quelle:
- Module 8.0: File Input and Output IO
- [https://www.youtube.com/watch?v=wQDle_BpVL0]
- Module 8.1: An Introduction to Files
- [https://www.youtube.com/watch?v=_23xBK6_8rE]
- Module 8.2: pathlib Basics
- [https://www.youtube.com/watch?v=BR_xn-aL5ok]
- Module 8.3: Opening and Closing a File
- [https://www.youtube.com/watch?v=zX4ReB2pkpY]
- Module 8.4: Reading and Writing Files
- [https://www.youtube.com/watch?v=Dp58x1G03L4]
- Module 8.5: Working with Files
- [https://www.youtube.com/watch?v=Tgl4bUzb5bs]
- Module 8.6: Working with Different File Types
- [https://www.youtube.com/watch?v=5Ix2LCPbxU0]
tst = pathlib.Path('E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log')
print(f"tst: {tst}")
Ausgabe:
---------------------------------------
tst: E:1\Projekte\Python1_jun\IAP-20210601-20210722-1145\ALOG_20210722 est2.log
---------------------------------------
tst = pathlib.Path(r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log')
print(f"tst: {tst}")
Ausgabe:
---------------------------------------
tst: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst = pathlib.Path('E:\\2021\\Projekte\\Python\\2021\\06_jun\\IAP-20210601-20210722-1145\\ALOG_20210722\\test2.log')
print(f"tst: {tst}")
Ausgabe:
---------------------------------------
tst: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst1 = pathlib.Path(
'E:\\2021\\Projekte\\Python\\2021\\06_jun\\IAP-20210601-20210722-1145\\ALOG_20210722\\test2.log'
)
print(f"tst1: {tst1}")
tst2 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log'
)
print(f"tst2: {tst2}")
print(f"tst2.exists(): {tst2.exists()}")
tst3 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722'
)
print(f"tst3: {tst3}")
print(f"tst3.exists(): {tst3.exists()}")
tst4 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST'
)
print(f"tst4: {tst4}")
print(f"tst4.exists(): {tst4.exists()}")
Ausgabe:
---------------------------------------
tst1: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2.exists(): True
tst3: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722
tst3.exists(): True
tst4: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST
tst4.exists(): False
import pathlib
def CHECK_STRUCTURE_20211001(log_root="LOGFILES", year="2021", month="10", day="01"):
print("")
print("CHECK_STRUCTURE")
print(f"pathlib.Path.cwd():{pathlib.Path.cwd()}")
print(f"pathlib.Path.home():{pathlib.Path.home()}")
path = pathlib.Path.cwd()
for parent in path.parents:
print(f"parent: {parent}")
tst1 = pathlib.Path(
'E:\\2021\\Projekte\\Python\\2021\\06_jun\\IAP-20210601-20210722-1145\\ALOG_20210722\\test2.log'
)
print(f"tst1: {tst1}")
tst2 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log'
)
print(f"tst2: {tst2}")
print(f"tst2.exists(): {tst2.exists()}")
tst3 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722'
)
print(f"tst3: {tst3}")
print(f"tst3.exists(): {tst3.exists()}")
tst4 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST'
)
print(f"tst4: {tst4}")
print(f"tst4.exists(): {tst4.exists()}")
print("")
'''
Ausgabe:
---------------------------------------------------------------------------------------------
tst1: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2.exists(): True
tst3: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722
tst3.exists(): True
tst4: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST
tst4.exists(): False
'''
[03.10.2021][0255]
import pathlib
def CHECK_STRUCTURE_20211001(log_root="LOGFILES", year="2021", month="10", day="01"):
print("")
print("CHECK_STRUCTURE")
print(f"pathlib.Path.cwd():{pathlib.Path.cwd()}")
print(f"pathlib.Path.home():{pathlib.Path.home()}")
path = pathlib.Path.cwd()
for parent in path.parents:
print(f"parent: {parent}")
tst1 = pathlib.Path(
'E:\\2021\\Projekte\\Python\\2021\\06_jun\\IAP-20210601-20210722-1145\\ALOG_20210722\\test2.log'
)
print(f"tst1: {tst1}")
tst2 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log'
)
print(f"tst2: {tst2}")
print(f"tst2.exists(): {tst2.exists()}")
tst3 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722'
)
print(f"tst3: {tst3}")
print(f"tst3.exists(): {tst3.exists()}")
tst4 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST'
)
print(f"tst4: {tst4}")
print(f"tst4.exists(): {tst4.exists()}")
tst5 = pathlib.Path('E:\\') / pathlib.Path('2021') / pathlib.Path('Projekte')
print(f"tst5: {tst5}")
print(f"tst5.exists(): {tst5.exists()}")
print("")
'''
tst1: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2.exists(): True
tst3: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722
tst3.exists(): True
tst4: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST
tst4.exists(): False
tst5: E:\2021\Projekte
tst5.exists(): True
'''
def CHECK_STRUCTURE_20211001(log_root="LOGFILES", year="2021", month="10", day="01"):
print("")
print("CHECK_STRUCTURE")
print(f"pathlib.Path.cwd():{pathlib.Path.cwd()}")
print(f"pathlib.Path.home():{pathlib.Path.home()}")
path = pathlib.Path.cwd()
for parent in path.parents:
print(f"parent: {parent}")
tst1 = pathlib.Path(
'E:\\2021\\Projekte\\Python\\2021\\06_jun\\IAP-20210601-20210722-1145\\ALOG_20210722\\test2.log'
)
print(f"tst1: {tst1}")
tst2 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log'
)
print(f"tst2: {tst2}")
print(f"tst2.exists(): {tst2.exists()}")
tst3 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722'
)
print(f"tst3: {tst3}")
print(f"tst3.exists(): {tst3.exists()}")
tst4 = pathlib.Path(
r'E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST'
)
print(f"tst4: {tst4}")
print(f"tst4.exists(): {tst4.exists()}")
tst5 = pathlib.Path('E:\\') / \
pathlib.Path('2021') / \
pathlib.Path('Projekte') / \
pathlib.Path('Python') / \
pathlib.Path('2021') / \
pathlib.Path('06_jun') / \
pathlib.Path('IAP-20210601-20210722-1145') / \
pathlib.Path('ALOG_20210722')
print(f"tst5: {tst5}")
print(f"tst5.exists(): {tst5.exists()}")
print("")
---------------------------------------
tst1: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\test2.log
tst2.exists(): True
tst3: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722
tst3.exists(): True
tst4: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722\TEST
tst4.exists(): False
tst5: E:\2021\Projekte\Python\2021\06_jun\IAP-20210601-20210722-1145\ALOG_20210722
tst5.exists(): True
---------------------------------------
Kommentare
Kommentar veröffentlichen