[game-data-packager] 08/09: Add configurable installation method instead of always using su
Simon McVittie
smcv at debian.org
Thu Oct 1 10:16:51 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 1acdb40899b1c796915f6cf70532c894b02c761d
Author: Simon McVittie <smcv at debian.org>
Date: Thu Oct 1 10:35:27 2015 +0100
Add configurable installation method instead of always using su
---
debian/TODO | 16 ------------
debian/changelog | 1 +
game_data_packager/__init__.py | 19 ++++++++++++++
game_data_packager/build.py | 2 +-
game_data_packager/config.py | 8 +++++-
game_data_packager/steam.py | 2 +-
game_data_packager/util.py | 59 ++++++++++++++++++++++++++++++++++--------
7 files changed, 77 insertions(+), 30 deletions(-)
diff --git a/debian/TODO b/debian/TODO
index 59c5827..fad1edb 100644
--- a/debian/TODO
+++ b/debian/TODO
@@ -1,21 +1,5 @@
TODO:
-* provide configurable methods for elevating privs
- - su
- - sudo
- - pkexec
-* provide configurable methods for installing packages
- - dpkg
- - gdebi, this handle Depends: , but doesn't install 'Recommends:' (=game-engine)
- - apt-get, but this needs that #47379 from 1999 to be fixed
- - integrate with graphical package managers ?
-
- nicer -i behaviour
- support (somehow) installing a generated .deb and throwing
- it away (current behaviour is now, generate and store in
- $(pwd) if otherwise unspecified; impossible not to preserve
- generated file)
-
See also: https://wiki.debian.org/Games/GameDataPackager/Development
## List of missing games (machine-read)
diff --git a/debian/changelog b/debian/changelog
index 3f2bc53..a9fcb85 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -59,6 +59,7 @@ game-data-packager (43) UNRELEASED; urgency=medium
* Move detailed information about files to be packaged into separate JSON
and *sums files, which are loaded lazily. This speeds up
"game-data-packager --help" considerably. (Continuation of #779937)
+ * Add configurable installation method instead of always using su
-- Simon McVittie <smcv at debian.org> Thu, 16 Jul 2015 09:59:23 +0200
diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 4b71cee..76af7a3 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -878,6 +878,15 @@ def run_command_line():
dest='packages', metavar='PACKAGE',
help='Produce this data package (may be repeated)')
+ base_parser.add_argument('--install-method', metavar='METHOD',
+ dest='install_method',
+ help='Use METHOD (apt, dpkg, gdebi, gdebi-gtk, gdebi-kde) ' +
+ 'to install packages')
+
+ base_parser.add_argument('--gain-root-command', metavar='METHOD',
+ dest='gain_root_command',
+ help='Use METHOD (su, sudo, pkexec) to gain root if needed')
+
# Misc options
group = base_parser.add_mutually_exclusive_group()
group.add_argument('-i', '--install', action='store_true',
@@ -971,6 +980,8 @@ def run_command_line():
download=True,
verbose=False,
install=False,
+ install_method='',
+ gain_root_command='',
packages=[],
save_downloads=None,
shortname=None,
@@ -984,6 +995,14 @@ def run_command_line():
if config['verbose']:
logger.debug('obeying VERBOSE=yes in configuration')
parsed.verbose = True
+ if config['install_method']:
+ logger.debug('obeying INSTALL_METHOD=%r in configuration',
+ config['install_method'])
+ parsed.install_method = config['install_method']
+ if config['gain_root_command']:
+ logger.debug('obeying GAIN_ROOT_COMMAND=%r in configuration',
+ config['gain_root_command'])
+ parsed.gain_root_command = config['gain_root_command']
parser.parse_args(namespace=parsed)
logger.debug('parsed command-line arguments into: %r', parsed)
diff --git a/game_data_packager/build.py b/game_data_packager/build.py
index fe386b9..8c33cbe 100644
--- a/game_data_packager/build.py
+++ b/game_data_packager/build.py
@@ -1912,7 +1912,7 @@ class PackagingTask(object):
print('generated "%s"' % os.path.abspath(deb))
if install_debs:
- install_packages(debs)
+ install_packages(debs, args.install_method, args.gain_root_command)
engines_alt = set((p.engine or self.game.engine) for p in ready)
engines_alt.discard(None)
diff --git a/game_data_packager/config.py b/game_data_packager/config.py
index 6503db3..f5146b0 100644
--- a/game_data_packager/config.py
+++ b/game_data_packager/config.py
@@ -29,7 +29,13 @@ def read_config():
"""The world's simplest shell script parser.
"""
- config = { 'install': False, 'preserve': True, 'verbose': False }
+ config = {
+ 'install': False,
+ 'preserve': True,
+ 'verbose': False,
+ 'install_method': '',
+ 'gain_root_command': '',
+ }
try:
with open(CONFIG, encoding='utf-8') as conffile:
diff --git a/game_data_packager/steam.py b/game_data_packager/steam.py
index 0e5483d..aaa63a9 100644
--- a/game_data_packager/steam.py
+++ b/game_data_packager/steam.py
@@ -203,6 +203,6 @@ def run_steam_meta_mode(parsed, games):
raise SystemExit(1)
if install_debs:
- install_packages(all_debs)
+ install_packages(all_debs, args.install_method, args.gain_root_command)
if workdir:
rm_rf(workdir)
diff --git a/game_data_packager/util.py b/game_data_packager/util.py
index e561375..89e0c9d 100644
--- a/game_data_packager/util.py
+++ b/game_data_packager/util.py
@@ -16,6 +16,7 @@
# You can find the GPL license text on a Debian system under
# /usr/share/common-licenses/GPL-2.
+import logging
import os
import shlex
import shutil
@@ -27,6 +28,8 @@ from debian.debian_support import Version
from .version import GAME_PACKAGE_VERSION
+logger = logging.getLogger('game-data-packager.util')
+
KIBIBYTE = 1024
MEBIBYTE = KIBIBYTE * KIBIBYTE
@@ -168,19 +171,53 @@ def ascii_safe(string, force=False):
'aacceeeeiiiln***'))
return string
-def install_packages(debs):
- """Install one or more packages (a list of filenames)."""
+def run_as_root(argv, gain_root='su'):
+ if gain_root not in ('su', 'pkexec' ,'sudo', 'super', 'really'):
+ logger.warning(('Unknown privilege escalation method %r, assuming ' +
+ 'it works like sudo') % gain_root)
+
+ if gain_root == 'su':
+ print('using su to obtain root privileges and install the package(s)')
- print('using su(1) to obtain root privileges and install the package(s)')
+ # su expects a single sh(1) command-line
+ cmd = ' '.join([shlex.quote(arg) for arg in argv])
- apt_ver = subprocess.check_output(['dpkg-query', '--show',
- '--showformat', '${Version}', 'apt'], universal_newlines=True)
- if Version(apt_ver.strip()) >= Version('1.1'):
- cmd = 'apt-get install --install-recommends'
+ subprocess.call(['su', '-c', cmd])
else:
- cmd = 'dpkg -i'
+ # this code path works for pkexec, sudo, super, really;
+ # we assume everything else is the same
+ print('using %s to obtain root privileges and install the package(s)' %
+ gain_root)
+ subprocess.call([gain_root] + list(argv))
- for deb in debs:
- cmd = cmd + ' ' + shlex.quote(deb)
+def install_packages(debs, method, gain_root='su'):
+ """Install one or more packages (a list of filenames)."""
- subprocess.call(['su', '-c', cmd])
+ default = None
+
+ if method and method not in (
+ 'apt', 'dpkg',
+ 'gdebi', 'gdebi-gtk', 'gdebi-kde',
+ ):
+ logger.warning(('Unknown installation method %r, using apt or dpkg ' +
+ 'instead') % method)
+ method = None
+
+ if not method:
+ apt_ver = subprocess.check_output(['dpkg-query', '--show',
+ '--showformat', '${Version}', 'apt'], universal_newlines=True)
+ if Version(apt_ver.strip()) >= Version('1.1'):
+ method = 'apt'
+ else:
+ method = 'dpkg'
+
+ if method == 'apt':
+ run_as_root(['apt-get', 'install', '--install-recommends'] + list(debs),
+ gain_root)
+ elif method == 'dpkg':
+ run_as_root(['dpkg', '-i'] + list(debs), gain_root)
+ elif method == 'gdebi':
+ run_as_root(['gdebi'] + list(debs), gain_root)
+ else:
+ # gdebi-gtk etc.
+ subprocess.call([method] + list(debs))
--
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