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 .
27 def read_icons(fname
):
30 full_path
= os
.path
.join(args
.base_path
, fname
)
31 if not os
.path
.exists(full_path
):
33 print("Skipping non-existent {}\n".format(full_path
), file=sys
.stderr
)
35 with
open(full_path
) as fp
:
37 m
= re
.search(r
'xlink:href="\.uno:(\S+)"\s+', line
)
39 images
.append(m
.group(1).lower())
42 # filter out already seen icons & do prefixing
43 def read_new_icons(fname
, prefix
):
44 images
= read_icons(fname
)
48 iname
= "cmd/" + prefix
+ icon
+ ".png"
49 if iname
not in global_hash
and \
50 iname
not in new_icons_d
:
51 new_icons_arr
.append(iname
)
52 new_icons_d
[iname
] = 1
55 def process_group(prefix
, uiconfigs
):
56 global global_list
, global_hash
60 # a very noddy sorting algorithm
61 for uiconfig
in uiconfigs
:
62 images
= read_new_icons(uiconfig
, prefix
)
70 group
[icon
] = group
[prev
] + (1.0 - 0.5 / cur_max
)
73 for icon
in sorted(group
.keys(), key
=intvalue
):
74 global_list
.append(icon
)
77 def process_file(fname
, prefix
):
78 global global_list
, global_hash
79 images
= read_new_icons(fname
, prefix
)
82 global_list
.append(icon
)
85 def chew_controlfile(ifile
):
86 global global_list
, global_hash
90 if line
.startswith('#'):
95 m
= re
.match(r
'-- (\S+)\s*', line
)
99 small
= line
.lower().endswith(' small')
100 if code
.lower() == 'group':
102 process_group("lc_", filelist
)
103 process_group ("sc_", filelist
)
104 elif code
.lower() == 'ordered':
107 process_file(f
, "lc_")
109 process_file(f
, "sc_")
110 elif code
.lower() == 'literal':
112 if f
not in global_hash
:
113 global_list
.append(f
)
116 sys
.exit("Unknown code '{}'".format(code
))
119 filelist
.append(line
)
121 parser
= argparse
.ArgumentParser()
122 # where the control file lives
123 parser
.add_argument('control_file', metavar
='image-sort.lst',
124 help='the sort control file')
125 # where the uiconfigs live
126 parser
.add_argument('base_path', metavar
='directory',
127 help='path to the UIConfigs directory')
128 parser
.add_argument('output', metavar
='output file', type=argparse
.FileType('w'),
129 nargs
='?', default
=None, help='optionally write to this output file')
130 parser
.add_argument("-q", "--quiet", action
="store_true",
131 help="don't print status messages to stdout")
133 args
= parser
.parse_args()
135 if args
.output
is not None:
138 args
.output
= sys
.stdout
141 with
open(args
.control_file
) as cf
:
144 for icon
in global_list
:
145 if not icon
.startswith('sc_'):
146 args
.output
.write(icon
+ "\n")
148 for icon
in global_list
:
149 if icon
.startswith('sc_'):
150 args
.output
.write(icon
+ "\n")
155 # dnl vim:set shiftwidth=4 softtabstop=4 expandtab: