File: ecwolf_common.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 (112 lines) | stat: -rw-r--r-- 3,979 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2015-2016 Alexandre Detiste <alexandre@detiste.be>
# Copyright © 2016 Simon McVittie <smcv@debian.org>
# SPDX-License-Identifier: GPL-2.0-or-later

import configparser
import logging
import os
import subprocess

from ..build import (PackagingTask)
from ..data import (Package)
from ..game import (GameData)
from ..paths import DATADIR
from ..util import (mkdir_p)

logger = logging.getLogger(__name__)

def install_data(from_, to):
    subprocess.check_call(['cp', '--reflink=auto', from_, to])

class EcwolfGameData(GameData):
    """Special subclass of GameData for games playable with ecwolf:
    - Blake Stone I&II
    - Super 3D Noah's Ark
    the .desktop file provided by the engine's package would
    default to Wolfenstein3D
    """

    def __init__(self, shortname, data):
        super(EcwolfGameData, self).__init__(shortname, data)
        if self.engine is None:
            self.engine = 'ecwolf'
        if self.genre is None:
            self.genre = 'First-person shooter'

    def construct_package(self, binary, data):
        return EcwolfPackage(binary, data)

    def construct_task(self, **kwargs):
        return EcwolfTask(self, **kwargs)

class EcwolfPackage(Package):
    def __init__(self, binary, data):
        super(EcwolfPackage, self).__init__(binary, data)

        if 'quirks' in data:
            self.quirks = ' ' + data['quirks']
        else:
            self.quirks = ''

class EcwolfTask(PackagingTask):
    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

        pixdir = os.path.join(destdir, 'usr/share/pixmaps')
        mkdir_p(pixdir)

        to_ = os.path.join(pixdir, '%s.png' % package.name)
        if not os.path.isfile(to_):
            for from_ in (self.locate_steam_icon(package),
                          os.path.join(DATADIR, package.name + '.png'),
                          os.path.join(DATADIR, self.game.shortname + '.png'),
                          os.path.join('/usr/share/pixmaps', package.name + '.png'),
                          os.path.join(DATADIR, 'wolf-common.png')):
                if from_ and os.path.exists(from_):
                    install_data(from_, to_)
                    break
            else:
                raise AssertionError('wolf-common.png should have existed')

            from_ = os.path.splitext(from_)[0] + '.svgz'
            if os.path.exists(from_):
                svgdir = os.path.join(destdir, 'usr/share/icons/hicolor/scalable/apps')
                mkdir_p(svgdir)
                install_data(from_, os.path.join(svgdir, '%s.svgz' % package.name))

        install_to = self.packaging.substitute(package.install_to,
                package.name)

        desktop = configparser.RawConfigParser()
        desktop.optionxform = lambda option: option
        desktop['Desktop Entry'] = {}
        entry = desktop['Desktop Entry']
        entry['Name'] = package.longname or self.game.longname
        entry['GenericName'] = self.game.genre + ' game'
        entry['TryExec'] = 'ecwolf'
        entry['Exec'] = 'ecwolf' + package.quirks
        entry['Path'] = os.path.join('/', install_to)
        entry['Icon'] = package.name
        entry['Terminal'] = 'false'
        entry['Type'] = 'Application'
        entry['Categories'] = 'Game;'

        appdir = os.path.join(destdir, 'usr/share/applications')
        mkdir_p(appdir)
        with open(os.path.join(appdir, '%s.desktop' % package.name),
                  'w', encoding='utf-8') as output:
             desktop.write(output, space_around_delimiters=False)

        per_package_state.lintian_overrides.add(
            'desktop-command-not-in-package {} '
            '[usr/share/applications/{}.desktop]'.format(
                'ecwolf', package.name,
            )
        )

GAME_DATA_SUBCLASS = EcwolfGameData