TSVZ 2.67__tar.gz → 2.70__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.
- {tsvz-2.67 → tsvz-2.70}/PKG-INFO +10 -2
- {tsvz-2.67 → tsvz-2.70}/TSVZ.egg-info/PKG-INFO +10 -2
- {tsvz-2.67 → tsvz-2.70}/TSVZ.py +40 -9
- {tsvz-2.67 → tsvz-2.70}/setup.py +1 -1
- {tsvz-2.67 → tsvz-2.70}/LICENSE +0 -0
- {tsvz-2.67 → tsvz-2.70}/README.md +0 -0
- {tsvz-2.67 → tsvz-2.70}/TSVZ.egg-info/SOURCES.txt +0 -0
- {tsvz-2.67 → tsvz-2.70}/TSVZ.egg-info/dependency_links.txt +0 -0
- {tsvz-2.67 → tsvz-2.70}/TSVZ.egg-info/entry_points.txt +0 -0
- {tsvz-2.67 → tsvz-2.70}/TSVZ.egg-info/top_level.txt +0 -0
- {tsvz-2.67 → tsvz-2.70}/setup.cfg +0 -0
{tsvz-2.67 → tsvz-2.70}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: TSVZ
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.70
|
|
4
4
|
Summary: An simple in memory wrapper around a TSV file to function as a database
|
|
5
5
|
Home-page: https://github.com/yufei-pan/TSVZ
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -11,6 +11,14 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.6
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
14
22
|
|
|
15
23
|
This lib provides some helper funtions to interact with tsv ( tab seperated values ) files.
|
|
16
24
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: TSVZ
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.70
|
|
4
4
|
Summary: An simple in memory wrapper around a TSV file to function as a database
|
|
5
5
|
Home-page: https://github.com/yufei-pan/TSVZ
|
|
6
6
|
Author: Yufei Pan
|
|
@@ -11,6 +11,14 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.6
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
14
22
|
|
|
15
23
|
This lib provides some helper funtions to interact with tsv ( tab seperated values ) files.
|
|
16
24
|
|
{tsvz-2.67 → tsvz-2.70}/TSVZ.py
RENAMED
|
@@ -10,23 +10,39 @@ if os.name == 'nt':
|
|
|
10
10
|
elif os.name == 'posix':
|
|
11
11
|
import fcntl
|
|
12
12
|
|
|
13
|
-
version = '2.
|
|
13
|
+
version = '2.70'
|
|
14
14
|
author = 'pan@zopyr.us'
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def pretty_format_table(data):
|
|
18
|
+
version = 1.0
|
|
18
19
|
if not data:
|
|
19
|
-
return
|
|
20
|
+
return ''
|
|
20
21
|
if type(data) == str:
|
|
21
22
|
data = data.strip('\n').split('\n')
|
|
23
|
+
data = [line.split('\t') for line in data]
|
|
24
|
+
elif isinstance(data, dict):
|
|
25
|
+
# flatten the 2D dict to a list of lists
|
|
26
|
+
if isinstance(next(iter(data.values())), dict):
|
|
27
|
+
tempData = [['key'] + list(next(iter(data.values())).keys())]
|
|
28
|
+
tempData.extend( [[key] + list(value.values()) for key, value in data.items()])
|
|
29
|
+
data = tempData
|
|
30
|
+
else:
|
|
31
|
+
# it is a dict of lists
|
|
32
|
+
data = [[key] + list(value) for key, value in data.items()]
|
|
22
33
|
elif type(data) != list:
|
|
23
34
|
data = list(data)
|
|
35
|
+
# format the list into 2d list of list of strings
|
|
36
|
+
if isinstance(data[0], dict):
|
|
37
|
+
tempData = [data[0].keys()]
|
|
38
|
+
tempData.extend([list(item.values()) for item in data])
|
|
39
|
+
data = tempData
|
|
40
|
+
data = [[str(item) for item in row] for row in data]
|
|
24
41
|
num_cols = len(data[0])
|
|
25
42
|
col_widths = [0] * num_cols
|
|
26
43
|
# Calculate the maximum width of each column
|
|
27
44
|
for c in range(num_cols):
|
|
28
|
-
|
|
29
|
-
col_widths[c] = max(len(item) for item in col_items)
|
|
45
|
+
col_widths[c] = max(len(row[c]) for row in data)
|
|
30
46
|
# Build the row format string
|
|
31
47
|
row_format = ' | '.join('{{:<{}}}'.format(width) for width in col_widths)
|
|
32
48
|
# Print the header
|
|
@@ -35,7 +51,11 @@ def pretty_format_table(data):
|
|
|
35
51
|
outTable.append(row_format.format(*header))
|
|
36
52
|
outTable.append('-+-'.join('-' * width for width in col_widths))
|
|
37
53
|
for row in data[1:]:
|
|
38
|
-
|
|
54
|
+
# if the row is empty, print an divider
|
|
55
|
+
if not any(row):
|
|
56
|
+
outTable.append('-+-'.join('-' * width for width in col_widths))
|
|
57
|
+
else:
|
|
58
|
+
outTable.append(row_format.format(*row))
|
|
39
59
|
return '\n'.join(outTable) + '\n'
|
|
40
60
|
|
|
41
61
|
def __teePrintOrNot(message,level = 'info',teeLogger = None):
|
|
@@ -225,11 +245,15 @@ def lineContainHeader(header,line,verbose = False,teeLogger = None,strict = Fals
|
|
|
225
245
|
Returns:
|
|
226
246
|
bool: True if the header matches the line, False otherwise.
|
|
227
247
|
"""
|
|
248
|
+
escapedHeader = repr(header.strip())
|
|
249
|
+
escapedLine = repr(line.strip())
|
|
228
250
|
if verbose:
|
|
229
|
-
__teePrintOrNot(f"Header: {
|
|
230
|
-
__teePrintOrNot(f"First line: {
|
|
231
|
-
|
|
232
|
-
|
|
251
|
+
__teePrintOrNot(f"Header: \n{escapedHeader}",teeLogger=teeLogger)
|
|
252
|
+
__teePrintOrNot(f"First line: \n{escapedLine}",teeLogger=teeLogger)
|
|
253
|
+
headerList = header.strip().lower().split('\t')
|
|
254
|
+
lineList = line.strip().lower().split('\t')
|
|
255
|
+
if len(headerList) != len(lineList) or any([headerList[i] not in lineList[i] for i in range(len(headerList))]):
|
|
256
|
+
__teePrintOrNot(f"Header mismatch: \n{escapedLine} \n!= \n{escapedHeader}",teeLogger=teeLogger)
|
|
233
257
|
if strict:
|
|
234
258
|
raise Exception("Data format error! Header mismatch")
|
|
235
259
|
return False
|
|
@@ -333,6 +357,13 @@ def appendTSV(fileName,lineToAppend,teeLogger = None,header = '',createIfNotExis
|
|
|
333
357
|
return
|
|
334
358
|
if type(lineToAppend) == str:
|
|
335
359
|
lineToAppend = lineToAppend.strip().split('\t')
|
|
360
|
+
else:
|
|
361
|
+
for i in range(len(lineToAppend)):
|
|
362
|
+
if type(lineToAppend[i]) != str:
|
|
363
|
+
try:
|
|
364
|
+
lineToAppend[i] = str(lineToAppend[i])
|
|
365
|
+
except Exception as e:
|
|
366
|
+
lineToAppend[i] = str(e)
|
|
336
367
|
|
|
337
368
|
with open(fileName, mode ='r+b')as file:
|
|
338
369
|
correctColumnNum = len(lineToAppend)
|
{tsvz-2.67 → tsvz-2.70}/setup.py
RENAMED
{tsvz-2.67 → tsvz-2.70}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|