mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Implement table creation from the object
This commit is contained in:
parent
3c7a97e904
commit
71c2eec85b
@ -15,6 +15,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import csv
|
||||
import datetime
|
||||
|
||||
|
||||
@ -132,10 +133,16 @@ class CsvDB(object):
|
||||
def table_from_object(self, obj):
|
||||
'''
|
||||
Create a table from the object.
|
||||
NOTE: This method doesn't stores anything.
|
||||
|
||||
:param obj:
|
||||
:return:
|
||||
'''
|
||||
get_type = lambda item: str(type(item)).split("'")[1]
|
||||
if not os.path.exists(os.path.join(self.db_path, obj._TABLE)):
|
||||
with open(os.path.join(self.db_path, obj._TABLE), 'wb') as table_file:
|
||||
csv.writer(table_file).writerow(['{col}:{type}'.format(col=elm[0], type=get_type(elm[1]))
|
||||
for elm in tuple(obj.__dict__.items())])
|
||||
|
||||
def store(self, obj):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user