articlib 0.2.3__tar.gz → 0.2.5__tar.gz

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,21 +1,21 @@
1
- # MIT License
2
-
3
- Copyright (c) 2023 Iñaki Arrondo
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ # MIT License
2
+
3
+ Copyright (c) 2023 Iñaki Arrondo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: articlib
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Small set of tools and utilities in python. Destined to be use in my personal projects.
5
5
  License: MIT
6
6
  Author: Artic42
@@ -1,51 +1,51 @@
1
- # pythonLib
2
-
3
- This is my personal general case python modules and apps to be used in other projects
4
-
5
- ## testEngine
6
-
7
- Test engine is a simple module with the propose of running automated test, this allows to create test for the rest of the library easily. Test are separated in scenario, once a test in a scenario fail the rest of the scenario is skipped. It also outputs using colored test with errors in red and pass test in green. It has the following methods:
8
- * testIfEqual
9
- * testIfFalse
10
- * testIfEqual
11
- * testIfNotEqual
12
- * ...
13
-
14
- ## dateTime
15
-
16
- Library to manage dates for other proposes.
17
-
18
- Public methods for setting dates
19
- * __setToNow__
20
- * __setTo__ (year, month, day, hour, minute, second)
21
- * __setToString__ (string)
22
- * __setMode__ (mode)
23
- * _mode1_: YYYYMMDD
24
- * _mode2_: DDMMYYYY
25
- * _mode3_: MMDDYYYY
26
-
27
- Public methods to get values from the object
28
- * __getDate__
29
- * __getTime__
30
- * __getDateTime__
31
- * __getYear__
32
- * __getMonth__
33
- * __getDay__
34
- * __getHour__
35
- * __getMinute__
36
- * __getSecond__
37
- * __getMode__
38
- * __getDateTimePathFomat__ (It prints the date and time in a format usable in paths, for files)
39
-
40
- ## Log
41
-
42
- A simple log system, it creates a log iwth 7 mask levels and a maximun size of file. If you log more lines than max it creates a new log file. Available masks
43
-
44
- * INFO_MASK
45
- * WARN_MASK
46
- * ERROR_MASK
47
- * COMMS_SEND_MASK
48
- * COMMS_RECV_MASK
49
- * HERMES_MASK000
50
- * COMMS_MASK
51
- * DEBUG_MASK
1
+ # pythonLib
2
+
3
+ This is my personal general case python modules and apps to be used in other projects
4
+
5
+ ## testEngine
6
+
7
+ Test engine is a simple module with the propose of running automated test, this allows to create test for the rest of the library easily. Test are separated in scenario, once a test in a scenario fail the rest of the scenario is skipped. It also outputs using colored test with errors in red and pass test in green. It has the following methods:
8
+ * testIfEqual
9
+ * testIfFalse
10
+ * testIfEqual
11
+ * testIfNotEqual
12
+ * ...
13
+
14
+ ## dateTime
15
+
16
+ Library to manage dates for other proposes.
17
+
18
+ Public methods for setting dates
19
+ * __setToNow__
20
+ * __setTo__ (year, month, day, hour, minute, second)
21
+ * __setToString__ (string)
22
+ * __setMode__ (mode)
23
+ * _mode1_: YYYYMMDD
24
+ * _mode2_: DDMMYYYY
25
+ * _mode3_: MMDDYYYY
26
+
27
+ Public methods to get values from the object
28
+ * __getDate__
29
+ * __getTime__
30
+ * __getDateTime__
31
+ * __getYear__
32
+ * __getMonth__
33
+ * __getDay__
34
+ * __getHour__
35
+ * __getMinute__
36
+ * __getSecond__
37
+ * __getMode__
38
+ * __getDateTimePathFomat__ (It prints the date and time in a format usable in paths, for files)
39
+
40
+ ## Log
41
+
42
+ A simple log system, it creates a log iwth 7 mask levels and a maximun size of file. If you log more lines than max it creates a new log file. Available masks
43
+
44
+ * INFO_MASK
45
+ * WARN_MASK
46
+ * ERROR_MASK
47
+ * COMMS_SEND_MASK
48
+ * COMMS_RECV_MASK
49
+ * HERMES_MASK000
50
+ * COMMS_MASK
51
+ * DEBUG_MASK
@@ -0,0 +1,84 @@
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)
@@ -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()
@@ -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)