Skip to content

Commit

Permalink
check for file types
Browse files Browse the repository at this point in the history
  • Loading branch information
baijum committed Jul 5, 2021
1 parent 88ca131 commit f3fd039
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[metadata]
name = pyservicebinding
version = 0.2.1
version = 0.2.2
author = Baiju Muthukadan
author_email = baiju.m.mail@gmail.com
description = Kubernetes Service Binding Library for Python Applications
Expand Down
12 changes: 12 additions & 0 deletions src/pyservicebinding/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ def all_bindings(self) -> list[dict[str, str]]:
root = self.root
l = []
for dirname in os.listdir(root):
if not os.path.isdir(os.path.join(root, dirname)):
continue
b = {}
for filename in os.listdir(os.path.join(root, dirname)):
if not os.path.isfile(os.path.join(root, dirname, filename)):
continue
b[filename] = open(os.path.join(root, dirname, filename)).read().strip()

l.append(b)
Expand All @@ -74,6 +78,8 @@ def bindings(self, _type: str, provider: typing.Optional[str] = None) -> list[di
b = {}
if provider:
for dirname in os.listdir(root):
if not os.path.isdir(os.path.join(root, dirname)):
continue
typepath = os.path.join(root, dirname, "type")
providerpath = os.path.join(root, dirname, "provider")
if os.path.exists(typepath):
Expand All @@ -86,18 +92,24 @@ def bindings(self, _type: str, provider: typing.Optional[str] = None) -> list[di
continue

for filename in os.listdir(os.path.join(root, dirname)):
if not os.path.isfile(os.path.join(root, dirname, filename)):
continue
b[filename] = open(os.path.join(root, dirname, filename)).read().strip()

l.append(b)
else:
for dirname in os.listdir(root):
if not os.path.isdir(os.path.join(root, dirname)):
continue
typepath = os.path.join(root, dirname, "type")
if os.path.exists(typepath):
typevalue = open(typepath).read().strip()
if typevalue != _type:
continue

for filename in os.listdir(os.path.join(root, dirname)):
if not os.path.isfile(os.path.join(root, dirname, filename)):
continue
b[filename] = open(os.path.join(root, dirname, filename)).read().strip()

l.append(b)
Expand Down
6 changes: 6 additions & 0 deletions src/pyservicebinding/binding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

def test_bindings(tmpdir, monkeypatch):
bindings_dir = tmpdir.mkdir("bindings")
junk = bindings_dir.join("junk")
junk.write("junk text")
sb1 = tmpdir.join("bindings").mkdir("sb1")
sb1.mkdir("sub1")
_type = sb1.join("type")
_type.write("mysql")
username = sb1.join("username")
Expand Down Expand Up @@ -46,7 +49,10 @@ def test_bindings(tmpdir, monkeypatch):

def test_all_bindings(tmpdir, monkeypatch):
bindings_dir = tmpdir.mkdir("bindings")
junk = bindings_dir.join("junk")
junk.write("junk text")
sb1 = tmpdir.join("bindings").mkdir("sb1")
sb1.mkdir("sub1")
_type = sb1.join("type")
_type.write("mysql")
username = sb1.join("username")
Expand Down

0 comments on commit f3fd039

Please sign in to comment.