Debian Codegraph @

examples/book/buildapp/step1/install-cmd.py

raw
1 #!/usr/bin/env python3
2
3 # External command, intended to be called from
4 # ninja install-desktop-file
5 # and
6 # ninja install-gschema-file
7
8 import os
9 import sys
10 import shutil
11 import subprocess
12
13 # install-cmd.py desktop <program_name> <desktop_file> <icon_file>
14 def desktop():
15 program_name = sys.argv[2]
16 desktop_file = sys.argv[3]
17 icon_file = sys.argv[4]
18
19 desktop_install_dir = os.path.expanduser(
20 os.path.join('~' , '.local', 'share', 'applications'))
21 icon_install_dir = os.path.expanduser(
22 os.path.join('~' , '.local', 'share', 'icons', 'hicolor', '48x48', 'apps'))
23
24 # Create the installation directories, if they do not exist.
25 os.makedirs(desktop_install_dir, exist_ok=True)
26 os.makedirs(icon_install_dir, exist_ok=True)
27
28 shutil.copy(desktop_file, os.path.join(desktop_install_dir, program_name + '.desktop'))
29 shutil.copy(icon_file, icon_install_dir)
30 return 0
31
32 # install-cmd.py gschema <gschema_file>
33 def gschema():
34 gschema_file = sys.argv[2]
35
36 # Don't do anything, if GSETTINGS_SCHEMA_DIR is not set,
37 # or if it is set to the current directory ('.').
38 gschema_install_dir = os.environ.get('GSETTINGS_SCHEMA_DIR', None)
39 if not gschema_install_dir or gschema_install_dir == os.curdir:
40 return 0
41
42 # Create the installation directory, if it does not exist.
43 os.makedirs(gschema_install_dir, exist_ok=True)
44
45 shutil.copy(gschema_file, gschema_install_dir)
46 return subprocess.run(['glib-compile-schemas', gschema_install_dir]).returncode
47
48 # ----- Main -----
49 subcommand = sys.argv[1]
50 if subcommand == 'desktop':
51 sys.exit(desktop())
52 if subcommand == 'gschema':
53 sys.exit(gschema())
54 print(sys.argv[0], ': illegal subcommand,', subcommand)
55 sys.exit(1)