articlib 0.2.3__py3-none-any.whl → 0.2.4__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.
- articlib/articFileUtils.py +66 -58
- articlib/articLogger.py +106 -102
- articlib/consoleUtils.py +46 -36
- articlib/dateTime.py +155 -121
- articlib/dice.py +35 -32
- articlib/sqliteEngine.py +69 -66
- articlib/systemUtils.py +33 -34
- articlib/testEngine.py +122 -111
- {articlib-0.2.3.dist-info → articlib-0.2.4.dist-info}/LICENSE +21 -21
- {articlib-0.2.3.dist-info → articlib-0.2.4.dist-info}/METADATA +1 -1
- articlib-0.2.4.dist-info/RECORD +12 -0
- articlib-0.2.3.dist-info/RECORD +0 -12
- {articlib-0.2.3.dist-info → articlib-0.2.4.dist-info}/WHEEL +0 -0
articlib/dateTime.py
CHANGED
|
@@ -1,121 +1,155 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
|
|
3
|
-
YYYYMMDD = 1
|
|
4
|
-
DDMMYYYY = 2
|
|
5
|
-
MMDDYYYY = 3
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
self.
|
|
15
|
-
self.
|
|
16
|
-
self.
|
|
17
|
-
self.
|
|
18
|
-
self.
|
|
19
|
-
self.
|
|
20
|
-
self.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
self.
|
|
25
|
-
self.
|
|
26
|
-
self.
|
|
27
|
-
self.
|
|
28
|
-
self.
|
|
29
|
-
self.
|
|
30
|
-
self.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
self.
|
|
38
|
-
self.
|
|
39
|
-
self.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
self.
|
|
45
|
-
self.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
self.
|
|
49
|
-
self.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
self.
|
|
53
|
-
self.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
self.
|
|
60
|
-
self.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
YYYYMMDD = 1
|
|
4
|
+
DDMMYYYY = 2
|
|
5
|
+
MMDDYYYY = 3
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class createDate:
|
|
9
|
+
def __init__(self, mode):
|
|
10
|
+
self.mode = mode
|
|
11
|
+
|
|
12
|
+
def setToNow(self):
|
|
13
|
+
date = datetime.now()
|
|
14
|
+
self.year = int(date.year)
|
|
15
|
+
self.month = int(date.month)
|
|
16
|
+
self.day = int(date.day)
|
|
17
|
+
self.hour = int(date.hour)
|
|
18
|
+
self.minute = int(date.minute)
|
|
19
|
+
self.second = int(date.second)
|
|
20
|
+
self.calculateStringDate()
|
|
21
|
+
self.calculateStringTime()
|
|
22
|
+
|
|
23
|
+
def setTo(self, year, month, day, hour, minute, second):
|
|
24
|
+
self.year = year
|
|
25
|
+
self.month = month
|
|
26
|
+
self.day = day
|
|
27
|
+
self.hour = hour
|
|
28
|
+
self.minute = minute
|
|
29
|
+
self.second = second
|
|
30
|
+
self.calculateStringDate()
|
|
31
|
+
self.calculateStringTime()
|
|
32
|
+
|
|
33
|
+
def setToString(self, string):
|
|
34
|
+
string = string.split(" ")
|
|
35
|
+
date = string[0]
|
|
36
|
+
time = string[1]
|
|
37
|
+
self.dateString = date
|
|
38
|
+
self.timeString = time
|
|
39
|
+
self.calculateDate()
|
|
40
|
+
self.calculateTime()
|
|
41
|
+
|
|
42
|
+
def calculateDate(self):
|
|
43
|
+
if self.mode == YYYYMMDD:
|
|
44
|
+
self.year = int(self.dateString[0:4])
|
|
45
|
+
self.month = int(self.dateString[5:7])
|
|
46
|
+
self.day = int(self.dateString[8:10])
|
|
47
|
+
elif self.mode == DDMMYYYY:
|
|
48
|
+
self.day = int(self.dateString[0:2])
|
|
49
|
+
self.month = int(self.dateString[3:5])
|
|
50
|
+
self.year = int(self.dateString[6:10])
|
|
51
|
+
elif self.mode == MMDDYYYY:
|
|
52
|
+
self.month = int(self.dateString[0:2])
|
|
53
|
+
self.day = int(self.dateString[3:5])
|
|
54
|
+
self.year = int(self.dateString[6:10])
|
|
55
|
+
else:
|
|
56
|
+
raise ValueError("Invalid mode")
|
|
57
|
+
|
|
58
|
+
def calculateTime(self):
|
|
59
|
+
self.hour = int(self.timeString[0:2])
|
|
60
|
+
self.minute = int(self.timeString[3:5])
|
|
61
|
+
self.second = int(self.timeString[6:8])
|
|
62
|
+
|
|
63
|
+
def calculateStringDate(self):
|
|
64
|
+
if self.mode == YYYYMMDD:
|
|
65
|
+
self.dateString = (
|
|
66
|
+
str(self.year)
|
|
67
|
+
+ "/"
|
|
68
|
+
+ str(self.month).zfill(2)
|
|
69
|
+
+ "/"
|
|
70
|
+
+ str(self.day).zfill(2)
|
|
71
|
+
)
|
|
72
|
+
elif self.mode == DDMMYYYY:
|
|
73
|
+
self.dateString = (
|
|
74
|
+
str(self.day).zfill(2)
|
|
75
|
+
+ "/"
|
|
76
|
+
+ str(self.month).zfill(2)
|
|
77
|
+
+ "/"
|
|
78
|
+
+ str(self.year)
|
|
79
|
+
)
|
|
80
|
+
elif self.mode == MMDDYYYY:
|
|
81
|
+
self.dateString = (
|
|
82
|
+
str(self.month).zfill(2)
|
|
83
|
+
+ "/"
|
|
84
|
+
+ str(self.day).zfill(2)
|
|
85
|
+
+ "/"
|
|
86
|
+
+ str(self.year)
|
|
87
|
+
)
|
|
88
|
+
else:
|
|
89
|
+
raise ValueError("Invalid mode")
|
|
90
|
+
|
|
91
|
+
def calculateStringTime(self):
|
|
92
|
+
self.timeString = (
|
|
93
|
+
str(self.hour).zfill(2)
|
|
94
|
+
+ ":"
|
|
95
|
+
+ str(self.minute).zfill(2)
|
|
96
|
+
+ ":"
|
|
97
|
+
+ str(self.second).zfill(2)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def setMode(self, mode):
|
|
101
|
+
self.mode = mode
|
|
102
|
+
self.calculateStringDate()
|
|
103
|
+
|
|
104
|
+
## Output values
|
|
105
|
+
def getDateTimePathFomat(self):
|
|
106
|
+
if self.mode == YYYYMMDD:
|
|
107
|
+
dateString = (
|
|
108
|
+
str(self.year) + str(self.month).zfill(2) + str(self.day).zfill(2)
|
|
109
|
+
)
|
|
110
|
+
elif self.mode == DDMMYYYY:
|
|
111
|
+
dateString = (
|
|
112
|
+
str(self.day).zfill(2) + str(self.month).zfill(2) + str(self.year)
|
|
113
|
+
)
|
|
114
|
+
elif self.mode == MMDDYYYY:
|
|
115
|
+
dateString = (
|
|
116
|
+
str(self.month).zfill(2) + str(self.day).zfill(2) + str(self.year)
|
|
117
|
+
)
|
|
118
|
+
else:
|
|
119
|
+
raise ValueError("Invalid mode")
|
|
120
|
+
timeString = (
|
|
121
|
+
str(self.hour).zfill(2)
|
|
122
|
+
+ str(self.minute).zfill(2)
|
|
123
|
+
+ str(self.second).zfill(2)
|
|
124
|
+
)
|
|
125
|
+
return f"{dateString}_{timeString}"
|
|
126
|
+
|
|
127
|
+
def getDate(self):
|
|
128
|
+
return self.dateString
|
|
129
|
+
|
|
130
|
+
def getTime(self):
|
|
131
|
+
return self.timeString
|
|
132
|
+
|
|
133
|
+
def getDateTime(self):
|
|
134
|
+
return self.dateString + " " + self.timeString
|
|
135
|
+
|
|
136
|
+
def getYear(self):
|
|
137
|
+
return self.year
|
|
138
|
+
|
|
139
|
+
def getMonth(self):
|
|
140
|
+
return self.month
|
|
141
|
+
|
|
142
|
+
def getDay(self):
|
|
143
|
+
return self.day
|
|
144
|
+
|
|
145
|
+
def getHour(self):
|
|
146
|
+
return self.hour
|
|
147
|
+
|
|
148
|
+
def getMinute(self):
|
|
149
|
+
return self.minute
|
|
150
|
+
|
|
151
|
+
def getSecond(self):
|
|
152
|
+
return self.second
|
|
153
|
+
|
|
154
|
+
def getMode(self):
|
|
155
|
+
return self.mode
|
articlib/dice.py
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
import random
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
def
|
|
32
|
-
return sum(
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class dice:
|
|
5
|
+
def __init__(self, size: int = 6) -> None:
|
|
6
|
+
self.size = size
|
|
7
|
+
|
|
8
|
+
def setSize(self, size: int) -> None:
|
|
9
|
+
self.size = size
|
|
10
|
+
|
|
11
|
+
def roll(self) -> int:
|
|
12
|
+
return random.randint(1, self.size)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class customDice(dice):
|
|
16
|
+
def __init__(self, faces: list[str]) -> None:
|
|
17
|
+
self.faces = faces
|
|
18
|
+
self.size = len(faces)
|
|
19
|
+
|
|
20
|
+
def roll(self) -> str:
|
|
21
|
+
return random.choice(self.faces)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class dicePool:
|
|
25
|
+
def __init__(self, diceList) -> None:
|
|
26
|
+
self.diceList = diceList
|
|
27
|
+
|
|
28
|
+
def roll(self) -> list[int]:
|
|
29
|
+
return [d.roll() for d in self.diceList]
|
|
30
|
+
|
|
31
|
+
def rollSum(self) -> int:
|
|
32
|
+
return sum(self.roll())
|
|
33
|
+
|
|
34
|
+
def rollSuccesses(self, target: int) -> int:
|
|
35
|
+
return sum([1 for roll in self.roll() if roll >= target])
|
articlib/sqliteEngine.py
CHANGED
|
@@ -1,66 +1,69 @@
|
|
|
1
|
-
import sqlite3
|
|
2
|
-
import articlib.articLogger as Logger
|
|
3
|
-
from articlib.articLogger import log
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
self.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def
|
|
33
|
-
self.executeCommand
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def
|
|
62
|
-
self.
|
|
63
|
-
|
|
64
|
-
def
|
|
65
|
-
self.commit()
|
|
66
|
-
|
|
1
|
+
import sqlite3
|
|
2
|
+
import articlib.articLogger as Logger
|
|
3
|
+
from articlib.articLogger import log
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class sqliteEngine:
|
|
7
|
+
def __init__(self, dbPath):
|
|
8
|
+
self.con = sqlite3.connect(dbPath)
|
|
9
|
+
self.cursor = self.con.cursor()
|
|
10
|
+
|
|
11
|
+
def executeCommand(self, command):
|
|
12
|
+
log.addEntry(f"Executing command: {command}", Logger.DEBUG_MASK)
|
|
13
|
+
self.cursor.execute(command)
|
|
14
|
+
|
|
15
|
+
def createTable(self, name, columns):
|
|
16
|
+
self.executeCommand(f"CREATE TABLE {name} ({columns});")
|
|
17
|
+
|
|
18
|
+
def addColumn(self, table, column):
|
|
19
|
+
self.executeCommand(f"ALTER TABLE {table} ADD COLUMN {column};")
|
|
20
|
+
|
|
21
|
+
def deleteColumn(self, table, column):
|
|
22
|
+
self.executeCommand(f"ALTER TABLE {table} DROP COLUMN {column}")
|
|
23
|
+
|
|
24
|
+
def addEntry(self, table, columns, values):
|
|
25
|
+
self.executeCommand(f"INSERT INTO {table} ({columns}) VALUES ({values});")
|
|
26
|
+
|
|
27
|
+
def updateEntry(self, table, columns, values, condition):
|
|
28
|
+
self.executeCommand(
|
|
29
|
+
f'UPDATE {table} SET {columns} = "{values}" WHERE {condition};'
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def deleteEntry(self, table, condition):
|
|
33
|
+
self.executeCommand(f"DELETE FROM {table} WHERE {condition};")
|
|
34
|
+
|
|
35
|
+
def readEntry(self, table, columns):
|
|
36
|
+
self.executeCommand(f"SELECT {columns} FROM {table};")
|
|
37
|
+
result = self.cursor.fetchall()
|
|
38
|
+
log.addEntry(f"Read entry: {result}", Logger.DEBUG_MASK)
|
|
39
|
+
return result
|
|
40
|
+
|
|
41
|
+
def readNumberOfEntries(self, table):
|
|
42
|
+
self.executeCommand(f"SELECT COUNT(*) FROM {table};")
|
|
43
|
+
result = self.cursor.fetchall()
|
|
44
|
+
log.addEntry(f"Read number of entries: {result}", Logger.DEBUG_MASK)
|
|
45
|
+
return result[0][0]
|
|
46
|
+
|
|
47
|
+
def readEntryFiltered(self, table, columns, filter):
|
|
48
|
+
self.executeCommand(f"SELECT {columns} FROM {table} WHERE {filter};")
|
|
49
|
+
result = self.cursor.fetchall()
|
|
50
|
+
log.addEntry(f"Read entry: {result}", Logger.DEBUG_MASK)
|
|
51
|
+
return result
|
|
52
|
+
|
|
53
|
+
def entryExistsOnTable(self, table, condition):
|
|
54
|
+
self.executeCommand(f"SELECT * FROM {table} WHERE {condition};")
|
|
55
|
+
entry = self.cursor.fetchall()
|
|
56
|
+
if len(entry) != 0:
|
|
57
|
+
return True
|
|
58
|
+
else:
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
def deleteEntryFromTable(self, table, condition):
|
|
62
|
+
self.executeCommand(f"DELETE FROM {table} WHERE {condition};")
|
|
63
|
+
|
|
64
|
+
def commit(self):
|
|
65
|
+
self.con.commit()
|
|
66
|
+
|
|
67
|
+
def commitClose(self):
|
|
68
|
+
self.commit()
|
|
69
|
+
self.con.close()
|
articlib/systemUtils.py
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import subprocess
|
|
2
|
-
import datetime
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
self.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
self.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def
|
|
30
|
-
return self.process.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import subprocess
|
|
2
|
+
import datetime
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def executeCommand(command):
|
|
6
|
+
result = subprocess.run(command)
|
|
7
|
+
return result.returncode
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class command:
|
|
11
|
+
def __init__(self, command, run=True, capture=True, timeout=-1):
|
|
12
|
+
self.command = command
|
|
13
|
+
self.capture = capture
|
|
14
|
+
self.timeout = timeout
|
|
15
|
+
if run:
|
|
16
|
+
self.run
|
|
17
|
+
|
|
18
|
+
def run(self):
|
|
19
|
+
if self.timeout > 0:
|
|
20
|
+
self.process = subprocess.run(
|
|
21
|
+
command, capture_output=self.capture, timeout=self.timeout
|
|
22
|
+
)
|
|
23
|
+
else:
|
|
24
|
+
self.runWithoutTimeout
|
|
25
|
+
|
|
26
|
+
def runWithoutTimeout(self):
|
|
27
|
+
self.process = subprocess.run(command, capture_output=self.capture)
|
|
28
|
+
|
|
29
|
+
def stdout(self):
|
|
30
|
+
return self.process.stdout
|
|
31
|
+
|
|
32
|
+
def stderr(self):
|
|
33
|
+
return self.process.stderr
|