File: package.py

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (92 lines) | stat: -rw-r--r-- 3,335 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3

import argparse
import json
import subprocess
import sys


def prepare(ex, game, arg_dict):
    if ex["prepare"]["type"] == "python-script":
        cmd = sys.executable + " scripts/" + ex["prepare"]["location"]
        for key in ex["prepare"]["options"].keys():
            cmd += " " + key + " "
            value = ex["prepare"]["options"][key]
            # $ -> get from here (package.py), $$ -> get from games.json, $$$ -> get from environment variables
            if len(value) >= 3 and value[2] == '$':
                cmd += value[2:]
            elif len(value) >= 2 and value[1] == '$':
                # check in game's metadata
                cmd += game[value[2:]]
            elif len(value) >= 1 and value[0] == '$':
                cmd += arg_dict[value[1:]]
            else:
                cmd += value

        subprocess.run(cmd, shell=True)
        print(ex["prepare"]["successMessage"])


def bundle(ex, game, arg_dict):
    if ex["bundle"]["type"] == "python-script":
        cmd = sys.executable + " scripts/" + ex["bundle"]["location"]
        for key in ex["bundle"]["options"].keys():
            cmd += " " + key + " "
            value = ex["bundle"]["options"][key]
            # $ -> get from here (package.py), $$ -> get from games.json, $$$ -> get from environment variables
            if len(value) >= 3 and value[2] == '$':
                cmd += value[2:]
            elif len(value) >= 2 and value[1] == '$':
                # check in game's metadata
                cmd += game[value[2:]]
                if value == "$$packname":
                    cmd += ".zip"  # temporary hack
            elif len(value) >= 1 and value[0] == '$':
                cmd += arg_dict[value[1:]]
            else:
                cmd += value

        subprocess.run(cmd, shell=True)
        print(ex["bundle"]["successMessage"])


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--export-platform', required=True,
                        help='Export platform name as per export-platforms.json')
    parser.add_argument('--game', required=True,
                        help='Game name as per dlc-games.json')
    parser.add_argument('--game-location', required=True,
                        help='Location of game\'s datafiles')
    parser.add_argument('--binary-location', required=False,
                        help='Location of ScummVM executable (Required for Android)')

    args = parser.parse_args()

    arg_dict = {"game_location": args.game_location,
            "binary_location": args.binary_location}

    f = open('export-platforms.json')
    export_platforms = json.load(f)

    f = open('dlc-games.json')
    games = json.load(f)

    if args.export_platform in export_platforms:
        if args.game in games:
            print()
            prepare(export_platforms[args.export_platform],
                    games[args.game], arg_dict)

            bundle(export_platforms[args.export_platform],
                   games[args.game], arg_dict)

        else:
            print(
                "Game's metadata not found! Make sure the provided game is in dlc-games.json")
    else:
        print("Export platform not found! Make sure the provided export-platform is in export-platforms.json")


if __name__ == '__main__':
    main()