|
|
|
@ -2,6 +2,7 @@
|
|
|
|
hashdb.py
|
|
|
|
hashdb.py
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
import collections
|
|
|
|
import collections
|
|
|
|
|
|
|
|
import dataclasses
|
|
|
|
import hashlib
|
|
|
|
import hashlib
|
|
|
|
import sqlite3
|
|
|
|
import sqlite3
|
|
|
|
import uuid
|
|
|
|
import uuid
|
|
|
|
@ -16,9 +17,27 @@ SQL_OR = ' OR '
|
|
|
|
# TODO: UUID generation/editing is probably best done in here.
|
|
|
|
# TODO: UUID generation/editing is probably best done in here.
|
|
|
|
ImageData = collections.namedtuple('ImageData', 'UUID, sha1sum, filename, release_group')
|
|
|
|
ImageData = collections.namedtuple('ImageData', 'UUID, sha1sum, filename, release_group')
|
|
|
|
ReleaseGroupData = collections.namedtuple('ReleaseGroupData', 'UUID, name, platform')
|
|
|
|
ReleaseGroupData = collections.namedtuple('ReleaseGroupData', 'UUID, name, platform')
|
|
|
|
PlatformData = collections.namedtuple('PlatformData', 'UUID, name, shortcode')
|
|
|
|
|
|
|
|
DatData = collections.namedtuple('DatData', 'UUID, name, website, version, image_list')
|
|
|
|
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.
|
|
|
|
# TODO: This should go in the eventual romdb class.
|
|
|
|
def get_file_sha1sum(filename):
|
|
|
|
def get_file_sha1sum(filename):
|
|
|
|
sha1sum = hashlib.sha1()
|
|
|
|
sha1sum = hashlib.sha1()
|
|
|
|
@ -102,8 +121,10 @@ class MetadataDB:
|
|
|
|
|
|
|
|
|
|
|
|
def add_platform(self, platform_data):
|
|
|
|
def add_platform(self, platform_data):
|
|
|
|
''' Add a platform shortcode to the database. '''
|
|
|
|
''' Add a platform shortcode to the database. '''
|
|
|
|
|
|
|
|
values = list(dataclasses.asdict(platform_data).values())
|
|
|
|
|
|
|
|
print(values)
|
|
|
|
with self._connection:
|
|
|
|
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):
|
|
|
|
def update_platform(self, platform_data):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|