aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/Lib/dircache.py
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-06-13 20:06:38 +1000
committerRogueAI42 <[email protected]>2017-06-13 20:06:38 +1000
commit2acfa34596061a9236bb6a9df1e3f3a0c01d6ff0 (patch)
tree72954044f3dde5f9a17d12f99cd57a819f1b0f58 /ShiftOS_TheReturn/Lib/dircache.py
parenta2db5d39096cbf4d32412ad40168769ca63d9493 (diff)
downloadshiftos_thereturn-2acfa34596061a9236bb6a9df1e3f3a0c01d6ff0.tar.gz
shiftos_thereturn-2acfa34596061a9236bb6a9df1e3f3a0c01d6ff0.tar.bz2
shiftos_thereturn-2acfa34596061a9236bb6a9df1e3f3a0c01d6ff0.zip
Python API
It uses a meta-language and a CSharpCodeProvider on startup. I will release a tutorial on the forums soon showing how to use it. This commit also adds an extremely basic loading screen which shows while Desktop is getting everything ready. Which can take a while if you have any Python mods. Thanks, IronPython.
Diffstat (limited to 'ShiftOS_TheReturn/Lib/dircache.py')
-rw-r--r--ShiftOS_TheReturn/Lib/dircache.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/ShiftOS_TheReturn/Lib/dircache.py b/ShiftOS_TheReturn/Lib/dircache.py
new file mode 100644
index 0000000..7e4f0b5
--- /dev/null
+++ b/ShiftOS_TheReturn/Lib/dircache.py
@@ -0,0 +1,41 @@
+"""Read and cache directory listings.
+
+The listdir() routine returns a sorted list of the files in a directory,
+using a cache to avoid reading the directory more often than necessary.
+The annotate() routine appends slashes to directories."""
+from warnings import warnpy3k
+warnpy3k("the dircache module has been removed in Python 3.0", stacklevel=2)
+del warnpy3k
+
+import os
+
+__all__ = ["listdir", "opendir", "annotate", "reset"]
+
+cache = {}
+
+def reset():
+ """Reset the cache completely."""
+ global cache
+ cache = {}
+
+def listdir(path):
+ """List directory contents, using cache."""
+ try:
+ cached_mtime, list = cache[path]
+ del cache[path]
+ except KeyError:
+ cached_mtime, list = -1, []
+ mtime = os.stat(path).st_mtime
+ if mtime != cached_mtime:
+ list = os.listdir(path)
+ list.sort()
+ cache[path] = mtime, list
+ return list
+
+opendir = listdir # XXX backward compatibility
+
+def annotate(head, list):
+ """Add '/' suffixes to directories."""
+ for i in range(len(list)):
+ if os.path.isdir(os.path.join(head, list[i])):
+ list[i] = list[i] + '/'