Compare commits
No commits in common. 'metadata-restructure' and 'dev' have entirely different histories.
metadata-r
...
dev
@ -0,0 +1,62 @@
|
||||
import xml.etree.ElementTree
|
||||
import hashdb
|
||||
|
||||
class DatImportError(Exception):
|
||||
'''This error is raised when a DAT import fails.'''
|
||||
|
||||
# TODO: l o g g i n g
|
||||
|
||||
# TODO: Consider using a context object to avoid keeping large XML trees in memory.
|
||||
class Dat:
|
||||
'''A Dat object processes DAT files into the data structures defined in hashdb. '''
|
||||
def __init__(self, filename):
|
||||
'''Open the given DAT file and gather metadata from it.'''
|
||||
|
||||
xml_tree = xml.etree.ElementTree.parse(filename)
|
||||
self._xml_root = xml_tree.getroot()
|
||||
|
||||
dat_header = self._xml_root.find('header')
|
||||
self.info = hashdb.DatInfo(name=dat_header.find('name').text,
|
||||
description=dat_header.find('description').text,
|
||||
platform=None,
|
||||
version=dat_header.find('version').text)
|
||||
|
||||
def set_platform(self, platform_info):
|
||||
'''
|
||||
Set a platform for this DAT file.
|
||||
DAT files don't include platform metadata, but are all platform-specific.
|
||||
'''
|
||||
new_info = hashdb.DatInfo(name=self.info.name,
|
||||
description=self.info.description,
|
||||
platform=platform_info.shortcode,
|
||||
version=self.info.version)
|
||||
self.info = new_info
|
||||
|
||||
def set_name(self, new_name):
|
||||
'''
|
||||
Override the DAT file's name.
|
||||
DAT files often have less-than-helpful names.
|
||||
'''
|
||||
new_info = hashdb.DatInfo(name=new_name,
|
||||
description=self.info.description,
|
||||
platform=self.info.platform,
|
||||
version=self.info.version)
|
||||
self.info = new_info
|
||||
|
||||
def read_all_hashes(self):
|
||||
'''Read every hash in the DAT file and return it as a large list of RomInfo tuples.'''
|
||||
if self.info.platform is None:
|
||||
raise DatImportError('DAT platform not set.')
|
||||
|
||||
rom_info_list = []
|
||||
all_rom_entries = self._xml_root.findall('.//rom')
|
||||
|
||||
for rom in all_rom_entries:
|
||||
rom_info = hashdb.RomInfo(sha1sum=rom.get('sha1'),
|
||||
filename=rom.get('name'),
|
||||
platform=self.info.platform,
|
||||
datorigin=self.info.name)
|
||||
|
||||
rom_info_list.append(rom_info)
|
||||
|
||||
return rom_info_list
|
||||
@ -1,79 +1,41 @@
|
||||
# Metadata definitions
|
||||
|
||||
## Platform
|
||||
A single set of hardware and/or software that shares compatibility. For example:
|
||||
- Nintendo Entertainment System
|
||||
- Microsoft Windows 7
|
||||
- Microsoft Windows 98
|
||||
|
||||
* name
|
||||
- The English name of the platform. As with release group names, this is mostly for
|
||||
hand-editing data.
|
||||
* regional_names
|
||||
- A hash map with the keys being language identifers (en-US, jp, fr, etc) and the values
|
||||
being the platform's name in the language and script it was released in.
|
||||
* shortcode
|
||||
- A small, three to five letter code for the platform. This must be unique among other
|
||||
platforms.
|
||||
* release groups
|
||||
- A list containing release groups for this platform.
|
||||
|
||||
## Release group
|
||||
A container for all languages and versions of a release. For example, the Star Fox 64 release
|
||||
group would contain all of the following releases:
|
||||
- Star Fox 64 (U) v1.2
|
||||
- Star Fox 64 (U) v1.0
|
||||
- Star Fox 64 (J) v1.0
|
||||
- Lylat Wars (E) v1.0
|
||||
|
||||
* name
|
||||
- The English name for the release group. This is largely for contributors to quickly
|
||||
understand the raw data, as frontends should ideally pull the name from a configured
|
||||
region or something.
|
||||
* releases
|
||||
- A list containing all releases in this release group.
|
||||
|
||||
## 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
|
||||
|
||||
* name
|
||||
- The release's name in the language and script it was released in.
|
||||
* UUID
|
||||
* sha1sum
|
||||
* format (For now this is just the file extension)
|
||||
* region
|
||||
- The official release code for the game.
|
||||
* version
|
||||
- The release version of the game. Some are verison numbers, some are just sequential
|
||||
release numbers.
|
||||
* disambiguation (can be empty)
|
||||
- If this release is different in a way that isn't region or version, that information goes
|
||||
here.
|
||||
* images
|
||||
- A list of all images of this release.
|
||||
## Image
|
||||
A stored copy of a game's disk image. For example:
|
||||
- Star Fox 64 (U) v1.2.z64
|
||||
- Star Fox 64 (U) v1.2.v64
|
||||
|
||||
* format
|
||||
- The format this image is stored in. For example: bin, iso, chd, z64, v64
|
||||
* sha1sum
|
||||
- The sha1sum hash of this specific image.
|
||||
* dump credit
|
||||
- Where the hash came from, who dumped it, etc
|
||||
* patches (can be empty)
|
||||
- A list of patches that are intended to apply to this image.
|
||||
|
||||
## Patches
|
||||
Unofficial patches or mods for a game, usually called romhacks.
|
||||
* disambiguation
|
||||
* release group
|
||||
|
||||
## Release group
|
||||
- A container for all versions of a release.
|
||||
For example, the Star Fox 64 release group would contain:
|
||||
Star Fox 64 (U) v1.2
|
||||
Star Fox 64 (U) v1.0
|
||||
Star Fox 64 (J) v1.0
|
||||
etc.
|
||||
|
||||
* UUID
|
||||
* name
|
||||
- The patch's name in it's original language.
|
||||
* file sha1sum
|
||||
- The patch file's sha1sum.
|
||||
* platform
|
||||
|
||||
# Design notes
|
||||
## Platform
|
||||
- A single set of hardware and/or software that shares compatibility
|
||||
Examples:
|
||||
Nintendo Entertainment System
|
||||
Microsoft Windows 7
|
||||
Microsoft Windows 98
|
||||
|
||||
* This spec is designed with the intent to be imported into databases while also being reasonably
|
||||
hand-editable for contributors.
|
||||
* UUID
|
||||
* name
|
||||
* shortcode
|
||||
|
||||
* Releases have multiple images to account for different formats. The z64 and v64 images of the
|
||||
same N64 game are different files with different hashes.
|
||||
## DAT credits
|
||||
- A large list of hashes imported from other sources.
|
||||
* DAT name
|
||||
* DAT website
|
||||
* DAT version
|
||||
* image UUID list
|
||||
|
||||
Loading…
Reference in New Issue