From patchwork Wed Jan 8 19:51:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7774: resourceutil: implement `contents()` to iterate over resources in a package From: phabricator X-Patchwork-Id: 44206 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 8 Jan 2020 19:51:36 +0000 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 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)