1 # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
29 def read_icons(fname
):
32 full_path
= os
.path
.join(args
.base_path
, fname
)
33 if not os
.path
.exists(full_path
):
35 print("Skipping non-existent {}".format(full_path
), file=sys
.stderr
)
37 with
open(full_path
) as fp
:
39 m
= re
.search(r
'xlink:href="\.uno:(\S+)"\s+', line
)
41 images
.append(m
.group(1).lower())
44 # filter out already seen icons & do prefixing
45 def read_new_icons(fname
, prefix
):
46 images
= read_icons(fname
)
50 iname
= "cmd/" + prefix
+ icon
+ ".png"
51 if iname
not in global_hash
and \
52 iname
not in new_icons_d
:
53 new_icons_arr
.append(iname
)
54 new_icons_d
[iname
] = 1
57 def process_group(prefix
, uiconfigs
):
58 global global_list
, global_hash
62 # a very noddy sorting algorithm
63 for uiconfig
in uiconfigs
:
64 images
= read_new_icons(uiconfig
, prefix
)
72 group
[icon
] = group
[prev
] + (1.0 - 0.5 / cur_max
)
75 for icon
in sorted(group
.keys(), key
=intvalue
):
76 global_list
.append(icon
)
79 def process_file(fname
, prefix
):
80 global global_list
, global_hash
81 images
= read_new_icons(fname
, prefix
)
84 global_list
.append(icon
)
87 def chew_controlfile(ifile
):
88 global global_list
, global_hash
92 if line
.startswith('#'):
97 m
= re
.match(r
'-- (\S+)\s*', line
)
101 small
= line
.lower().endswith(' small')
102 if code
.lower() == 'group':
104 process_group("lc_", filelist
)
105 process_group ("sc_", filelist
)
106 elif code
.lower() == 'ordered':
109 process_file(f
, "lc_")
111 process_file(f
, "sc_")
112 elif code
.lower() == 'literal':
114 if f
not in global_hash
:
115 global_list
.append(f
)
118 sys
.exit("Unknown code '{}'".format(code
))
121 filelist
.append(line
)
123 parser
= argparse
.ArgumentParser()
124 # where the control file lives
125 parser
.add_argument('control_file', metavar
='image-sort.lst',
126 help='the sort control file')
127 # where the uiconfigs live
128 parser
.add_argument('base_path', metavar
='directory',
129 help='path to the UIConfigs directory')
130 parser
.add_argument('output', metavar
='output file', type=argparse
.FileType('w'),
131 nargs
='?', default
=None, help='optionally write to this output file')
132 parser
.add_argument("-q", "--quiet", action
="store_true",
133 help="don't print status messages to stdout")
135 args
= parser
.parse_args()
137 if args
.output
is not None:
140 args
.output
= sys
.stdout
143 with
open(args
.control_file
) as cf
:
146 for icon
in global_list
:
147 if not icon
.startswith('sc_'):
148 args
.output
.write(icon
+ "\n")
150 for icon
in global_list
:
151 if icon
.startswith('sc_'):
152 args
.output
.write(icon
+ "\n")
157 # dnl vim:set shiftwidth=4 softtabstop=4 expandtab: