resourceutil: implement `contents()` to iterate over resources in a package
Differential Revision: https://phab.mercurial-scm.org/D7774
--- 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)