TSVZ 3.11__py3-none-any.whl → 3.13__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.
- {TSVZ-3.11.dist-info → TSVZ-3.13.dist-info}/METADATA +1 -1
- TSVZ-3.13.dist-info/RECORD +6 -0
- TSVZ.py +48 -18
- TSVZ-3.11.dist-info/RECORD +0 -6
- {TSVZ-3.11.dist-info → TSVZ-3.13.dist-info}/WHEEL +0 -0
- {TSVZ-3.11.dist-info → TSVZ-3.13.dist-info}/entry_points.txt +0 -0
- {TSVZ-3.11.dist-info → TSVZ-3.13.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
TSVZ.py,sha256=ZCz71rVpAkeVxrN4vBFS7rdZJmkAtEQNatH83b7JMsM,66962
|
|
2
|
+
TSVZ-3.13.dist-info/METADATA,sha256=awkcZiJKtAnfJ9kuGt58o3bvzgweZx7ZTZjUPpYG6fU,1826
|
|
3
|
+
TSVZ-3.13.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
4
|
+
TSVZ-3.13.dist-info/entry_points.txt,sha256=WeXidyV5yKCRLaVsnAY35xGa08QgytOfvr1CK9aescI,60
|
|
5
|
+
TSVZ-3.13.dist-info/top_level.txt,sha256=OPx4LvOpaYykaos7oL_jGaObSWXxLzhHiWLuz-K147g,5
|
|
6
|
+
TSVZ-3.13.dist-info/RECORD,,
|
TSVZ.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
+
# /// script
|
|
3
|
+
# requires-python = ">=3.6"
|
|
4
|
+
# dependencies = [
|
|
5
|
+
# ]
|
|
6
|
+
# ///
|
|
2
7
|
import os , sys
|
|
3
8
|
from collections import OrderedDict , deque
|
|
4
9
|
import time
|
|
@@ -17,7 +22,8 @@ if os.name == 'nt':
|
|
|
17
22
|
elif os.name == 'posix':
|
|
18
23
|
import fcntl
|
|
19
24
|
|
|
20
|
-
version = '3.
|
|
25
|
+
version = '3.13'
|
|
26
|
+
__version__ = version
|
|
21
27
|
author = 'pan@zopyr.us'
|
|
22
28
|
|
|
23
29
|
DEFAULT_DELIMITER = '\t'
|
|
@@ -591,22 +597,45 @@ def appendTabularFile(fileName,lineToAppend,teeLogger = None,header = '',createI
|
|
|
591
597
|
- Exception: If the file does not exist and createIfNotExist is False.
|
|
592
598
|
- Exception: If the existing header does not match the provided header.
|
|
593
599
|
"""
|
|
600
|
+
return appendLinesTabularFile(fileName,[lineToAppend],teeLogger = teeLogger,header = header,createIfNotExist = createIfNotExist,verifyHeader = verifyHeader,verbose = verbose,encoding = encoding, strict = strict, delimiter = delimiter)
|
|
601
|
+
|
|
602
|
+
def appendLinesTabularFile(fileName,linesToAppend,teeLogger = None,header = '',createIfNotExist = False,verifyHeader = True,verbose = False,encoding = 'utf8', strict = True, delimiter = ...):
|
|
603
|
+
"""
|
|
604
|
+
Append lines of data to a Tabular file.
|
|
605
|
+
Parameters:
|
|
606
|
+
- fileName (str): The path of the Tabular file.
|
|
607
|
+
- linesToAppend (list): The lines of data to append. If it is a list of string, then each string will be split by delimiter to form a list.
|
|
608
|
+
- teeLogger (optional): A logger object for logging messages.
|
|
609
|
+
- header (str, optional): The header line to verify against. If provided, the function will check if the existing header matches the provided header.
|
|
610
|
+
- createIfNotExist (bool, optional): If True, the file will be created if it does not exist. If False and the file does not exist, an exception will be raised.
|
|
611
|
+
- verifyHeader (bool, optional): If True, the function will verify if the existing header matches the provided header. If False, the header will not be verified.
|
|
612
|
+
- verbose (bool, optional): If True, additional information will be printed during the execution.
|
|
613
|
+
- encoding (str, optional): The encoding of the file.
|
|
614
|
+
- strict (bool, optional): If True, the function will raise an exception if there is a data format error. If False, the function will ignore the error and continue.
|
|
615
|
+
- delimiter (str, optional): The delimiter used in the Tabular file. Defaults to '\t' for TSV, ',' for CSV, '\0' for NSV.
|
|
616
|
+
Raises:
|
|
617
|
+
- Exception: If the file does not exist and createIfNotExist is False.
|
|
618
|
+
- Exception: If the existing header does not match the provided header.
|
|
619
|
+
"""
|
|
594
620
|
delimiter = get_delimiter(delimiter,file_name=fileName)
|
|
595
621
|
header = _formatHeader(header,verbose = verbose,teeLogger = teeLogger,delimiter=delimiter)
|
|
596
622
|
if not _verifyFileExistence(fileName,createIfNotExist = createIfNotExist,teeLogger = teeLogger,header = header,encoding = encoding,strict = strict,delimiter=delimiter):
|
|
597
623
|
return
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
624
|
+
formatedLines = []
|
|
625
|
+
for line in linesToAppend:
|
|
626
|
+
if type(line) == str:
|
|
627
|
+
line = line.split(delimiter)
|
|
628
|
+
else:
|
|
629
|
+
for i in range(len(line)):
|
|
630
|
+
if type(line[i]) != str:
|
|
631
|
+
try:
|
|
632
|
+
line[i] = str(line[i])
|
|
633
|
+
except Exception as e:
|
|
634
|
+
line[i] = str(e)
|
|
635
|
+
formatedLines.append(line)
|
|
607
636
|
|
|
608
637
|
with open(fileName, mode ='r+b')as file:
|
|
609
|
-
correctColumnNum = len(
|
|
638
|
+
correctColumnNum = max([len(line) for line in formatedLines])
|
|
610
639
|
if header.rstrip():
|
|
611
640
|
if verifyHeader:
|
|
612
641
|
line = file.readline().decode(encoding=encoding)
|
|
@@ -614,18 +643,19 @@ def appendTabularFile(fileName,lineToAppend,teeLogger = None,header = '',createI
|
|
|
614
643
|
correctColumnNum = len(header.split(delimiter))
|
|
615
644
|
if verbose:
|
|
616
645
|
__teePrintOrNot(f"correctColumnNum: {correctColumnNum}",teeLogger=teeLogger)
|
|
617
|
-
# truncate / fill the
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
646
|
+
# truncate / fill the lines to the correct number of columns
|
|
647
|
+
for i in range(len(formatedLines)):
|
|
648
|
+
if len(formatedLines[i]) < correctColumnNum:
|
|
649
|
+
formatedLines[i] += ['']*(correctColumnNum-len(formatedLines[i]))
|
|
650
|
+
elif len(formatedLines[i]) > correctColumnNum:
|
|
651
|
+
formatedLines[i] = formatedLines[i][:correctColumnNum]
|
|
622
652
|
# check if the file ends in a newline
|
|
623
653
|
file.seek(-1, os.SEEK_END)
|
|
624
654
|
if file.read(1) != b'\n':
|
|
625
655
|
file.write(b'\n')
|
|
626
|
-
file.write(
|
|
656
|
+
file.write(b'\n'.join([delimiter.join(line).encode(encoding=encoding) for line in formatedLines]) + b'\n')
|
|
627
657
|
if verbose:
|
|
628
|
-
__teePrintOrNot(f"Appended {
|
|
658
|
+
__teePrintOrNot(f"Appended {len(formatedLines)} lines to {fileName}",teeLogger=teeLogger)
|
|
629
659
|
|
|
630
660
|
def clearTSV(fileName,teeLogger = None,header = '',verifyHeader = False,verbose = False,encoding = 'utf8',strict = False,delimiter = '\t'):
|
|
631
661
|
"""
|
TSVZ-3.11.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
TSVZ.py,sha256=FWLiXvU0sQhDr7yCNl5gGM4eYqMXV7QfnA6ZgWQ3aY0,64806
|
|
2
|
-
TSVZ-3.11.dist-info/METADATA,sha256=wTmWgGYLCDIhLsS7Rm1IIllV44vAe3EYIKFPJQExwbg,1826
|
|
3
|
-
TSVZ-3.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
4
|
-
TSVZ-3.11.dist-info/entry_points.txt,sha256=WeXidyV5yKCRLaVsnAY35xGa08QgytOfvr1CK9aescI,60
|
|
5
|
-
TSVZ-3.11.dist-info/top_level.txt,sha256=OPx4LvOpaYykaos7oL_jGaObSWXxLzhHiWLuz-K147g,5
|
|
6
|
-
TSVZ-3.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|