Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game meta, data validation and schema #358

Merged
merged 35 commits into from
Oct 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
63fa5d4
Validating games.yaml schema
nikuda Oct 7, 2016
34ffd98
Renamed status key to developement
nikuda Oct 7, 2016
cd27d42
Added requirements.txt and fixed travis-ci build
nikuda Oct 7, 2016
592d7b8
Re-added status key holding playable/unplayable values
nikuda Oct 7, 2016
71d31ba
Added 'complete' value to status key schema
nikuda Oct 7, 2016
dc13bbd
Rename lang 'Java 8' to 'Java'
nikuda Oct 7, 2016
7f1e52f
Updated status/playable schema
nikuda Oct 7, 2016
e752d02
Updated media schema
nikuda Oct 7, 2016
78b73a1
Readme update to match schema changes
nikuda Oct 7, 2016
9ea2a4a
Load games.yaml once only
nikuda Oct 7, 2016
aa28b9e
Improved schema error reporting
nikuda Oct 7, 2016
bebe36c
Added license code validation
nikuda Oct 7, 2016
c041e7a
Validation errors readability improvements
nikuda Oct 7, 2016
e6cf69f
ScummVM data update
nikuda Oct 7, 2016
f608b8b
Added licenses to Doom clones
nikuda Oct 7, 2016
244c453
Allow non handled exceptions to come up
nikuda Oct 8, 2016
ed0e3c0
Added meta key with genre/theme validation
nikuda Oct 8, 2016
7d0ce1e
Display genres/themes as tags
nikuda Oct 8, 2016
7ccbd47
Parse genre/theme meta into game tags
nikuda Oct 8, 2016
883f022
Added genres cloud to html template
nikuda Oct 8, 2016
9862db2
Fix item name rendering with no link
nikuda Oct 8, 2016
c719bdc
Fit large screenshots, remove border
nikuda Oct 8, 2016
5b618a7
Fix all YouTube videos
nikuda Oct 8, 2016
f4b512d
Added vimeo schema and embed
nikuda Oct 8, 2016
7c05929
Remove support for raw media embeds
nikuda Oct 8, 2016
f13858d
Set max screenshot width fix
nikuda Oct 8, 2016
7ef1973
C-Dogs license and genre update
nikuda Oct 8, 2016
98b5a84
Added Survival genre and Cataclysm: Dark Days Ahead game
nikuda Oct 8, 2016
cb79ce2
Added subgenre meta
nikuda Oct 9, 2016
0f3c170
Show subgenre next to game name
nikuda Oct 9, 2016
17f6e80
Fix html rendering bugs
nikuda Oct 9, 2016
1f1c662
Updated image links
nikuda Oct 9, 2016
14b8a42
Rewritten screenshot toggler
nikuda Oct 9, 2016
e79a0dd
Vimeo embed url encoding fix
nikuda Oct 9, 2016
d10eac9
Added Space Station 14
nikuda Oct 9, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/_build/
_build/
.env/
*.pyc
.env

3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ virtualenv:
addons:
ssh_known_hosts: sirius.solovyov.net
install:
- pip install cyrax
- pip install pyyaml
- pip install -r requirements.txt
script:
- cyrax
- test 6000 -lt $(cat _build/index.html | wc -l)
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CYRAX ?= cyrax
build:
$(CYRAX)

install:
pip install -r requirements.txt

