File indexing completed on 2024-04-21 04:39:50

0001 #!/usr/bin/env python3
0002 #
0003 # Downloads color schemes from download.kde.org and installs them into the desired prefix
0004 # Usage: install_colorschemes.py [INSTALL_DIR]
0005 
0006 import distutils.dir_util
0007 import os
0008 import shutil
0009 import sys
0010 import tarfile
0011 import urllib.request
0012 
0013 installDir = sys.argv[1] if len(sys.argv) > 1 else None
0014 ver = "5.13.4" # Plasma version
0015 colorSchemesDir = "color-schemes"
0016 
0017 def downloadAndExtract(url, extractPath):
0018     fname = os.path.basename(url)
0019     if not os.path.exists(fname):
0020         print("Downloading {0}".format(url))
0021         urllib.request.urlretrieve(url, fname)
0022     else:
0023         print("Skipping download of {0} (file already exists)".format(url))
0024 
0025     print("Unpacking {0}".format(fname))
0026     dirname = fname.replace(".tar.xz", "")
0027     shutil.rmtree(dirname, ignore_errors=True)
0028     with tarfile.open(fname) as tar:
0029         for tarinfo in tar.getmembers():
0030             if tarinfo.name.startswith(extractPath):
0031                 tarinfo.name = os.path.basename(tarinfo.name) # remove the path by reset it
0032                 tar.extract(member=tarinfo, path=colorSchemesDir)
0033 
0034 downloadAndExtract('https://download.kde.org/stable/plasma/{0}/breeze-{0}.tar.xz'.format(ver),
0035                    "breeze-{0}/colors/".format(ver))
0036 downloadAndExtract('https://download.kde.org/stable/plasma/{0}/plasma-desktop-{0}.tar.xz'.format(ver),
0037                    "plasma-desktop-{0}/kcms/colors/schemes/".format(ver))
0038 
0039 # Cleanup
0040 os.remove(os.path.join(colorSchemesDir, "CMakeLists.txt"))
0041 
0042 print("Available color schemes: {0}".format(", ".join(os.listdir(colorSchemesDir))))
0043 
0044 if installDir:
0045     print("Installing to: {0}".format(installDir))
0046     distutils.dir_util.copy_tree(colorSchemesDir, os.path.join(installDir, colorSchemesDir))