-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfind-missing.py
executable file
·81 lines (65 loc) · 2.44 KB
/
find-missing.py
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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import os
import sys
import argparse
import shutil
from glob import glob
from os.path import join, basename, exists
from extractor import KPP
from bundle import Bundle
def parse_cmdline():
parser = argparse.ArgumentParser(description="Find resources that are used by the bundle, but not included into it")
parser.add_argument('-b', '--brushes', nargs=1, metavar='DIRECTORY', help='Directory with brush files')
parser.add_argument('--embed', action='store_true', help='Automatically embed found resources to the bundle')
parser.add_argument('-d', '--delete', action='store_true', help='Automatically remove found resource from bundle\'s manifest')
parser.add_argument('bundle', metavar='FILE.BUNDLE', help="Path to bundle file to inspect")
return parser.parse_args()
def find_used(bundle_path):
def process_kpp(kpp):
links = kpp.get_links()
requiredBrushFile = links.get('requiredBrushFile', None)
if requiredBrushFile:
return [requiredBrushFile]
else:
return []
bundle = Bundle.open(bundle_path)
presets = bundle.presets_data
used = []
for kpp in presets:
used.extend(process_kpp(kpp))
result = [brush for brush in used if not bundle.find_brush(brush)]
return set(result)
def find_brush(paths, name):
for path in paths:
b = join(path, name)
if exists(b):
return b
return None
if __name__ == '__main__':
args = parse_cmdline()
if not args.bundle:
print("Error: path to bundle must be specified")
sys.exit(1)
used = find_used(args.bundle)
for brush in used:
print(brush)
if args.embed and len(used):
if not args.brushes:
print("Error: if --embed mode is on, --brushes must be specified")
sys.exit(1)
bundle = Bundle.open(args.bundle)
shutil.copy(args.bundle, args.bundle+'.bak')
found = []
for brush in used:
path = find_brush(args.brushes, brush)
if path:
found.append(path)
print("Added " + brush)
else:
print("Warning: can't find "+brush)
bundle.add_brushes(args.bundle, found)
elif args.delete and len(used):
bundle = Bundle.open(args.bundle)
shutil.copy(args.bundle, args.bundle+'.bak')
bundle.remove_brushes_from_manifest(args.bundle, used)