aboutsummaryrefslogtreecommitdiffstats
path: root/tools/queryforest
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-02-10 07:05:52 +0100
committerMattias Andrée <maandree@kth.se>2024-02-10 07:05:52 +0100
commitc90e3bf08b1c6f4426d0f72c76b1ac9a0a346efb (patch)
treef9a0216e5e7d2a0a77d40a1840a1f6b3424869d2 /tools/queryforest
parentAdd alias for versions up to 99 of applications (diff)
downloadsimple-icon-theme-c90e3bf08b1c6f4426d0f72c76b1ac9a0a346efb.tar.gz
simple-icon-theme-c90e3bf08b1c6f4426d0f72c76b1ac9a0a346efb.tar.bz2
simple-icon-theme-c90e3bf08b1c6f4426d0f72c76b1ac9a0a346efb.tar.xz
Add tools
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rwxr-xr-xtools/queryforest80
1 files changed, 80 insertions, 0 deletions
diff --git a/tools/queryforest b/tools/queryforest
new file mode 100755
index 0000000..8dc979c
--- /dev/null
+++ b/tools/queryforest
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+import sys, os
+
+args = sys.argv[1:]
+
+if len(args) == 0:
+ print('usage: %s (icon | file | directory) ... < icon-forest' % sys.argv[0], file = sys.stderr)
+ exit(1)
+
+forest = {}
+selected = {}
+
+try:
+ while True:
+ line = input()
+ if not line.strip():
+ continue
+ if not line.startswith('\t'):
+ tree = []
+ icon = line.strip()
+ tree.append(line)
+ if icon in forest:
+ print('duplicate entry of %s found' % icon, file = sys.stderr)
+ forest[icon] = (tree, len(tree) - 1)
+except EOFError:
+ pass
+
+basenames = {}
+for icon in forest:
+ iconbasename = icon.split('/')[-1]
+ icons = basenames.get(iconbasename, [])
+ icons.append(icon)
+ basenames[iconbasename] = icons
+
+def select(icon):
+ if icon in forest:
+ (tree, line) = forest[icon]
+ lines = selected.get(tree[0], {})
+ lines[line] = None
+ selected[tree[0]] = lines
+ elif icon.split('/')[-1] in basenames:
+ icondir = '/'.join(icon.split('/')[:-1])
+ for alticon in basenames[icon.split('/')[-1]]:
+ (tree, line) = forest[alticon]
+ lines = selected.get(tree[0], {})
+ if line not in lines:
+ lines[line] = [icondir]
+ elif lines[line] is None:
+ continue
+ else:
+ lines[line].append(icondir)
+ selected[tree[0]] = lines
+
+def visit(d):
+ for f in os.listdir(d):
+ f = d + '/' + f
+ if os.path.isfile(f):
+ icon = '/'.join('.'.join(f.split('.')[:-1]).split('/')[-2:])
+ select(icon)
+ elif os.path.isdir(f):
+ visit(f)
+
+for icon in args:
+ if os.path.isfile(icon) and '/' in icon and icon.endswith('.svg'):
+ icon = '/'.join(icon[:-4].split('/')[-2:])
+ elif os.path.isdir(icon):
+ visit(icon)
+ continue
+ select(icon)
+
+for tree in sorted(selected):
+ lines = selected[tree]
+ (tree, _) = forest[tree]
+ for i, line in enumerate(tree):
+ if i not in lines:
+ print(line)
+ elif lines[i] is None:
+ print('\033[1;31m%s\033[m' % line)
+ else:
+ print('\033[1;33m%s\033[;33m (%s)\033[m' % (line, ', '.join(sorted(lines[i]))))