update:
git pull
$(CYRAX)
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@ This is a source of [http://osgameclones.com](http://osgameclones.com). Feel
free to submit pull requests to add new games and improve information about
those already in the database.

## How
## Games database

Check `games.yaml` out. All information is inside, and you should more or less
Check [`games.yaml`][games] out. All information is inside, and you should more or less
understand what's going on by reading it. Sorting is alphabetical, with an
exception of ScummVM, just because it's so many games at once.

Simplest way to contribute:
[edit games.yaml](https://github.com/piranha/osgameclones/edit/master/games.yaml),
and then your changes will be submitted as a pull request.
## Add a game

Please refer to [this template](https://github.com/piranha/osgameclones/blob/master/.github/ISSUE_TEMPLATE.md).
Simplest way to contribute is to edit the [`games.yaml`][games] file. Your
changes will be submitted as a pull request.

- `name`/`names`: Name of the original game
- If the game goes under multiple names, or if the clone is inspired by multiple related games, use `names`
- A Wikipedia link is created for the name; if the article link is different, use the syntax `[Name, Name of Wikipedia article]`
- `clones`/`reimplementations`: List the clones/reimplementations under this heading. Multiple clones can be listed.
- `name`: Name of the clone
- `url`: URL of clone main page
- `repo`: (optional) if the clone has an online code repository (e.g. GitHub), link here
- `info`: free text, but try to use terms already used in the list. Should include code details. HTML is supported
- `status`: (string) status of the project (active, halted)
- `license`: (string) project license
- `lang`: (string|list) programming languages used in the project
- `framework`: (string|list) programming frameworks and/or engines used in the project
- `added`: (optional) date when this clone was first added. Newly added clones are highlighted
- `media`: (optional) list of screenshots or videos for the clone
- `image`: URL of an image to display, preferrably a thumbnail
- `url`: (optional) link to a bigger image, when the user clicks the thumbnail
- `raw`: to embed raw HTML, e.g. to embed a video, use this tag followed by raw HTML

Please refer to the [template][template] and the [`schema.yaml`][schema] file
when adding new games.


[games]: https://github.com/piranha/osgameclones/edit/master/games.yaml
[schema]: https://github.com/piranha/osgameclones/edit/master/schema.yaml
[template]: https://github.com/piranha/osgameclones/blob/master/.github/ISSUE_TEMPLATE.md
64 changes: 46 additions & 18 deletions _ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import os.path as op
from datetime import date, timedelta
from collections import OrderedDict
from functools import partial

import yaml
from cyrax import events
from pykwalify.core import Core


def abort(msg):
Expand Down Expand Up @@ -35,8 +37,7 @@ def parse_tag(tag):
return tag.replace(' ', '-').lower()


def parse_tags(entry):
fields = ['status', 'license', 'lang', 'framework']
def parse_tags(entry, fields):
tags = []

for field in fields:
Expand All @@ -49,44 +50,71 @@ def parse_tags(entry):
return tags


def parse_global_tags(site, games, tag):
for game in games:
if tag in game:
if not getattr(site, tag, False):
setattr(site, tag, {})
def parse_global_tags(site, item, tag):
if tag in item:
if not getattr(site, tag, False):
setattr(site, tag, {})

if isinstance(game[tag], basestring):
game[tag] = [game[tag]]
if isinstance(item[tag], basestring):
item[tag] = [item[tag]]

for t in game[tag]:
tagObj = getattr(site, tag, False)
if not tagObj.get(t, False):
tagObj[t] = {'tag_count': 0}
tagObj[t]['tag_count'] += 1
for t in item[tag]:
tagObj = getattr(site, tag, False)
if not tagObj.get(t, False):
tagObj[t] = {'tag_count': 0}
tagObj[t]['tag_count'] += 1

setattr(site, tag, OrderedDict(sorted(getattr(site, tag, {}).items())))


def parse_item(entry):
def parse_item(entry, entry_tags=[], meta={}, meta_tags=[]):
added = entry.get('added') or date(1970, 1, 1)
return dict(entry,
new=(date.today() - added) < timedelta(days=30),
tags=parse_tags(entry))
tags=parse_tags(entry, entry_tags) + parse_tags(meta, meta_tags))


def parse_items(site, item, key):
if key in item and validate(item, key):
if not getattr(site, key, False):
setattr(site, key, [])

parse_global_tags(site, item[key], 'lang')
getattr(site, key).append((names(item), map(parse_item, item[key])))
meta = item.get('meta', {})
meta_tags = ['genre', 'subgenre', 'theme']
game_tags = ['status', 'development', 'license', 'lang', 'framework']
parse_fn = partial(parse_item, entry_tags=game_tags, meta=meta, meta_tags=meta_tags)

for game in item[key]:
parse_global_tags(site, game, 'lang')
getattr(site, key).append((names(item), meta, map(parse_fn, item[key])))


def show_validation_errors(data, errors):
print('\n')
for error in errors:
path = error.path.split('/')
game = data[int(path[1])]
name = game.get('name') or game.get('names')
print('\033[91m' + ' ' + str(name) + '\033[0m')
print(' ' + error.__repr__())
print('\n ' + str(len(errors)) + ' errors\n')
sys.exit(1)


def parse_data(site):
data = yaml.load(file(op.join(op.dirname(__file__), 'games.yaml')))

try:
core = Core(source_data=data, schema_files=['schema.yaml'])
core.validate(raise_exception=True)
except Exception as error:
if len(core.errors) > 0:
show_validation_errors(data, core.errors)
else:
raise error

for item in data:
parse_global_tags(site, item.get('meta', {}), 'genre')
parse_items(site, item, 'clones')
parse_items(site, item, 'reimplementations')

Expand Down
Loading