[game-data-packager] 11/18: Teach the Python code to read game-data-packager.conf
Simon McVittie
smcv at debian.org
Thu Jan 22 12:40:41 UTC 2015
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository game-data-packager.
commit b441099e24dc55f9b338a78041aa2efc288f068f
Author: Simon McVittie <smcv at debian.org>
Date: Thu Jan 22 11:09:58 2015 +0000
Teach the Python code to read game-data-packager.conf
---
lib/game_data_packager/__init__.py | 9 ++++++
lib/game_data_packager/config.py | 64 ++++++++++++++++++++++++++++++++++++++
lib/game_data_packager/paths.py | 2 ++
3 files changed, 75 insertions(+)
diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index 71e30cf..2c0cc69 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -41,6 +41,7 @@ import zipfile
from debian.deb822 import Deb822
import yaml
+from .config import read_config
from .paths import DATADIR, ETCDIR
from .util import (MEBIBYTE,
TemporaryUmask,
@@ -2295,6 +2296,7 @@ def run_command_line():
for g in sorted(games.keys()):
games[g].add_parser(game_parsers, base_parser)
+ config = read_config()
parsed = argparse.Namespace(
compress=None,
destination=None,
@@ -2305,6 +2307,13 @@ def run_command_line():
search=True,
shortname=None,
)
+ if config['install']:
+ logger.debug('obeying INSTALL=yes in configuration')
+ parsed.install = True
+ if config['preserve']:
+ logger.debug('obeying PRESERVE=yes in configuration')
+ parsed.destination = '.'
+
parser.parse_args(namespace=parsed)
logger.debug('parsed command-line arguments into: %r', parsed)
diff --git a/lib/game_data_packager/config.py b/lib/game_data_packager/config.py
new file mode 100644
index 0000000..d8a1e20
--- /dev/null
+++ b/lib/game_data_packager/config.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python3
+# vim:set fenc=utf-8:
+#
+# Copyright © 2014-2015 Simon McVittie <smcv at debian.org>
+#
+# 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 logging
+import re
+
+from .paths import CONFIG
+
+logger = logging.getLogger('game-data-packager.config')
+
+COMMENT = re.compile(r'#.*')
+OPTION = re.compile('^([A-Z]+)=(["\']?)(.*)\\2$')
+
+def read_config():
+ """The world's simplest shell script parser.
+ """
+
+ config = { 'install': False, 'preserve': True }
+
+ try:
+ with open(CONFIG) as conffile:
+ lineno = 0
+ for line in conffile:
+ lineno += 1
+ line = COMMENT.sub('', line)
+ line = line.strip()
+ if not line:
+ continue
+ match = OPTION.match(line)
+ if match:
+ k = match.group(1).lower()
+ v = match.group(3)
+ if k in config:
+ if v == 'yes':
+ config[k] = True
+ elif v == 'no':
+ config[k] = False
+ else:
+ logger.warning('%s:%d: unknown option value: %s=%r',
+ CONFIG, lineno, k, v)
+ else:
+ logger.warning('%s:%d: unknown option: %s',
+ CONFIG, lineno, k)
+ else:
+ logger.warning('%s:%d: could not parse line: %r',
+ CONFIG, lineno, line)
+ except OSError:
+ pass
+
+ return config
diff --git a/lib/game_data_packager/paths.py b/lib/game_data_packager/paths.py
index 970e828..abb80c5 100644
--- a/lib/game_data_packager/paths.py
+++ b/lib/game_data_packager/paths.py
@@ -1,10 +1,12 @@
import os
if os.environ.get('GDP_UNINSTALLED'):
+ CONFIG = './etc/game-data-packager.conf'
DATADIR = './out'
ETCDIR = './etc'
LIBDIR = './lib'
else:
+ CONFIG = '/etc/game-data-packager.conf'
DATADIR = '/usr/share/games/game-data-packager'
ETCDIR = '/etc/game-data-packager'
LIBDIR = '/usr/lib/game-data-packager'
--
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