|
|
|
@ -20,15 +20,15 @@ SQLITE_FILENAME = 'metadata.db'
|
|
|
|
data_path = os.path.join(xdg.BaseDirectory.xdg_data_home, 'lark')
|
|
|
|
data_path = os.path.join(xdg.BaseDirectory.xdg_data_home, 'lark')
|
|
|
|
|
|
|
|
|
|
|
|
def get_sha1sum(filename):
|
|
|
|
def get_sha1sum(filename):
|
|
|
|
sha1sum = hashlib.sha1()
|
|
|
|
sha1sum = hashlib.sha1()
|
|
|
|
with open(filename, 'rb') as file_contents:
|
|
|
|
with open(filename, 'rb') as file_contents:
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
chunk = file_contents.read(HASH_CHUNK_SIZE)
|
|
|
|
chunk = file_contents.read(HASH_CHUNK_SIZE)
|
|
|
|
if not chunk:
|
|
|
|
if not chunk:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
sha1sum.update(chunk)
|
|
|
|
sha1sum.update(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
return sha1sum.hexdigest()
|
|
|
|
return sha1sum.hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
@ -37,16 +37,16 @@ smd_dat = dat(SMD_DAT_PATH)
|
|
|
|
# TODO: Use a proper arg parser.
|
|
|
|
# TODO: Use a proper arg parser.
|
|
|
|
search_dir = sys.argv[1]
|
|
|
|
search_dir = sys.argv[1]
|
|
|
|
for filename in os.listdir(search_dir):
|
|
|
|
for filename in os.listdir(search_dir):
|
|
|
|
# TODO: Ignore or descend into directories.
|
|
|
|
# TODO: Ignore or descend into directories.
|
|
|
|
# TODO: Compare hashes
|
|
|
|
# TODO: Compare hashes
|
|
|
|
file_path = os.path.abspath(os.path.join(search_dir, filename))
|
|
|
|
file_path = os.path.abspath(os.path.join(search_dir, filename))
|
|
|
|
file_sha1 = get_sha1sum(file_path)
|
|
|
|
file_sha1 = get_sha1sum(file_path)
|
|
|
|
search_result = smd_dat.search_by_sha1(file_sha1)
|
|
|
|
search_result = smd_dat.search_by_sha1(file_sha1)
|
|
|
|
if search_result:
|
|
|
|
if search_result:
|
|
|
|
rom_data = search_result[0]
|
|
|
|
rom_data = search_result[0]
|
|
|
|
print('File %s matches database entry for %s.' % (filename, rom_data.filename))
|
|
|
|
print('File %s matches database entry for %s.' % (filename, rom_data.filename))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print('File %s is not in database.' % filename)
|
|
|
|
print('File %s is not in database.' % filename)
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
# Test code! :D
|
|
|
|
# Test code! :D
|
|
|
|
# TODO: Write test code that doesn't depend on external resources.
|
|
|
|
# TODO: Write test code that doesn't depend on external resources.
|
|
|
|
@ -54,12 +54,12 @@ SMD_DAT_PATH = '/home/lumia/Downloads/Sega - Mega Drive - Genesis (20200303-0355
|
|
|
|
TEST_HASH = 'cfbf98c36c776677290a872547ac47c53d2761d6'
|
|
|
|
TEST_HASH = 'cfbf98c36c776677290a872547ac47c53d2761d6'
|
|
|
|
|
|
|
|
|
|
|
|
def _kwargs_parse(kwargs_list):
|
|
|
|
def _kwargs_parse(kwargs_list):
|
|
|
|
kwargs = {}
|
|
|
|
kwargs = {}
|
|
|
|
for kwarg_string in kwargs_list:
|
|
|
|
for kwarg_string in kwargs_list:
|
|
|
|
key, value = kwarg_string.split('=')
|
|
|
|
key, value = kwarg_string.split('=')
|
|
|
|
kwargs[key] = value
|
|
|
|
kwargs[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
return kwargs
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
|
action_object = sys.argv[1]
|
|
|
|
action_object = sys.argv[1]
|
|
|
|
action = sys.argv[2]
|
|
|
|
action = sys.argv[2]
|
|
|
|
@ -68,102 +68,102 @@ metadata.configure(os.path.join(data_path, SQLITE_FILENAME))
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: Use a real UI library. This mess is just intended for development.
|
|
|
|
# TODO: Use a real UI library. This mess is just intended for development.
|
|
|
|
if action_object == 'platform':
|
|
|
|
if action_object == 'platform':
|
|
|
|
if action == 'add':
|
|
|
|
if action == 'add':
|
|
|
|
print('add a platform')
|
|
|
|
print('add a platform')
|
|
|
|
platform_shortcode = sys.argv[3]
|
|
|
|
platform_shortcode = sys.argv[3]
|
|
|
|
platform_name = sys.argv[4]
|
|
|
|
platform_name = sys.argv[4]
|
|
|
|
|
|
|
|
|
|
|
|
platform_data = metadata.Platform(shortcode=platform_shortcode,
|
|
|
|
platform_data = metadata.Platform(shortcode=platform_shortcode,
|
|
|
|
fullname=platform_name)
|
|
|
|
fullname=platform_name)
|
|
|
|
with metadata.get_db_session() as session:
|
|
|
|
with metadata.get_db_session() as session:
|
|
|
|
session.add(platform_data)
|
|
|
|
session.add(platform_data)
|
|
|
|
|
|
|
|
|
|
|
|
elif action == 'list':
|
|
|
|
elif 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
|
|
|
|
# out a good way to include other filters.
|
|
|
|
# out a good way to include other filters.
|
|
|
|
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.Platform, **filters))
|
|
|
|
print(metadata.search(session, metadata.Platform, **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:
|
|
|
|
platforms = metadata.search(session, metadata.Platform, **filters)
|
|
|
|
platforms = metadata.search(session, metadata.Platform, **filters)
|
|
|
|
for platform in platforms:
|
|
|
|
for platform in platforms:
|
|
|
|
print('Removing %s.' % platform.fullname)
|
|
|
|
print('Removing %s.' % platform.fullname)
|
|
|
|
session.delete(platform)
|
|
|
|
session.delete(platform)
|
|
|
|
|
|
|
|
|
|
|
|
elif action == 'test':
|
|
|
|
elif action == 'test':
|
|
|
|
# TODO: Delete this action before merging into dev. It's just for ugly testing.
|
|
|
|
# TODO: Delete this action before merging into dev. It's just for ugly testing.
|
|
|
|
platform_shortcode = sys.argv[3]
|
|
|
|
platform_shortcode = sys.argv[3]
|
|
|
|
platform_name = sys.argv[4]
|
|
|
|
platform_name = sys.argv[4]
|
|
|
|
|
|
|
|
|
|
|
|
platform_data = metadata.Platform(shortcode=platform_shortcode,
|
|
|
|
platform_data = metadata.Platform(shortcode=platform_shortcode,
|
|
|
|
fullname=platform_name)
|
|
|
|
fullname=platform_name)
|
|
|
|
|
|
|
|
|
|
|
|
with metadata.get_db_session() as session:
|
|
|
|
with metadata.get_db_session() as session:
|
|
|
|
print(metadata.search(session, metadata.Platform))
|
|
|
|
print(metadata.search(session, metadata.Platform))
|
|
|
|
|
|
|
|
|
|
|
|
elif action_object == 'release-group':
|
|
|
|
elif action_object == 'release-group':
|
|
|
|
if action == 'add':
|
|
|
|
if action == 'add':
|
|
|
|
properties = _kwargs_parse(sys.argv[3:])
|
|
|
|
properties = _kwargs_parse(sys.argv[3:])
|
|
|
|
release_group = metadata.ReleaseGroup(name=properties['name'])
|
|
|
|
release_group = metadata.ReleaseGroup(name=properties['name'])
|
|
|
|
|
|
|
|
|
|
|
|
with metadata.get_db_session() as session:
|
|
|
|
with metadata.get_db_session() as session:
|
|
|
|
if properties['platform']:
|
|
|
|
if properties['platform']:
|
|
|
|
platform = metadata.search(session, metadata.Platform,
|
|
|
|
platform = metadata.search(session, metadata.Platform,
|
|
|
|
shortcode=properties['platform'])[0]
|
|
|
|
shortcode=properties['platform'])[0]
|
|
|
|
release_group.platform = platform
|
|
|
|
release_group.platform = platform
|
|
|
|
session.add(release_group)
|
|
|
|
session.add(release_group)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
# out a good way to include other filters.
|
|
|
|
# out a good way to include other filters.
|
|
|
|
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.ReleaseGroup, **filters))
|
|
|
|
print(metadata.search(session, metadata.ReleaseGroup, **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.ReleaseGroup, **filters)
|
|
|
|
release_groups = metadata.search(session, metadata.ReleaseGroup, **filters)
|
|
|
|
for release_group in release_groups:
|
|
|
|
for release_group in release_groups:
|
|
|
|
print('Removing %s.' % release_group.name)
|
|
|
|
print('Removing %s.' % release_group.name)
|
|
|
|
session.delete(release_group)
|
|
|
|
session.delete(release_group)
|
|
|
|
|
|
|
|
|
|
|
|
elif action_object == 'release':
|
|
|
|
elif action_object == 'release':
|
|
|
|
if action == 'add':
|
|
|
|
if action == 'add':
|
|
|
|
properties = _kwargs_parse(sys.argv[3:])
|
|
|
|
properties = _kwargs_parse(sys.argv[3:])
|
|
|
|
release = metadata.Release(**properties)
|
|
|
|
release = metadata.Release(**properties)
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
release.release_group = release_group
|
|
|
|
release.release_group = release_group
|
|
|
|
session.add(release)
|
|
|
|
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
|
|
|
|
# out a good way to include other filters.
|
|
|
|
# out a good way to include other filters.
|
|
|
|
print('Listing releases.')
|
|
|
|
print('Listing releases.')
|
|
|
|
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.Release, **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.Release, **filters)
|
|
|
|
release_groups = metadata.search(session, metadata.Release, **filters)
|
|
|
|
for release in release_groups:
|
|
|
|
for release in release_groups:
|
|
|
|
print('Removing %s.' % release.name)
|
|
|
|
print('Removing %s.' % release.name)
|
|
|
|
session.delete(release)
|
|
|
|
session.delete(release)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print('Unknown object.')
|
|
|
|
print('Unknown object.')
|
|
|
|
|