articlib 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of articlib might be problematic. Click here for more details.

@@ -1,58 +1,84 @@
1
- import os
2
- import shutil
3
-
4
- def deleteFile(path):
5
- os.remove(path)
6
-
7
- def createFile(path):
8
- file = open (path, "r")
9
- file.close()
10
-
11
- def copyFile(source, destination):
12
- shutil.copy(source, destination)
13
-
14
- def fileExists(path):
15
- return os.path.isfile(path)
16
-
17
- def getFilesInDirectory(path):
18
- return os.listdir(path)
19
-
20
- def deleteDirectory(path):
21
- os.rmdir(path)
22
-
23
- def createDirectory(path):
24
- os.makedirs(path, exist_ok=True)
25
-
26
- class FileIO:
27
- def __init__(self, path, readIt = False):
28
- self.path = path
29
- if readIt:
30
- self.readFile()
31
- else:
32
- lines = []
33
-
34
- def readFile(self):
35
- filePointer = open (self.path, "r")
36
- self.lines = filePointer.readlines()
37
- filePointer.close()
38
-
39
- def writeFile(self):
40
- filePointer = open (self.path, "w")
41
- for line in self.lines:
42
- filePointer.write(line + "\n")
43
- filePointer.close()
44
-
45
- def appendToFile(self):
46
- filePointer = open (self.path, "a")
47
- for line in self.lines:
48
- filePointer.write(line + "\n")
49
- filePointer.close()
50
-
51
- def addLine(self, line):
52
- self.lines.append(line)
53
-
54
- def modifyLine(self, lineNumber, line):
55
- self.lines[lineNumber] = line
56
-
57
- def lineCount(self):
58
- return len(self.lines)
1
+ import os
2
+ import shutil
3
+
4
+
5
+ def deleteFile(path: str):
6
+ os.remove(path)
7
+
8
+
9
+ def createFile(path: str):
10
+ file = open(path, "r")
11
+ file.close()
12
+
13
+
14
+ def copyFile(source: str, destination: str):
15
+ shutil.copy(source, destination)
16
+
17
+
18
+ def fileExists(path: str):
19
+ return os.path.isfile(path)
20
+
21
+
22
+ def getFilesInDirectory(path: str):
23
+ return os.listdir(path)
24
+
25
+
26
+ def deleteDirectory(path: str):
27
+ os.rmdir(path)
28
+
29
+
30
+ def createDirectory(path: str):
31
+ os.makedirs(path, exist_ok=True)
32
+
33
+
34
+ class FileIO:
35
+ def __init__(self, path: str, readIt: bool = False) -> None:
36
+ self.path = path
37
+ if readIt:
38
+ self.readFile()
39
+ else:
40
+ self.lines = []
41
+
42
+ def readFile(self) -> None:
43
+ filePointer = open(self.path, "r")
44
+ self.lines = filePointer.readlines()
45
+ self.lines = [line[:-1] for line in self.lines]
46
+ filePointer.close()
47
+
48
+ def writeFile(self) -> None:
49
+ filePointer = open(self.path, "w")
50
+ for line in self.lines:
51
+ filePointer.write(line + "\n")
52
+ filePointer.close()
53
+
54
+ def appendToFile(self) -> None:
55
+ filePointer = open(self.path, "a")
56
+ for line in self.lines:
57
+ filePointer.write(line + "\n")
58
+ filePointer.close()
59
+
60
+ def addLine(self, line: str) -> None:
61
+ self.lines.append(line)
62
+
63
+ def modifyLine(self, lineNumber: int, line: str) -> None:
64
+ self.lines[lineNumber] = line
65
+
66
+ def removeLine(self, lineNumber: int) -> None:
67
+ del self.lines[lineNumber]
68
+
69
+ def removeLastLine(self) -> None:
70
+ del self.lines[-1]
71
+
72
+ def findLine(self, text: str) -> int:
73
+ result = []
74
+ for i in range(len(self.lines)):
75
+ if text in self.lines[i]:
76
+ result.append(i)
77
+ return result
78
+
79
+ def findAndReplace(self, find: str, replace: str) -> None:
80
+ for i in range(len(self.lines)):
81
+ self.lines[i] = self.lines[i].replace(find, replace)
82
+
83
+ def lineCount(self) -> int:
84
+ return len(self.lines)
articlib/articLogger.py CHANGED
@@ -1,102 +1,106 @@
1
- import articlib.dateTime as dateTime
2
- import os
3
-
4
- if __name__ == "__main__":
5
- pass
6
-
7
- INFO_MASK = 0b00000001
8
- WARN_MASK = 0b00000010
9
- ERROR_MASK = 0b00000100
10
- COMMS_SEND_MASK = 0b00001000
11
- COMMS_RECV_MASK = 0b00010000
12
- HERMES_MASK = 0b00100000
13
- COMMS_MASK= 0b00011000
14
- DEBUG_MASK = 0b01000000
15
- DEFAULT_MASK = INFO_MASK | COMMS_MASK | ERROR_MASK | HERMES_MASK
16
-
17
- class Logger:
18
- def __init__(self):
19
- self.init = False
20
- self.logName = ""
21
- self.maxLines = 0
22
- self.lines = 0
23
- self.logPath = ""
24
- self.mask = 0b0
25
-
26
- def initialize(self, logName, maxLines = 1000, logPath = "logs", mask = DEFAULT_MASK):
27
- self.init = True
28
- self.logName = logName
29
- self.maxLines = maxLines
30
- self.lines = 0
31
- self.logPath = logPath
32
- self.mask = mask
33
- self.date = dateTime.createDate(dateTime.YYYYMMDD)
34
- self.createLogFile()
35
-
36
- def createLogFile(self):
37
- self.date.setToNow()
38
- dateSring = self.date.getDateTimePathFomat()
39
- os.makedirs(self.logPath, exist_ok=True)
40
- self.logFilePath = self.logPath + "/" + self.logName + "_" + dateSring + ".log"
41
- if os.path.isfile(self.logFilePath):
42
- self.logFile = open(self.logFilePath, "a")
43
- else:
44
- self.logFile = open(self.logFilePath, "w")
45
- self.logFile.write(f"Log file created at {self.date.getDateTime()} with name {self.logName}\n")
46
- self.lines = 0
47
-
48
- def addEntry(self, message, mask = INFO_MASK):
49
- maskName = self.getMaskName(mask)
50
- if mask & self.mask:
51
- if self.init:
52
- self.writeLog(message, maskName)
53
-
54
- def getMaskName(self, mask):
55
- switcher = {
56
- INFO_MASK: "INFO",
57
- WARN_MASK: "WARN",
58
- ERROR_MASK: "ERROR",
59
- COMMS_SEND_MASK: "COMMS_SEND",
60
- COMMS_RECV_MASK: "COMMS_RECV",
61
- HERMES_MASK: "HERMES",
62
- DEBUG_MASK: "DEBUG",
63
- DEFAULT_MASK: "DEFAULT"
64
- }
65
- return switcher.get(mask, "UNKNOWN")
66
-
67
- def writeLog(self, message, maskName):
68
- self.date.setToNow()
69
- dateSring = self.date.getDateTime()
70
- self.lines += 1
71
- self.logFile.write(f"{dateSring} - {maskName} - {message}\n")
72
- if self.lines >= self.maxLines:
73
- self.logFile.close()
74
- self.createLogFile()
75
-
76
- def setMask(self, mask):
77
- self.mask = mask
78
-
79
- def getMask(self):
80
- return self.mask
81
-
82
- def setValueInMask(self, mask):
83
- self.mask = self.mask | mask
84
-
85
- def unsetValueInMask(self, mask):
86
- self.mask = self.mask & ~mask
87
-
88
- def flush(self):
89
- self.logFile.flush()
90
-
91
- def restartFile(self):
92
- self.logFile.close()
93
- self.lines = 0
94
- self.createLogFile()
95
-
96
- def getLogFilePath(self):
97
- return self.logFilePath
98
-
99
- def close(self):
100
- self.logFile.close()
101
-
102
- log = Logger()
1
+ import articlib.dateTime as dateTime
2
+ import os
3
+
4
+ if __name__ == "__main__":
5
+ pass
6
+
7
+ INFO_MASK = 0b00000001
8
+ WARN_MASK = 0b00000010
9
+ ERROR_MASK = 0b00000100
10
+ COMMS_SEND_MASK = 0b00001000
11
+ COMMS_RECV_MASK = 0b00010000
12
+ HERMES_MASK = 0b00100000
13
+ COMMS_MASK = 0b00011000
14
+ DEBUG_MASK = 0b01000000
15
+ DEFAULT_MASK = INFO_MASK | COMMS_MASK | ERROR_MASK | HERMES_MASK
16
+
17
+
18
+ class Logger:
19
+ def __init__(self):
20
+ self.init = False
21
+ self.logName = ""
22
+ self.maxLines = 0
23
+ self.lines = 0
24
+ self.logPath = ""
25
+ self.mask = 0b0
26
+
27
+ def initialize(self, logName, maxLines=1000, logPath="logs", mask=DEFAULT_MASK):
28
+ self.init = True
29
+ self.logName = logName
30
+ self.maxLines = maxLines
31
+ self.lines = 0
32
+ self.logPath = logPath
33
+ self.mask = mask
34
+ self.date = dateTime.createDate(dateTime.YYYYMMDD)
35
+ self.createLogFile()
36
+
37
+ def createLogFile(self):
38
+ self.date.setToNow()
39
+ dateSring = self.date.getDateTimePathFomat()
40
+ os.makedirs(self.logPath, exist_ok=True)
41
+ self.logFilePath = self.logPath + "/" + self.logName + "_" + dateSring + ".log"
42
+ if os.path.isfile(self.logFilePath):
43
+ self.logFile = open(self.logFilePath, "a")
44
+ else:
45
+ self.logFile = open(self.logFilePath, "w")
46
+ self.logFile.write(
47
+ f"Log file created at {self.date.getDateTime()} with name {self.logName}\n"
48
+ )
49
+ self.lines = 0
50
+
51
+ def addEntry(self, message, mask=INFO_MASK):
52
+ maskName = self.getMaskName(mask)
53
+ if mask & self.mask:
54
+ if self.init:
55
+ self.writeLog(message, maskName)
56
+
57
+ def getMaskName(self, mask):
58
+ switcher = {
59
+ INFO_MASK: "INFO",
60
+ WARN_MASK: "WARN",
61
+ ERROR_MASK: "ERROR",
62
+ COMMS_SEND_MASK: "COMMS_SEND",
63
+ COMMS_RECV_MASK: "COMMS_RECV",
64
+ HERMES_MASK: "HERMES",
65
+ DEBUG_MASK: "DEBUG",
66
+ DEFAULT_MASK: "DEFAULT",
67
+ }
68
+ return switcher.get(mask, "UNKNOWN")
69
+
70
+ def writeLog(self, message, maskName):
71
+ self.date.setToNow()
72
+ dateSring = self.date.getDateTime()
73
+ self.lines += 1
74
+ self.logFile.write(f"{dateSring} - {maskName} - {message}\n")
75
+ if self.lines >= self.maxLines:
76
+ self.logFile.close()
77
+ self.createLogFile()
78
+
79
+ def setMask(self, mask):
80
+ self.mask = mask
81
+
82
+ def getMask(self):
83
+ return self.mask
84
+
85
+ def setValueInMask(self, mask):
86
+ self.mask = self.mask | mask
87
+
88
+ def unsetValueInMask(self, mask):
89
+ self.mask = self.mask & ~mask
90
+
91
+ def flush(self):
92
+ self.logFile.flush()
93
+
94
+ def restartFile(self):
95
+ self.logFile.close()
96
+ self.lines = 0
97
+ self.createLogFile()
98
+
99
+ def getLogFilePath(self):
100
+ return self.logFilePath
101
+
102
+ def close(self):
103
+ self.logFile.close()
104
+
105
+
106
+ log = Logger()
articlib/consoleUtils.py CHANGED
@@ -1,36 +1,46 @@
1
- import colorama
2
- from colorama import Fore, Back, Style
3
-
4
- def printRed(text):
5
- print(Fore.RED + text + Style.RESET_ALL)
6
-
7
- def printGreen(text):
8
- print(Fore.GREEN + text + Style.RESET_ALL)
9
-
10
- def printYellow(text):
11
- print(Fore.YELLOW + text + Style.RESET_ALL)
12
-
13
- def printBlue(text):
14
- print(Fore.BLUE + text + Style.RESET_ALL)
15
-
16
- def printMagenta(text):
17
- print(Fore.MAGENTA + text + Style.RESET_ALL)
18
-
19
- def printBold(text):
20
- print(Style.BRIGHT + text + Style.RESET_ALL)
21
-
22
- def printRedBold(text):
23
- print(Style.BRIGHT + Fore.RED + text + Style.RESET_ALL)
24
-
25
- def printGreenBold(text):
26
- print(Style.BRIGHT + Fore.GREEN + text + Style.RESET_ALL)
27
-
28
- def printYellowBold(text):
29
- print(Style.BRIGHT + Fore.YELLOW + text + Style.RESET_ALL)
30
-
31
- def printBlueBold(text):
32
- print(Style.BRIGHT + Fore.BLUE + text + Style.RESET_ALL)
33
-
34
- def printMagentaBold(text):
35
- print(Style.BRIGHT + Fore.MAGENTA + text + Style.RESET_ALL)
36
-
1
+ import colorama
2
+ from colorama import Fore, Back, Style
3
+
4
+
5
+ def printRed(text):
6
+ print(Fore.RED + text + Style.RESET_ALL)
7
+
8
+
9
+ def printGreen(text):
10
+ print(Fore.GREEN + text + Style.RESET_ALL)
11
+
12
+
13
+ def printYellow(text):
14
+ print(Fore.YELLOW + text + Style.RESET_ALL)
15
+
16
+
17
+ def printBlue(text):
18
+ print(Fore.BLUE + text + Style.RESET_ALL)
19
+
20
+
21
+ def printMagenta(text):
22
+ print(Fore.MAGENTA + text + Style.RESET_ALL)
23
+
24
+
25
+ def printBold(text):
26
+ print(Style.BRIGHT + text + Style.RESET_ALL)
27
+
28
+
29
+ def printRedBold(text):
30
+ print(Style.BRIGHT + Fore.RED + text + Style.RESET_ALL)
31
+
32
+
33
+ def printGreenBold(text):
34
+ print(Style.BRIGHT + Fore.GREEN + text + Style.RESET_ALL)
35
+
36
+
37
+ def printYellowBold(text):
38
+ print(Style.BRIGHT + Fore.YELLOW + text + Style.RESET_ALL)
39
+
40
+
41
+ def printBlueBold(text):
42
+ print(Style.BRIGHT + Fore.BLUE + text + Style.RESET_ALL)
43
+
44
+
45
+ def printMagentaBold(text):
46
+ print(Style.BRIGHT + Fore.MAGENTA + text + Style.RESET_ALL)