changeset 44031:bba9149adc14

resourceutil: implement `contents()` to iterate over resources in a package Differential Revision: https://phab.mercurial-scm.org/D7774
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 29 Dec 2019 20:35:34 -0500
parents 42a897bf678c
children 5ac0e6f19eb4
files mercurial/utils/resourceutil.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)