Debian Codegraph @

files/usr/bin/cinnamon-install-spice

raw
1 #!/usr/bin/python3
2
3 import sys
4 import os
5 import argparse
6
7 import gi
8 gi.require_version('Gtk', '3.0')
9
10 sys.path.append('/usr/share/cinnamon/cinnamon-settings/bin')
11 from Spices import Spice_Harvester
12
13 USAGE_DESCRIPTION = 'Installs an applet, desklet, extension, or theme from a local folder. Rather than just doing a shallow copy, it will also install translations, schema files (if present) and update the metadata with a timestamp for version comparison.'
14 USAGE_EPILOG = 'This script is designed for developers to test their work. It is recommended that everyone else continue to use cinnamon-settings to install their spices as this script has no safeguards in place to prevent malicious code.'
15 SPICE_TYPES = ['applet', 'desklet', 'extension', 'theme', 'search_provider']
16
17 parser = argparse.ArgumentParser(description=USAGE_DESCRIPTION, epilog=USAGE_EPILOG)
18 parser.add_argument('spice_type', type=str, choices=SPICE_TYPES, help='The type of spice you are installing.')
19 parser.add_argument('path', type=str, default=os.getcwd(), nargs='?', help='The path from which you are installing. Default is the current directory.')
20
21 args = parser.parse_args()
22
23 source_dir = os.path.abspath(args.path)
24 spice_type = args.spice_type
25
26 if not os.path.exists(source_dir):
27 print('invalid directory - %s does not exist' % source_dir)
28 quit()
29
30 uuid = os.path.basename(source_dir)
31 if os.path.exists(os.path.join(source_dir, 'files', uuid)):
32 source_dir = os.path.join(source_dir, 'files', uuid)
33
34 if spice_type == 'theme':
35 theme_file = os.path.join(source_dir, 'cinnamon/cinnamon.css')
36 if not os.path.exists(theme_file):
37 print('Invalid theme - missing file cinnamon.css')
38 quit()
39 else:
40 # we always need metadata.json as well as the corresponding applet.js, deskelt.js, etc.
41 if not os.path.exists(os.path.join(source_dir, 'metadata.json')):
42 print('Invalid %s - metadata.json not found' % spice_type)
43 quit()
44 if not os.path.exists(os.path.join(source_dir, '%s.js' % spice_type)):
45 # multi-version xlets may not have it in the root directory, so check subdirectories as well
46 found = False
47 for name in os.listdir(source_dir):
48 if os.path.exists(os.path.join(source_dir, name, '%s.js' % spice_type)):
49 found = True
50 break
51 if not found:
52 print('Invalid %s - %s.js not found' % (spice_type, spice_type))
53 quit()
54
55 spices = Spice_Harvester(spice_type)
56
57 spices.install_from_folder(source_dir, uuid)