PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/silverlining/createconf.py

https://bitbucket.org/ianb/silverlining/
Python | 39 lines | 28 code | 5 blank | 6 comment | 3 complexity | 628feb21325f5735433ab1d82a703b6c MD5 | raw file
Possible License(s): GPL-2.0
  1. """Creates ~/.silverlining.conf
  2. This builds the file from a template, and asks the user some questions
  3. about how to build it.
  4. """
  5. import os
  6. import tempita
  7. template = tempita.Template.from_filename(
  8. os.path.join(os.path.dirname(__file__), 'silverlining.conf.tmpl'))
  9. silverlining_conf = os.path.join(os.environ['HOME'], '.silverlining.conf')
  10. def create_conf():
  11. """Create a brand-new ~/.silverlining.conf"""
  12. print 'Creating %s' % silverlining_conf
  13. username = raw_input('Your service-provider username: ')
  14. api_key = raw_input('Your service-provider API key: ')
  15. for path in ['id_rsa.pub', 'id_dsa.pub']:
  16. pubkey_path = os.path.join(os.environ['HOME'], '.ssh', path)
  17. if os.path.exists(pubkey_path):
  18. print 'Using %s' % pubkey_path
  19. fp = open(pubkey_path)
  20. pubkey = fp.read().strip()
  21. fp.close()
  22. break
  23. else:
  24. pubkey = None
  25. print "%s doesn't exist" % pubkey_path
  26. print " you won't automatically be able to login to new servers"
  27. content = template.substitute(
  28. username=username, api_key=api_key, pubkey=pubkey,
  29. silverlining_location=os.path.dirname(__file__),
  30. )
  31. fp = open(silverlining_conf, 'w')
  32. fp.write(content)
  33. fp.close()