Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Adam <dev@robert-adam.de>2022-08-26 19:51:35 +0300
committerRobert Adam <dev@robert-adam.de>2022-09-10 18:10:14 +0300
commit4a18246158d38a6a7a4ca544df92d4378f29efd2 (patch)
treebf9a522af6ffea40e0e52a4a061a800b6170e760 /scripts
parent51b0a267991bd15dfd7cdb6cf7c530ecd71b0b48 (diff)
MAINT: Update mkflags.py
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate_flag_qrc.py63
-rw-r--r--scripts/mkflags.py111
2 files changed, 63 insertions, 111 deletions
diff --git a/scripts/generate_flag_qrc.py b/scripts/generate_flag_qrc.py
new file mode 100755
index 000000000..b0071c9ef
--- /dev/null
+++ b/scripts/generate_flag_qrc.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Copyright 2016-2022 The Mumble Developers. All rights reserved.
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file at the root of the
+# Mumble source tree or at <https://www.mumble.info/LICENSE>.
+
+# mkflags.py generates .pri and .qrc files from Mumble's
+# flag SVGs, such that the flags can be included as Qt
+# resources.
+#
+# The script splits the flags into multiple .qrc files once
+# a single .qrc file exceeds a given threshold.
+#
+# This is because older compilers (and old hardware, too!)
+# can have problems with large source files. When Qt embeds
+# a .qrc file, it generates a .cpp file and compiles it. Some
+# of our flag SVGs can be quite large, and if we only use a
+# single .qrc file, it is (as of this writing) 32MB+ large.
+
+from __future__ import (unicode_literals, print_function, division)
+
+import os
+import codecs
+import argparse
+
+# Once a .qrc file's content exceeds this size, the
+# file will be considered full.
+MAX_SIZE = 1024*1024
+
+def main():
+ parser = argparse.ArgumentParser("This script generates a QRC file for embedding the flag SVG icons")
+ parser.add_argument("--flag-dir", help="Path to the directory in which the flag SVGs reside in", metavar="PATH", required=True)
+ parser.add_argument("--output", help="Path to which the generated QRC file shall be written", metavar="PATH", required=True)
+
+ args = parser.parse_args()
+
+ # Get a list of all flag SVGs
+ flags = []
+
+ for fn in os.listdir(args.flag_dir):
+ if not fn.lower().endswith('svg'):
+ continue
+
+ flags.append(fn)
+
+ output_directory = os.path.dirname(args.output)
+
+ # Generate output file.
+ with codecs.open(args.output, "w", "utf-8") as f:
+ f.write('<!DOCTYPE RCC>\n')
+ f.write('<RCC version="1.0">\n')
+ f.write('<qresource>\n')
+
+ for fn in flags:
+ f.write('<file alias="{0}">{1}</file>\n'.format('flags/' + fn, os.path.relpath(os.path.join(args.flag_dir, fn), output_directory)))
+
+ f.write('</qresource>\n')
+ f.write('</RCC>\n')
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/mkflags.py b/scripts/mkflags.py
deleted file mode 100644
index 94d6e4ddf..000000000
--- a/scripts/mkflags.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-# Copyright 2016-2022 The Mumble Developers. All rights reserved.
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file at the root of the
-# Mumble source tree or at <https://www.mumble.info/LICENSE>.
-
-# mkflags.py generates .pri and .qrc files from Mumble's
-# flag SVGs, such that the flags can be included as Qt
-# resources.
-#
-# The script splits the flags into multiple .qrc files once
-# a single .qrc file exceeds a given threshold.
-#
-# This is because older compilers (and old hardware, too!)
-# can have problems with large source files. When Qt embeds
-# a .qrc file, it generates a .cpp file and compiles it. Some
-# of our flag SVGs can be quite large, and if we only use a
-# single .qrc file, it is (as of this writing) 32MB+ large.
-
-from __future__ import (unicode_literals, print_function, division)
-
-import os
-import shutil
-import codecs
-import collections
-
-# Container for an on-disk flag SVG. Contains size and filename.
-OnDiskFlag = collections.namedtuple('OnDiskFlag', ['size', 'filename'])
-
-# Once a .qrc file's content exceeds this size, the
-# file will be considered full.
-MAX_SIZE = 1024*1024
-
-def main():
- # Get a list of all flag SVGs, and sort them by size.
- flags = []
-
- flagsDir = os.path.join('icons', 'flags')
- flagFns = os.listdir(flagsDir)
- for fn in flagFns:
- if not fn.lower().endswith('svg'):
- continue
-
- with open(os.path.join(flagsDir, fn), 'r') as f:
- buf = f.read()
- sz = len(buf)
- flags.append(OnDiskFlag(size=sz, filename=fn))
-
- flags = sorted(flags) # Sort by first tuple index (size).
-
- # Figure out the .qrc target of the individual
- # SVG files. Once a .qrc target exceeds MAX_SIZE,
- # we add a new file.
- flagsOut = []
-
- curFileContent = []
- curFileSz = 0
-
- for flag in flags:
- sz = flag.size
- fn = flag.filename
-
- curFileSz += sz
-
- curFileContent.append(fn)
-
- if curFileSz > MAX_SIZE:
- flagsOut.append(curFileContent)
-
- curFileContent = []
- curFileSz = 0
-
- if len(curFileContent) > 0:
- flagsOut.append(curFileContent)
-
- # Remove old flags qrc file.
- oldFlagsQrc = os.path.join('src', 'mumble', 'mumble_flags.qrc')
- if os.path.exists(oldFlagsQrc):
- os.remove(oldFlagsQrc)
-
- # Remove existing flags dir in src/mumble.
- flagsOutDir = os.path.join('src', 'mumble', 'flags')
- if os.path.exists(flagsOutDir):
- shutil.rmtree(flagsOutDir)
- os.mkdir(flagsOutDir)
-
- # Generate output files.
- for idx, content in enumerate(flagsOut):
- fn = 'mumble_flags_{0}.qrc'.format(idx)
-
- with codecs.open(os.path.join(flagsOutDir, fn), "w", "utf-8") as f:
- f.write('<!DOCTYPE RCC>\n')
- f.write('<RCC version="1.0">\n')
- f.write('<qresource>\n')
-
- for fn in content:
- f.write('<file alias="{0}">{1}</file>\n'.format('flags/' + fn, '../../../icons/flags/' + fn))
-
- f.write('</qresource>\n')
- f.write('</RCC>\n')
-
- # Generate .pri file for flags.
- with codecs.open(os.path.join(flagsOutDir, 'mumble_flags.pri'), "w", "utf-8") as f:
- for idx, _ in enumerate(flagsOut):
- fn = 'mumble_flags_{0}.qrc'.format(idx)
- f.write('RESOURCES *= flags/{0}\n'.format(fn))
-
-if __name__ == '__main__':
- main()