Skip to content

Commit

Permalink
Restore Remote object context manager support
Browse files Browse the repository at this point in the history
This was broken in e5f7f44.
  • Loading branch information
Ape committed Dec 29, 2016
1 parent ce57e04 commit 88ea177
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 9 additions & 10 deletions samsungctl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,15 @@ def main():
return

try:
remote = Remote(config)

for key in args.key:
remote.control(key)

if args.interactive:
logging.getLogger().setLevel(logging.ERROR)
interactive.run(remote)
elif len(args.key) == 0:
logging.warning("Warning: No keys specified.")
with Remote(config) as remote:
for key in args.key:
remote.control(key)

if args.interactive:
logging.getLogger().setLevel(logging.ERROR)
interactive.run(remote)
elif len(args.key) == 0:
logging.warning("Warning: No keys specified.")
except exceptions.ConnectionClosed:
logging.error("Error: Connection closed!")
except exceptions.AccessDenied:
Expand Down
6 changes: 6 additions & 0 deletions samsungctl/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def __init__(self, config):
else:
raise exceptions.UnknownMethod()

def __enter__(self):
return self.remote.__enter__()

def __exit__(self, type, value, traceback):
self.remote.__exit__(type, value, traceback)

def close(self):
return self.remote.close()

Expand Down

0 comments on commit 88ea177

Please sign in to comment.