diff --git a/hashdb.py b/hashdb.py index d85efbb..65eda7c 100644 --- a/hashdb.py +++ b/hashdb.py @@ -2,6 +2,7 @@ hashdb.py ''' import collections +import dataclasses import hashlib import sqlite3 import uuid @@ -16,9 +17,27 @@ SQL_OR = ' OR ' # TODO: UUID generation/editing is probably best done in here. ImageData = collections.namedtuple('ImageData', 'UUID, sha1sum, filename, release_group') ReleaseGroupData = collections.namedtuple('ReleaseGroupData', 'UUID, name, platform') -PlatformData = collections.namedtuple('PlatformData', 'UUID, name, shortcode') DatData = collections.namedtuple('DatData', 'UUID, name, website, version, image_list') +def _uuidgen(): + return str(uuid.uuid4()) + +@dataclasses.dataclass +class BaseMetaData: + #TODO: See below + ''' + Move the uuid property in here once this bug gets fixed. + https://bugs.python.org/issue36077 + + Inheriting properties with default values is currently kind of broken. + ''' + +@dataclasses.dataclass +class PlatformData(BaseMetaData): + name: str + shortcode: str + uuid: str = dataclasses.field(default_factory=_uuidgen) + # TODO: This should go in the eventual romdb class. def get_file_sha1sum(filename): sha1sum = hashlib.sha1() @@ -102,8 +121,10 @@ class MetadataDB: def add_platform(self, platform_data): ''' Add a platform shortcode to the database. ''' + values = list(dataclasses.asdict(platform_data).values()) + print(values) with self._connection: - self._connection.execute('INSERT INTO platforms VALUES (?, ?, ?);', platform_data) + self._connection.execute('INSERT INTO platforms VALUES (?, ?, ?);', values) def update_platform(self, platform_data): pass diff --git a/lark b/lark index 42c068e..d818fc8 100755 --- a/lark +++ b/lark @@ -38,7 +38,7 @@ import os import uuid import xdg.BaseDirectory -import dat +#import dat import hashdb HASH_CHUNK_SIZE = 10485760 # 10mb @@ -85,30 +85,42 @@ action = sys.argv[2] db = hashdb.MetadataDB(os.path.join(data_path, SQLITE_FILENAME)) -# TODO: Use a real UI library. This one is just intended for development. +# TODO: Use a real UI library. This mess is just intended for development. if action_object == 'platform': if action == 'add': print('add a platform') - platform_uuid = uuid.uuid4() platform_shortcode = sys.argv[3] platform_name = sys.argv[4] - platform_data = hashdb.PlatformData(UUID=str(platform_uuid), shortcode=platform_shortcode, + platform_data = hashdb.PlatformData(shortcode=platform_shortcode, name=platform_name) print(platform_data) db.add_platform(platform_data) - if action == 'list': + elif action == 'list': # TODO: convert this into a dict before passing. # TODO: Abstract out constraint parsing etc. constraints = sys.argv[3:] platform_results = db.search_platforms() print(platform_results) - if action == 'remove': + elif action == 'remove': constraints = sys.argv[3:] db.remove_platform(constraints) + + elif action == 'test': + # TODO: Delete this action before merging into dev. It's just for ugly testing. + platform_shortcode = sys.argv[3] + platform_name = sys.argv[4] + + platform_data = hashdb.PlatformData(shortcode=platform_shortcode, + name=platform_name) + + import dataclasses + print(dataclasses.asdict(platform_data).values()) + + else: print('Unknown object.')