Closed ScriptSlayer0 closed 2 months ago
Hi @Unaiperezdiaz, i like the idea of making the HDF5 handler as a single class, but the other parts of the code would need to be corrected to handle that code before any those updates can be published. Also, can I get a copy of your test file than you're using to get that error with BivitattusView? I will check it out and see if i can trace it.
This file is from the same module "BDB_io.py". test.zip I hope you can trace the problem. :)
it looks like you ran the output file from BDB_io.py
through BivitattusView.py
(onward 'BV'), but BV
is setup to accept a very specific format of the text. Try running the example file ex_auto_commit.py
to see if you get the same error with BV
. Also, the output of BDB_io
is just a tester to see if the code above works, not if it's compatible with the outside code. The code in BivitattusDB.py
, BDB_metadata.py
, and BDB_tb.py
so that they run correctly with the HDF5Handler
class.
I used the example file ex_auto_commit.py
.
And the output was:
Traceback (most recent call last): File "d:\github\bivittatusDB\src\BivitattusDB\ex_auto_commit.py", line 6, in <module> tb1 = test_db.make_table("table1", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\github\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 44, in make_table return self.load_table(name) ^^^^^^^^^^^^^^^^^^^^^ File "d:\github\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 18, in load_table return table(self.database_name, table_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\github\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 12, in __init__ self.__read__() File "d:\github\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 33, in __read__ reader=io.read(self.database) ^^^^^^^ AttributeError: module 'BDB_io' has no attribute 'read' encrypting...
I'm trying to get a fix
Would you like to continue working on it, or should I give it a shot?
I'm working on it, but I have found a strange file output executing ex_auto_commut.py output.zip All file with random numbers.
That's the encrypted database file. I found out on other projects that converting the encrypted text to hexadecimal decreases the risk of corruption or mis-understood directive when it comes to read/sending files. The key should be the password you set when initializing the test
database
After the commit this is the output:
Password for test:
decrypting...
Error reading the database: module 'BDB_io' has no attribute 'read'
No data to show.
encrypting...
When you restructered BDB.io into a class, the other files can't find the functions to read and write correctly. You got to change the read/write/edit functions in the other files so they can read the right code. For example, in BDB_tb.py: This:
def __edit__(self):
'''Change data in database table. Used in the __save__ method'''
editor=io.edit(self.database)
new_data=json.dumps([self.columns]+self.data)
editor.edit_table(self.table_name, new_data)
would need to be:
def __edit__(self):
'''Change data in database table. Used in the __save__ method'''
editor=io.HDF5Handler(self.database)
new_data=json.dumps([self.columns]+self.data)
editor.edit_table(self.table_name, new_data)
Password for test:
decrypting...
Error reading the table table1: Unable to synchronously open file (file signature not found)
No data to show.
encrypting...
it looks like the data is never decompressed when reading the table:
Error loading table table1 from database test: the JSON object must be str, bytes or bytearray, not list
Traceback (most recent call last):
File "c:\Users\malac\Code\Python\Bivattus\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 19, in load_table
return table(self.database_name, table_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\malac\Code\Python\Bivattus\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 13, in __init__
self.__read__()
File "c:\Users\malac\Code\Python\Bivattus\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 47, in __read__
self.data = json.loads(table_data)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\malac\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 339, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not list
umh... this is new when I create a new DB using the example code:
`Password for test:
Error loading table table1 from database test: the JSON object must be str, bytes or bytearray, not list
Traceback (most recent call last):
File "d:\github\bivittatusDB\src\BivitattusDB\ex_auto_commit.py", line 11, in
TypeError: unsupported operand type(s) for @: 'NoneType' and 'bool'
encrypting...`
Yeah, I expanded the first error:
Error loading table table1 from database test: the JSON object must be str, bytes or bytearray, not list
and ditched the second.
Why don't we check the JSON before dumping it? I think that's the best way to understand what's going on.
Because if this JSON has a problem, which we can't see because it is compressed and encrypted, we can't know if there will be more problems or not.
What I think is happening is that when we reload the JSON when reading the data into a newly loaded table, it's not getting decoded and decompressed before being converted back to obj format.
Sometimes it appears: An error occurred: Non-hexadecimal digit found
Yeah, that's unhexlify trying to decode the encryption, but it's finding bytes instead of hexadecimal
So, I found there was a clause to decode and decompress during the read process, and then we were trying to do it again afterwards, which threw an error. I fixed that in both the bdb_tb and bdb_metadata tables, but I've came across another error while reading a already created table, which I am working on currently.
Ok... didn't mean to merge it... but hopefully you can find the error of why it's having problems reopening the file
Also, I just want to let you know, I'm working on a C code that can replace the use of HDF5 files, so this issue may just solve itself.
I have solved the problem to be able to display the ex_auto_commit.py
data.
what about ex_use_table.py
Withex_use_table.py
throws:
Error reading the table Table1: "Unable to synchronously open object (object 'Table1' doesn't exist)"
Yeah, I was getting the same error, I though I'd give it to you to try. Right now I have it committed with this error (by accident) so hopefully we can fix it.
quick tip. you can expand the traceback by importing traceback and adding the line print(traceback.format_exc())
inside the except clause that is causing the error.
I have fixed this error with the modification I have made, because every time you displayed the treeview you got an error message that doesn't appear anymore. But now I don't know how to fix the following. (Using the test file):