[game-data-packager] 01/02: rebase, minus acf parser moved in master
Alexandre Detiste
detiste-guest at moszumanska.debian.org
Tue Feb 17 11:17:20 UTC 2015
This is an automated email from the git hooks/post-receive script.
detiste-guest pushed a commit to branch steam
in repository game-data-packager.
commit 8782aae6b086ed4f805a1669b93b492edbed1db5
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date: Wed Feb 11 14:41:22 2015 +0100
rebase, minus acf parser moved in master
---
game_data_packager/steam_wip.py | 217 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 217 insertions(+)
diff --git a/game_data_packager/steam_wip.py b/game_data_packager/steam_wip.py
new file mode 100644
index 0000000..276e0e4
--- /dev/null
+++ b/game_data_packager/steam_wip.py
@@ -0,0 +1,217 @@
+#!/usr/bin/python3
+# vim:set fenc=utf-8:
+#
+# Copyright © 2015 Alexandre Detiste <alexandre at detiste.be>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# You can find the GPL license text on a Debian system under
+# /usr/share/common-licenses/GPL-2.
+
+import os
+import glob
+import yaml
+import argparse
+import logging
+import urllib.request
+import xml.etree.ElementTree
+
+from . import GameData,load_yaml_games,rm_rf
+from .paths import DATADIR
+from .steam import parse_acf
+
+logging.basicConfig()
+logger = logging.getLogger('steam.py')
+
+if os.environ.get('DEBUG'):
+ logging.getLogger().setLevel(logging.DEBUG)
+else:
+ logging.getLogger().setLevel(logging.INFO)
+
+
+STEAMDIRS = ['~/.steam',
+ '~/.wine/drive_c/Program Files/Steam',
+ '~/.PlayOnLinux/wineprefix/Steam/drive_c/Program Files/Steam']
+
+games = []
+for yaml_file in sorted(glob.glob(DATADIR + '/*.yaml')):
+ shortname = os.path.splitext(os.path.basename(yaml_file))[0]
+ yaml_data = yaml.load(open(yaml_file))
+ with GameData(shortname,yaml_data) as gamedata:
+ logger.debug('G: %s: %s' % (shortname, str(gamedata.steam)))
+ for package in gamedata.packages.values():
+ logger.debug('P: %s: %s' % (package.name, str(package.steam)))
+ if 'path' in package.steam:
+ steam_suffix = package.steam['path']
+ steam_id = package.steam['id']
+ elif 'path' in gamedata.steam:
+ steam_suffix = gamedata.steam['path']
+ steam_id = gamedata.steam['id']
+ else:
+ continue
+
+ type_order = { 'full' : 1,
+ 'expansion' : 2,
+ 'demo' : 3
+ }.get(package.type)
+
+ steam_path = None
+ steam_date = 0
+ for dir in STEAMDIRS:
+ check_path = os.path.expanduser(dir) + '/SteamApps/' + steam_suffix
+ if os.path.isdir(check_path):
+ steam_path = check_path
+ steam_date = os.stat(steam_path).st_mtime
+ continue
+
+ game_struct = {
+ 'shortname' : shortname,
+ 'type' : package.type,
+ 'type_order' : type_order,
+ 'package': package.name,
+ 'installed': os.path.isdir('/usr/share/doc/' + package.name),
+ 'longname': package.longname if package.longname else gamedata.longname,
+ 'steam_path': steam_path,
+ 'steam_id': steam_id,
+ 'steam_date': steam_date,
+ }
+ if package.type != 'demo':
+ games.append(game_struct)
+
+games = sorted(games, key=lambda k: (k['shortname'], k['type_order'], k['longname']))
+
+def show(games,args):
+ print('steam packages supported:')
+ printed = []
+ for game in games:
+ if game['shortname'] not in printed:
+ print('\t%16s\t%s' % (game['shortname'], game['longname']))
+ printed.append(game['shortname'])
+ else:
+ print('\t\t\t\t%s' % game['longname'])
+
+def install(todos,args):
+ print('building %s:' % todos)
+ if args.dryrun:
+ exit(0)
+
+ games = load_yaml_games(os.environ.get('WORKDIR', None))
+ all_debs = set()
+ for todo in todos:
+ print(todo)
+ with games[todo] as game:
+ game.look_for_files()
+ packages = set(game.packages.values())
+ ready = game.prepare_packages(packages)
+ debs = game.build_packages(ready, destination='.', compress=True)
+ all_debs = all_debs.union(debs)
+ rm_rf(os.path.join(game.get_workdir(), 'tmp'))
+ for deb in debs:
+ print('generated "%s"' % os.path.abspath(deb))
+
+ assert all_debs, 'at least a .deb should have been generated'
+ # call su once
+ # my OOP sucks
+ with games['rott'] as game:
+ game.install_packages(all_debs)
+
+def last(games,args):
+ games = sorted(games, key=lambda k: (-k['steam_date']))
+ for game in games:
+ logger.debug("%s: %s" % (game['package'], game['steam_date']))
+ if not game['installed'] and game['steam_path']:
+ install(set([game['shortname']]),args)
+ exit(0)
+ exit('No new game to install')
+
+
+def new(games,args):
+ todo = set()
+ for game in games:
+ if game['steam_path'] and not game['installed']:
+ todo.add(game['shortname'])
+ if todo:
+ install(todo,args)
+ else:
+ print('No new game to install')
+
+def all(games,args):
+ todo = set()
+ for game in games:
+ if game['steam_path']:
+ todo.add(game['shortname'])
+ if todo:
+ install(todo,args)
+ else:
+ exit("Couldn't find any game to install")
+
+def parse(games,args):
+ acf = []
+ for dir in STEAMDIRS:
+ apps = os.path.expanduser(dir) + '/SteamApps'
+ if os.path.isdir(apps):
+ for acf_struct in parse_acf(apps):
+ acf.append(acf_struct)
+
+ acf = sorted(acf, key=lambda k: (k['name']))
+ for record in acf:
+ print(record)
+
+def owned(games,args):
+ url = "http://steamcommunity.com/id/" + os.environ.get('STEAM_ID', 'sir_dregan') + "/games?xml=1"
+ html = urllib.request.urlopen(url)
+ tree = xml.etree.ElementTree.ElementTree()
+ tree.parse(html)
+ games_xml = tree.getiterator('game')
+ owned = {}
+ for game in games_xml:
+ appid = int(game.find('appID').text)
+ name = game.find('name').text
+ for supported in games:
+ if supported['steam_id'] == appid:
+ owned[appid] = name
+ for k in owned:
+ print("%-9s %s" % (k, owned[k]))
+
+args_parser = argparse.ArgumentParser(description='manage your Steam collection with game-data-packager')
+
+group = args_parser.add_mutually_exclusive_group()
+
+group.add_argument('-s', '--show', dest='action', action='store_const', const='show',
+ help='Show games supported')
+group.add_argument('-l', '--last', dest='action', action='store_const', const='last',
+ help='Package newest game')
+group.add_argument('-n', '--new', dest='action', action='store_const', const='new',
+ help='Package all new games')
+group.add_argument('-a', '--all', dest='action', action='store_const', const='all',
+ help='Package all games')
+group.add_argument('-p', '--parse', dest='action', action='store_const', const='parse',
+ help="Parse Steam manifest data")
+group.add_argument('-o', '--owned', dest='action', action='store_const', const='owned',
+ help="List the games you own, set your STEAM_ID first")
+
+args_parser.add_argument('-d', '--dry-run', dest='dryrun', action='store_true',
+ help="Dry-run, don't really package anything")
+
+args = args_parser.parse_args()
+
+if not getattr(args, 'action', None):
+ args_parser.print_help()
+ print()
+
+action = {'show': show,
+ 'last': last,
+ 'new': new,
+ 'all': all,
+ 'parse': parse,
+ 'owned': owned,
+ }.get(args.action, show)
+
+action(games,args)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git
More information about the Pkg-games-commits
mailing list