File: quake.py

package info (click to toggle)
game-data-packager 73
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 23,420 kB
  • sloc: python: 11,086; sh: 609; makefile: 59
file content (76 lines) | stat: -rw-r--r-- 3,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2015 Simon McVittie <smcv@debian.org>
# SPDX-License-Identifier: GPL-2.0-or-later

import logging
import os

from ..build import (PackagingTask)
from ..game import GameData
from ..util import TemporaryUmask, mkdir_p

logger = logging.getLogger(__name__)

class QuakeTask(PackagingTask):
    """With hindsight, it would have been better to make the TryExec
    in quake point to a symlink to the quake executable, or something;
    but with a name like hipnotic-tryexec.sh it would seem silly for it
    not to be a shell script.
    """

    def fill_extra_files(self, per_package_state):
        super().fill_extra_files(per_package_state)
        package = per_package_state.package
        destdir = per_package_state.destdir

        for path in package.install:
            if path.startswith('hipnotic'):
                detector = 'hipnotic-tryexec.sh'
                break
            elif path.startswith('rogue'):
                detector = 'rogue-tryexec.sh'
                break
        else:
            return

        with TemporaryUmask(0o022):
            quakedir = os.path.join(destdir, 'usr/share/games/quake')
            mkdir_p(quakedir)
            path = os.path.join(quakedir, detector)
            with open(path, 'w') as f:
                f.write('#!/bin/sh\nexit 0\n')
            os.chmod(path, 0o755)

class QuakeGameData(GameData):
    def construct_task(self, **kwargs):
        return QuakeTask(self, **kwargs)

    def add_parser(self, parsers, base_parser):
        parser = super(QuakeGameData, self).add_parser(parsers, base_parser,
                conflict_handler='resolve')
        parser.add_argument('-m', dest='packages', action='append_const',
                const='quake-registered',
                help='Equivalent to --package=quake-registered')
        parser.add_argument('-s', dest='packages', action='append_const',
                const='quake-shareware',
                help='Equivalent to --package=quake-shareware')
        parser.add_argument('--mp1', '-mp1', dest='packages',
                action='append_const', const='quake-armagon',
                help='Equivalent to --package=quake-armagon')
        parser.add_argument('--mp2', '-mp2', dest='packages',
                action='append_const', const='quake-dissolution',
                help='Equivalent to --package=quake-dissolution')
        parser.add_argument('--music', dest='packages',
                action='append_const', const='quake-music',
                help='Equivalent to --package=quake-music')
        parser.add_argument('--mp1-music', dest='packages',
                action='append_const', const='quake-armagon-music',
                help='Equivalent to --package=quake-armagon-music')
        parser.add_argument('--mp2-music', dest='packages',
                action='append_const', const='quake-dissolution-music',
                help='Equivalent to --package=quake-dissolution-music')
        return parser

GAME_DATA_SUBCLASS = QuakeGameData