resourceutil: implement `contents()` to iterate over resources in a package
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 29 Dec 2019 20:35:34 -0500
changeset 44031 bba9149adc14
parent 44030 42a897bf678c
child 44032 5ac0e6f19eb4
resourceutil: implement `contents()` to iterate over resources in a package Differential Revision: https://phab.mercurial-scm.org/D7774
mercurial/utils/resourceutil.py
--- a/mercurial/utils/resourceutil.py	Sun Dec 29 20:32:56 2019 -0500
+++ b/mercurial/utils/resourceutil.py	Sun Dec 29 20:35:34 2019 -0500
@@ -55,6 +55,10 @@
             pycompat.sysstr(package), encoding.strfromlocal(name)
         )
 
+    def contents(package):
+        for r in resources.contents(pycompat.sysstr(package)):
+            yield encoding.strtolocal(r)
+
 
 except (ImportError, AttributeError):
 
@@ -72,3 +76,9 @@
             return os.path.isfile(pycompat.fsdecode(path))
         except (IOError, OSError):
             return False
+
+    def contents(package):
+        path = pycompat.fsdecode(_package_path(package))
+
+        for p in os.listdir(path):
+            yield pycompat.fsencode(p)