Description: Adapt to allow access to data from ~/.cache
 The installed path is not writeable, so change to an XDG
 directory as described in the supplied helper script.
Date: Tue  5 Apr 12:49:27 BST 2022
Author: Neil Williams <codehelp@debian.org>

---
--- a/pyimagetool/cmaps/CMap.py
+++ b/pyimagetool/cmaps/CMap.py
@@ -1,6 +1,8 @@
+import os
 from pathlib import Path
 from xml.dom import minidom
 import numpy as np
+import xdg
 from PIL import Image
 try:
     import matplotlib.cm as cm
@@ -51,7 +53,20 @@
     'nipy_spectral': 'nipy_spectral'
 }
 
+"""
+ Switch package to using a writeable location
+ Needs a helper to create the writeable cache.
+
+ See /usr/share/pyimagetool/debian_pyimagetool.py
+"""
 modulepath = Path(__file__).parent
+if not os.access(str(modulepath), os.W_OK):
+    modulepath = Path(xdg.xdg_cache_home(), "PyImageTool")
+if not os.access(str(modulepath), os.W_OK):
+    raise OSError(
+        "Packaged data files are not writeable, use a helper script."
+        "See /usr/share/pyimagetool/debian_pyimagetool.py"
+    )
 
 
 class CMap:
@@ -175,7 +190,10 @@
             cmap_name = filepath.stem
             mat = np.load(str(filepath))
             mat = mat[:, 0:3]
-            rows, cols = mat.shape
+            try:
+                rows, cols = mat.shape
+            except ValueError:
+                print(f"{str(filepath)} may have errors")
             if cols < 3 or rows != 256 or mat.dtype != np.uint8:
                 print(str(filepath) + ' unsupported format. Requires 256 rows and 3 columns.'
                       + f' Has rows={rows} and cols={cols}. Skipping...')
