|
7 | 7 | import hecdss.record_type |
8 | 8 | from hecdss.array_container import ArrayContainer |
9 | 9 | from hecdss.location_info import LocationInfo |
| 10 | +from hecdss.text import Text |
10 | 11 | from hecdss.paired_data import PairedData |
11 | 12 | from hecdss.native import _Native |
12 | 13 | from hecdss.dateconverter import DateConverter |
@@ -59,12 +60,18 @@ def __exit__(self, exc_type, exc_val, exc_tb): |
59 | 60 | def set_global_debug_level(level: int) -> None: |
60 | 61 | """ |
61 | 62 | Sets the library debug level |
62 | | -
|
63 | 63 | Args: |
64 | | - level (int): a value between 0 and 15. Larger for more output. |
65 | | - For level descriptions, see zdssMessages.h of the heclib source code, |
66 | | - or documentation from the HEC-DSS Programmers Guide for C on the `mlvl` parameter of the `zset` utility function. |
| 64 | + level (int): HEC-DSS message level (0-15) |
| 65 | + 0: No messages (not recommended) |
| 66 | + 1: Critical errors only |
| 67 | + 2: Terse output (errors + file operations) |
| 68 | + 3: General log messages (default) |
| 69 | + 4: User diagnostic messages |
| 70 | + 5: Internal debug level 1 (not recommended for users) |
| 71 | + 6: Internal debug level 2 (full debug) |
| 72 | + 7-15: Extended debug levels |
67 | 73 | """ |
| 74 | + # Set the native DLL level (controls what gets written) |
68 | 75 | _Native().hec_dss_set_debug_level(level) |
69 | 76 | def close(self): |
70 | 77 | """closes the DSS file and releases any locks |
@@ -123,8 +130,32 @@ def get(self, pathname: str, startdatetime=None, enddatetime=None, trim=False): |
123 | 130 | return self._get_array(pathname) |
124 | 131 | elif type == RecordType.LocationInfo: |
125 | 132 | return self._get_location_info(pathname) |
| 133 | + elif type == RecordType.Text: |
| 134 | + return self._get_text(pathname) |
126 | 135 | return None |
127 | 136 |
|
| 137 | + def _get_text(self, pathname: str): |
| 138 | + textLength = 1024 |
| 139 | + |
| 140 | + |
| 141 | + BUFFER_TOO_SMALL = -1 |
| 142 | + textArray = [] |
| 143 | + status = self._native.hec_dss_textRetrieve(pathname, textArray, textLength) |
| 144 | + while status == BUFFER_TOO_SMALL: |
| 145 | + textLength *= 2 |
| 146 | + status = self._native.hec_dss_textRetrieve(pathname, textArray, textLength) |
| 147 | + if textLength > 2*1048576: # 2 MB |
| 148 | + print(f"Text record too large to read from '{pathname}'") |
| 149 | + return None |
| 150 | + |
| 151 | + if status != 0: |
| 152 | + print(f"Error reading text from '{pathname}'") |
| 153 | + return None |
| 154 | + text = Text() |
| 155 | + text.id = pathname |
| 156 | + text.text = textArray[0] |
| 157 | + return text |
| 158 | + |
128 | 159 | def _get_array(self, pathname: str): |
129 | 160 | intValuesCount = [0] |
130 | 161 | floatValuesCount = [0] |
@@ -627,6 +658,10 @@ def put(self, container) -> int: |
627 | 658 | elif type(container) is LocationInfo: |
628 | 659 | status = self._native.hec_dss_locationStore(container,1) |
629 | 660 | self._catalog = None |
| 661 | + elif type(container) is Text: |
| 662 | + text = container |
| 663 | + status = self._native.hec_dss_textStore(text.id, text.text, len(text.text)) |
| 664 | + self._catalog = None |
630 | 665 | else: |
631 | 666 | raise NotImplementedError(f"unsupported record_type: {type(container)}. Expected types are: {RecordType.SUPPORTED_RECORD_TYPES.value}") |
632 | 667 |
|
|
0 commit comments