File indexing completed on 2024-04-21 04:01:56
0001 #!/usr/bin/env python3 0002 # -*- coding: utf-8 -*- 0003 0004 """ 0005 Copyright (C) 2008-2016 Wolfgang Rohdewald <wolfgang@rohdewald.de> 0006 0007 SPDX-License-Identifier: GPL-2.0 0008 0009 0010 Start this in the installation directory of Kajongg: That 0011 is where this program resides. Below you find a code 0012 block that might have to be adapted. 0013 """ 0014 0015 from subprocess import check_output, call, CalledProcessError 0016 from shutil import copy, move, copytree, rmtree 0017 0018 import os 0019 import zipfile 0020 import tempfile 0021 0022 from qt import QStandardPaths 0023 0024 # pylint:disable=invalid-name 0025 0026 0027 def makeIcon(svgName, icoName): 0028 """generates icoName.ico""" 0029 tmpDir = tempfile.mkdtemp(prefix='kaj') 0030 0031 def pngName(resolution): 0032 """name for this resolution""" 0033 return '{}/kajongg{}.png'.format( 0034 tmpDir, resolution) 0035 resolutions = (16, 24, 32, 40, 48, 64, 96, 128) 0036 try: 0037 for resolution in resolutions: 0038 call( 0039 'inkscape -z -e {outfile} -w {resolution} ' 0040 '-h {resolution} {infile}'.format( 0041 outfile=pngName(resolution), 0042 resolution=resolution, 0043 infile=svgName).split()) 0044 call('convert {pngFiles} {icoName}.ico'.format( 0045 pngFiles=' '.join(pngName(x) 0046 for x in resolutions), icoName=icoName).split()) 0047 finally: 0048 for resolution2 in resolutions: 0049 # if we re-use resolution, pylint sees a problem ... 0050 if os.path.exists(pngName(resolution2)): 0051 os.remove(pngName(resolution2)) 0052 os.rmdir(tmpDir) 0053 0054 iconDir = check_output( 0055 "kf5-config --expandvars --install icon".split()).strip() 0056 iconDir = iconDir.decode() 0057 0058 oxy48 = iconDir + '/oxygen/base/48x48' 0059 oxy48Cat = oxy48 + '/categories/' 0060 oxy48Act = oxy48 + '/actions/' 0061 oxy48Apps = oxy48 + '/apps/' 0062 oxy48Status = oxy48 + '/status/' 0063 0064 DEST = 'share' 0065 if os.path.exists(DEST): 0066 rmtree(DEST) 0067 0068 targetDir = DEST + '/kmahjongglib' 0069 kmjLibDir = QStandardPaths.locate(QStandardPaths.AppDataLocation, 'kmahjongglib', QStandardPaths.LocateDirectory) 0070 copytree(kmjLibDir, targetDir) 0071 for tileset in ('alphabet', 'egypt'): 0072 for extension in ('copyright', 'desktop', 'svgz'): 0073 os.remove(targetDir + '/tilesets/{}.{}'.format(tileset, extension)) 0074 0075 os.makedirs(DEST + '/kajongg') 0076 voiceDir = QStandardPaths.locate(QStandardPaths.AppDataLocation, 'kajongg/voices', QStandardPaths.LocateDirectory) 0077 copytree(voiceDir, DEST + '/kajongg/voices') 0078 0079 for bellSound in ('/usr/share/sounds/KDE-Im-Message-In.ogg', ): 0080 if os.path.exists(bellSound): 0081 os.makedirs(DEST + '/sounds') 0082 copy(bellSound, DEST + '/sounds/bell.ogg') 0083 break 0084 0085 os.makedirs(DEST + '/icons') 0086 copy(oxy48Cat + 'applications-education.png', DEST + '/icons') 0087 copy(oxy48Status + 'dialog-information.png', DEST + '/icons') 0088 copy(oxy48Status + 'dialog-warning.png', DEST + '/icons') 0089 copy(oxy48Apps + 'preferences-plugin-script.png', DEST + '/icons') 0090 copy(oxy48Apps + 'preferences-desktop-locale.png', DEST + '/icons') 0091 0092 0093 for png in ( 0094 'application-exit', 'games-config-background', 'arrow-right', 0095 'format-list-ordered', 'object-rotate-left', 'help-contents', 0096 'dialog-close', 'im-user', 'draw-freehand', 'call-start', 0097 'configure', 'games-config-tiles', 'arrow-right-double', 0098 'document-new', 'edit-delete', 'document-open', 'list-add-user', 0099 'list-remove-user', 'configure-toolbars', 0100 'go-up', 'go-down', 'go-next', 'go-previous'): 0101 copy('{}/{}.png'.format(oxy48Act, png), DEST + '/icons') 0102 0103 oggdec = 'oggdecV1.10.1.zip' 0104 try: 0105 call('wget https://www.rarewares.org/files/ogg/{}'.format(oggdec).split()) 0106 with zipfile.ZipFile(oggdec) as ziparch: 0107 ziparch.extract('oggdec.exe') 0108 finally: 0109 os.remove(oggdec) 0110 move('oggdec.exe', DEST + '/kajongg/voices') 0111 0112 copy('backgroundselector.ui', DEST + '/kajongg') 0113 copy('tilesetselector.ui', DEST + '/kajongg') 0114 0115 copy('../icons/sc-apps-kajongg.svgz', DEST + '/icons/kajongg.svgz') 0116 0117 makeIcon('../icons/sc-apps-kajongg.svgz', 'kajongg') 0118 makeIcon( 0119 iconDir + 0120 '/hicolor/scalable/actions/games-kajongg-law.svgz', 0121 'games-kajongg-law') 0122 copy('kajongg.ico', DEST + '/icons') 0123 copy('games-kajongg-law.ico', DEST + '/icons') 0124 0125 # select sufficiently complete languages from 0126 # https://websvn.kde.org/trunk/l10n-kf5 0127 languages = ( 0128 'bs', 'ca', 'da', 'de', 'en_GB', 'es', 'et', 'fr', 'gl', 'it', 'kk', 0129 'km', 'nl', 'nb', 'nds', 0130 'pl', 'pt', 'pt_BR', 'ru', 'sl', 'sv', 'uk', 'zh_TW') 0131 0132 # languages = ('de', 'zh_TW') 0133 0134 for lang in languages: 0135 print('getting language', lang) 0136 os.makedirs(DEST + '/locale/{}/LC_MESSAGES'.format(lang)) 0137 DEVNULL = open(os.devnull, 'wb') 0138 for filename in ( 0139 'kdegames/kajongg', 0140 'kdegames/libkmahjongg5', 0141 'kdegames/desktop_kdegames_libkmahjongg'): 0142 try: 0143 mo_data = check_output( 0144 'svn cat svn://anonsvn.kde.org/home/kde/' 0145 'trunk/l10n-kf5/{}/messages/{}.po'.format( 0146 lang, filename).split(), stderr=DEVNULL) 0147 print('found:', lang, filename) 0148 with open('x.po', 'wb') as outfile: 0149 outfile.write(mo_data) 0150 call( 0151 'msgfmt x.po -o {}/locale/{}/LC_MESSAGES/{}.mo'.format( 0152 DEST, 0153 lang, 0154 filename.split('/')[1]).split()) 0155 os.remove('x.po') 0156 except CalledProcessError: 0157 print('not found:', lang, filename)