Renamed Image to Release, removed a redundant function, and updated documentation.

dev
Emily Frost 6 years ago
parent af77353173
commit 7ea5711bcc
No known key found for this signature in database
GPG Key ID: FD1FA524668FB1FA

22
lark

@ -13,8 +13,8 @@ Intended features:
UI notes UI notes
# Key terms # Key terms
- hash Unique identifier for each ROM image. - hash Unique identifier for each ROM release.
- image ROM image, ripped from physical media. - release ROM release, ripped from physical media.
- dat List of hashes, with associated filenames. - dat List of hashes, with associated filenames.
- platform The original hardware on which the image was intended to run. - platform The original hardware on which the image was intended to run.
@ -163,18 +163,18 @@ elif action_object == 'release-group':
print('Removing %s.' % release_group.name) print('Removing %s.' % release_group.name)
session.delete(release_group) session.delete(release_group)
elif action_object == 'image': elif action_object == 'release':
if action == 'add': if action == 'add':
properties = _kwargs_parse(sys.argv[3:]) properties = _kwargs_parse(sys.argv[3:])
image = metadata.Image(filename=properties['filename'], release = metadata.Release(filename=properties['filename'],
sha1sum=properties['sha1sum']) sha1sum=properties['sha1sum'])
with metadata.get_db_session() as session: with metadata.get_db_session() as session:
if properties['release-group']: if properties['release-group']:
release_group = metadata.search(session, metadata.ReleaseGroup, release_group = metadata.search(session, metadata.ReleaseGroup,
name=properties['release-group'])[0] name=properties['release-group'])[0]
image.release_group = release_group release.release_group = release_group
session.add(image) session.add(release)
if action == 'list': if action == 'list':
# TODO: Filter support is exclusively limited to SQLAlchemy's filter.ilike function. Figure # TODO: Filter support is exclusively limited to SQLAlchemy's filter.ilike function. Figure
@ -182,16 +182,16 @@ elif action_object == 'image':
print('Listing release groups.') print('Listing release groups.')
filters = _kwargs_parse(sys.argv[3:]) filters = _kwargs_parse(sys.argv[3:])
with metadata.get_db_session() as session: with metadata.get_db_session() as session:
print(metadata.search(session, metadata.Image, **filters)) print(metadata.search(session, metadata.Release, **filters))
elif action == 'remove': elif action == 'remove':
constraints = sys.argv[3:] constraints = sys.argv[3:]
filters = _kwargs_parse(sys.argv[3:]) filters = _kwargs_parse(sys.argv[3:])
with metadata.get_db_session() as session: with metadata.get_db_session() as session:
release_groups = metadata.search(session, metadata.Image, **filters) release_groups = metadata.search(session, metadata.Release, **filters)
for image in release_groups: for release in release_groups:
print('Removing %s.' % image.name) print('Removing %s.' % release.name)
session.delete(image) session.delete(release)
else: else:
print('Unknown object.') print('Unknown object.')

@ -1,6 +1,6 @@
# Metadata definitions # Metadata definitions
## Release image ## Release
- A single release of a game. For example: Star Fox 64 (U) v1.2 [!] - A single release of a game. For example: Star Fox 64 (U) v1.2
* UUID * UUID
* sha1sum * sha1sum

