Guest User

Untitled

a guest
Aug 20th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import contextlib
  2. import subprocess
  3. import tempfile
  4.  
  5.  
  6. @contextlib.contextmanager
  7. def authfile(username, password):
  8. auth = dict(username=username, password=password)
  9. with tempfile.TemporaryDirectory() as tempdir:
  10. auth_file = os.path.join(tempdir, 'auth.json')
  11. with open(auth_file, 'w') as fd:
  12. json.dump(auth, fd)
  13.  
  14. yield auth_file
  15.  
  16.  
  17. def main():
  18. username = "foo"
  19. password = "bar"
  20. auth_file = authfile(username, password)
  21. subprocess.check_call(['prog', '--autfile', auth_file])
Add Comment
Please, Sign In to add comment