Patchwork D7774: resourceutil: implement `contents()` to iterate over resources in a package

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2020, 7:51 p.m.
Message ID <aa3b2555b658a14c18b84149c6883e1f@localhost.localdomain>
Download mbox | patch
Permalink /patch/44206/
State Not Applicable
Headers show

Comments

phabricator - Jan. 8, 2020, 7:51 p.m.
Closed by commit rHGbba9149adc14: resourceutil: implement `contents()` to iterate over resources in a package (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7774?vs=19005&id=19103

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7774/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7774

AFFECTED FILES
  mercurial/utils/resourceutil.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/utils/resourceutil.py b/mercurial/utils/resourceutil.py
--- a/mercurial/utils/resourceutil.py
+++ b/mercurial/utils/resourceutil.py
@@ -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)