@ -4,7 +4,6 @@ metadata.py
Everything needed to interact with the metadata database; namely SQL ORM objects, a context Everything needed to interact with the metadata database; namely SQL ORM objects, a context
generator for the actual database, and a handful of convenience functions. generator for the actual database, and a handful of convenience functions.
''' '''
# TODO: Rename file to metadata.py
import contextlib import contextlib
import collections import collections
import hashlib import hashlib
@ -28,8 +27,7 @@ def _uuidgen():
_SQLBase = sqlalchemy.ext.declarative.declarative_base() _SQLBase = sqlalchemy.ext.declarative.declarative_base()
# TODO: Rename Image concept to "Release". class Release(_SQLBase):
class Image(_SQLBase):
'''SQLAlchemy ORM class for ROM image metadata.''' '''SQLAlchemy ORM class for ROM image metadata.'''
# TODO: Split filenames into more meaningful metadata. # TODO: Split filenames into more meaningful metadata.
__tablename__ = 'images' __tablename__ = 'images'
@ -41,7 +39,7 @@ class Image(_SQLBase):
release_group_id = sqlalchemy.Column(sqlalchemy.Integer, release_group_id = sqlalchemy.Column(sqlalchemy.Integer,
sqlalchemy.ForeignKey('release_groups.id')) sqlalchemy.ForeignKey('release_groups.id'))
release_group = sqlalchemy.orm.relationship('ReleaseGroup', back_populates='images') release_group = sqlalchemy.orm.relationship('ReleaseGroup', back_populates='releases')
def __repr__(self): def __repr__(self):
return 'ROM Image: id: %s, uuid: %s, sha1sum: %s, filename: %s, release-group: %s' % ( return 'ROM Image: id: %s, uuid: %s, sha1sum: %s, filename: %s, release-group: %s' % (
@ -57,7 +55,7 @@ class ReleaseGroup(_SQLBase):
platform_id = sqlalchemy.Column(sqlalchemy.Integer, sqlalchemy.ForeignKey('platforms.id')) platform_id = sqlalchemy.Column(sqlalchemy.Integer, sqlalchemy.ForeignKey('platforms.id'))
platform = sqlalchemy.orm.relationship('Platform', back_populates='release_groups') platform = sqlalchemy.orm.relationship('Platform', back_populates='release_groups')
images = sqlalchemy.orm.relationship('Image', back_populates='release_group') images = sqlalchemy.orm.relationship('Release', back_populates='release_group')
def __repr__(self): def __repr__(self):
return 'Release Group: id: %s, uuid: %s, name: %s, platform:%s' % (self.id, self.uuid, return 'Release Group: id: %s, uuid: %s, name: %s, platform:%s' % (self.id, self.uuid,
@ -80,19 +78,6 @@ class Platform(_SQLBase):
return 'Platform: id: %s, uuid: %s, fullname: %s, shortcode: %s' % (self.id, self.uuid, return 'Platform: id: %s, uuid: %s, fullname: %s, shortcode: %s' % (self.id, self.uuid,
self.fullname, self.shortcode) self.fullname, self.shortcode)
# TODO: This should go in the eventual romdb class.
def get_file_sha1sum(filename):
sha1sum = hashlib.sha1()
with open(filename, 'rb') as file_contents:
while True:
chunk = file_contents.read(HASH_CHUNK_SIZE)
if not chunk:
break
sha1sum.update(chunk)
return sha1sum.hexdigest()
def configure(db_path): def configure(db_path):
''' '''
Configure and initialize the database for the entire module. Configure and initialize the database for the entire module.
@ -106,7 +91,6 @@ def configure(db_path):
_db_session_maker.configure(bind=_engine) _db_session_maker.configure(bind=_engine)
# TODO: Passing the session object is a little clunky. Maybe there's a way to infer it somehow? # TODO: Passing the session object is a little clunky. Maybe there's a way to infer it somehow?
# Maybe setting a _session class variable?
def search(session, table_object, **constraints): def search(session, table_object, **constraints):
''' '''
Search the database for entries matching the given constraints. Search the database for entries matching the given constraints.

@ -1,14 +1,14 @@
# Lark # Lark
Lark is a ROM organizer that uses known hash lists to validate and sort ROM files into a library Lark is a ROM organizer that uses known hashes to validate and sort ROM files into a library
directory structure. directory structure.
## Current features ## Current features
* Nothing really works yet. * Basic database editing works.
## Planned features ## Planned features
* Validate ROM images. * Validate ROM images.
* Download DAT files * Import DAT files
* Rename/move ROM files * Rename/move ROM files
* Maintain a database of present ROMs * Maintain a database of present ROMs
* A nice, Beets-like interface * A nice, Beets-like interface

Loading…
Cancel
Save