forked from linuxmint/cinnamon-spices-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-spice
executable file
·82 lines (70 loc) · 2.61 KB
/
test-spice
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
#!/usr/bin/python3
import argparse
import json
import os
import sys
import shutil
import subprocess
from pathlib import Path
DEV_PREFIX = "devtest-"
EXTENSIONS_PATH = f'{Path.home()}/.local/share/cinnamon/extensions/'
def validate_spice(uuid):
"""
Run the validation for the Spice
"""
try:
out = subprocess.run(['./validate-spice', uuid], check=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if out.returncode != 0:
print(out.stdout.decode('ascii') + '\nValidation failed!')
except FileNotFoundError:
print('Errors encountered! Please try running again from the top-level'
' directory of the repository.')
def copy_xlet(uuid):
"""
Copy the UUID directory and action file for testing purposes
"""
uuid_path = f'{uuid}/files/{uuid}'
dev_dest = f'{EXTENSIONS_PATH}{DEV_PREFIX}{uuid}'
try:
shutil.copytree(uuid_path, dev_dest, dirs_exist_ok=True)
metadata_file = f'{dev_dest}/metadata.json'
with open(metadata_file, 'r+', encoding='utf-8') as metadata:
data = json.load(metadata)
metadata.seek(0)
data['uuid'] = f"{DEV_PREFIX}{data['uuid']}"
data['name'] = f"({DEV_PREFIX.replace('-', '')}) {data['name']}"
json.dump(data, metadata, indent=4)
except (FileNotFoundError, KeyError):
# metadata.json file not found or missing valid keys
pass
def main():
"""
Simpler testing of Spices for developers
"""
parser = argparse.ArgumentParser()
parser.description = 'Copy a Spice locally for testing purposes'
parser.add_argument('-r', '--remove', action='store_true',
help='Remove all test Spices')
parser.add_argument('-s', '--skip', action='store_true',
help='Skip Spice validation with validate-spice')
parser.add_argument('uuid', type=str, metavar='UUID', nargs='?',
help='the UUID of the Spice')
args = parser.parse_args()
if args.remove and not args.uuid:
for file_path in os.listdir(EXTENSIONS_PATH):
if file_path.startswith(DEV_PREFIX):
rm_path = f'{EXTENSIONS_PATH}{file_path}'
if Path.is_dir(Path(rm_path)):
shutil.rmtree(rm_path)
sys.exit(0)
elif args.skip and args.uuid:
copy_xlet(args.uuid.rstrip('/'))
elif args.uuid and not args.remove:
validate_spice(args.uuid.rstrip('/'))
copy_xlet(args.uuid.rstrip('/'))
else:
parser.print_help()
sys.exit(2)
if __name__ == "__main__":
main()