2020-02-22 16:47:07 -06:00
|
|
|
# -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# This file is part of the LibreOffice project.
|
|
|
|
#
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
#
|
|
|
|
# This file incorporates work covered by the following license notice:
|
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed
|
|
|
|
# with this work for additional information regarding copyright
|
|
|
|
# ownership. The ASF licenses this file to you under the Apache
|
|
|
|
# License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys, os, re
|
2020-07-17 16:05:15 -05:00
|
|
|
import argparse
|
2020-02-22 16:47:07 -06:00
|
|
|
|
|
|
|
global_list = []
|
|
|
|
global_hash = {}
|
2020-07-17 16:05:15 -05:00
|
|
|
args = None
|
2020-02-22 16:47:07 -06:00
|
|
|
|
|
|
|
def read_icons(fname):
|
2020-07-17 16:05:15 -05:00
|
|
|
global args
|
2020-02-22 16:47:07 -06:00
|
|
|
images = []
|
2020-07-17 16:05:15 -05:00
|
|
|
full_path = os.path.join(args.base_path, fname)
|
2020-02-22 16:47:07 -06:00
|
|
|
if not os.path.exists(full_path):
|
2020-07-17 16:05:15 -05:00
|
|
|
if not args.quiet:
|
2021-05-21 08:41:15 -05:00
|
|
|
print("Skipping non-existent {}".format(full_path), file=sys.stderr)
|
2020-02-22 16:47:07 -06:00
|
|
|
return images
|
2020-03-20 10:26:55 -05:00
|
|
|
with open(full_path) as fp:
|
|
|
|
for line in fp:
|
|
|
|
m = re.search(r'xlink:href="\.uno:(\S+)"\s+', line)
|
|
|
|
if m:
|
|
|
|
images.append(m.group(1).lower())
|
2020-02-22 16:47:07 -06:00
|
|
|
return images
|
|
|
|
|
|
|
|
# filter out already seen icons & do prefixing
|
|
|
|
def read_new_icons(fname, prefix):
|
|
|
|
images = read_icons(fname)
|
|
|
|
new_icons_arr = []
|
|
|
|
new_icons_d = {}
|
|
|
|
for icon in images:
|
|
|
|
iname = "cmd/" + prefix + icon + ".png"
|
|
|
|
if iname not in global_hash and \
|
|
|
|
iname not in new_icons_d:
|
|
|
|
new_icons_arr.append(iname)
|
|
|
|
new_icons_d[iname] = 1
|
|
|
|
return new_icons_arr
|
|
|
|
|
|
|
|
def process_group(prefix, uiconfigs):
|
|
|
|
global global_list, global_hash
|
|
|
|
group = {}
|
|
|
|
cur_max = 1.0
|
|
|
|
|
|
|
|
# a very noddy sorting algorithm
|
|
|
|
for uiconfig in uiconfigs:
|
|
|
|
images = read_new_icons(uiconfig, prefix)
|
|
|
|
prev = ''
|
|
|
|
for icon in images:
|
|
|
|
if icon not in group:
|
|
|
|
if prev not in group:
|
|
|
|
group[icon] = cur_max
|
|
|
|
cur_max += 1.0
|
|
|
|
else:
|
|
|
|
group[icon] = group[prev] + (1.0 - 0.5 / cur_max)
|
|
|
|
def intvalue(i):
|
|
|
|
return group[i]
|
|
|
|
for icon in sorted(group.keys(), key=intvalue):
|
|
|
|
global_list.append(icon)
|
|
|
|
global_hash[icon] = 1
|
|
|
|
|
|
|
|
def process_file(fname, prefix):
|
|
|
|
global global_list, global_hash
|
|
|
|
images = read_new_icons(fname, prefix)
|
|
|
|
|
|
|
|
for icon in images:
|
|
|
|
global_list.append(icon)
|
|
|
|
global_hash[icon] = 1
|
|
|
|
|
2020-03-20 10:26:55 -05:00
|
|
|
def chew_controlfile(ifile):
|
2020-02-22 16:47:07 -06:00
|
|
|
global global_list, global_hash
|
|
|
|
filelist = []
|
2020-03-20 10:26:55 -05:00
|
|
|
for line in ifile:
|
2020-02-22 16:47:07 -06:00
|
|
|
line = line.strip()
|
|
|
|
if line.startswith('#'):
|
|
|
|
continue
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
|
|
|
|
m = re.match(r'-- (\S+)\s*', line)
|
|
|
|
if m:
|
|
|
|
# control code
|
|
|
|
code = m.group(1)
|
|
|
|
small = line.lower().endswith(' small')
|
|
|
|
if code.lower() == 'group':
|
|
|
|
if not small:
|
|
|
|
process_group("lc_", filelist)
|
|
|
|
process_group ("sc_", filelist)
|
|
|
|
elif code.lower() == 'ordered':
|
|
|
|
if not small:
|
|
|
|
for f in filelist:
|
|
|
|
process_file(f, "lc_")
|
|
|
|
for f in filelist:
|
|
|
|
process_file(f, "sc_")
|
|
|
|
elif code.lower() == 'literal':
|
|
|
|
for f in filelist:
|
|
|
|
if f not in global_hash:
|
|
|
|
global_list.append(f)
|
|
|
|
global_hash[f] = 1
|
|
|
|
else:
|
|
|
|
sys.exit("Unknown code '{}'".format(code))
|
|
|
|
filelist = []
|
|
|
|
else:
|
|
|
|
filelist.append(line)
|
|
|
|
|
2020-07-17 16:05:15 -05:00
|
|
|
parser = argparse.ArgumentParser()
|
2020-02-22 16:47:07 -06:00
|
|
|
# where the control file lives
|
2020-09-15 03:42:16 -05:00
|
|
|
parser.add_argument('control_file', metavar='image-sort.lst',
|
2020-07-17 16:05:15 -05:00
|
|
|
help='the sort control file')
|
2020-02-22 16:47:07 -06:00
|
|
|
# where the uiconfigs live
|
2020-07-17 16:05:15 -05:00
|
|
|
parser.add_argument('base_path', metavar='directory',
|
|
|
|
help='path to the UIConfigs directory')
|
|
|
|
parser.add_argument('output', metavar='output file', type=argparse.FileType('w'),
|
|
|
|
nargs='?', default=None, help='optionally write to this output file')
|
|
|
|
parser.add_argument("-q", "--quiet", action="store_true",
|
|
|
|
help="don't print status messages to stdout")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.output is not None:
|
2020-03-20 10:26:55 -05:00
|
|
|
close_output = True
|
2020-02-22 16:47:07 -06:00
|
|
|
else:
|
2020-07-17 16:05:15 -05:00
|
|
|
args.output = sys.stdout
|
2020-03-20 10:26:55 -05:00
|
|
|
close_output = False
|
2020-02-22 16:47:07 -06:00
|
|
|
|
2020-09-15 03:42:16 -05:00
|
|
|
with open(args.control_file) as cf:
|
|
|
|
chew_controlfile(cf)
|
2020-02-22 16:47:07 -06:00
|
|
|
|
|
|
|
for icon in global_list:
|
|
|
|
if not icon.startswith('sc_'):
|
2020-07-17 16:05:15 -05:00
|
|
|
args.output.write(icon + "\n")
|
2020-02-22 16:47:07 -06:00
|
|
|
|
|
|
|
for icon in global_list:
|
|
|
|
if icon.startswith('sc_'):
|
2020-07-17 16:05:15 -05:00
|
|
|
args.output.write(icon + "\n")
|
2020-02-22 16:47:07 -06:00
|
|
|
|
2020-03-20 10:26:55 -05:00
|
|
|
if close_output:
|
2020-07-17 16:05:15 -05:00
|
|
|
args.output.close()
|
2020-03-20 10:26:55 -05:00
|
|
|
|
2020-02-22 16:47:07 -06:00
|
|
|
# dnl vim:set shiftwidth=4 softtabstop=4 expandtab:
|