chiark / gitweb /
New calls add some delay, so cache the results.
authordaid303 <daid303@gmail.com>
Tue, 23 Apr 2013 12:01:01 +0000 (14:01 +0200)
committerdaid303 <daid303@gmail.com>
Tue, 23 Apr 2013 12:01:01 +0000 (14:01 +0200)
Cura/util/removableStorage.py

index 0562b74d402f50a984ff0cfc57714bfd135b0f4a..27d5c7055fdcd1e060e280f0e67395c161e810b4 100644 (file)
@@ -3,12 +3,16 @@ import string
 import glob
 import os
 import stat
+import time
 import subprocess
 try:
        from xml.etree import cElementTree as ElementTree
 except:
        from xml.etree import ElementTree
 
+_removeableCache = None
+_removeableCacheTime = None
+
 def _parseStupidPListXML(e):
        if e.tag == 'plist':
                return _parseStupidPListXML(list(e)[0])
@@ -46,6 +50,10 @@ def _findInTree(t, n):
        return ret
 
 def getPossibleSDcardDrives():
+       global _removeableCache, _removeableCacheTime
+       if _removeableCache is not None and time.time() - _removeableCacheTime < 5.0:
+               return _removeableCache
+
        drives = []
        if platform.system() == "Windows":
                from ctypes import windll
@@ -82,6 +90,9 @@ def getPossibleSDcardDrives():
        else:
                for volume in glob.glob('/media/*'):
                        drives.append((os.path.basename(volume), volume, os.path.basename(volume)))
+
+       _removeableCache = drives
+       _removeableCacheTime = time.time()
        return drives
 
 if __name__ == '__main__':