~ibmcharmers/charms/xenial/ibm-cinder-storwize-svc/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/setuptools/command/upload.py

  • Committer: Ankammarao
  • Date: 2017-03-06 05:11:42 UTC
  • Revision ID: achittet@in.ibm.com-20170306051142-dpg27z4es1k56hfn
Marked tests folder executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import getpass
 
2
from distutils.command import upload as orig
 
3
 
 
4
 
 
5
class upload(orig.upload):
 
6
    """
 
7
    Override default upload behavior to obtain password
 
8
    in a variety of different ways.
 
9
    """
 
10
 
 
11
    def finalize_options(self):
 
12
        orig.upload.finalize_options(self)
 
13
        self.username = (
 
14
            self.username or
 
15
            getpass.getuser()
 
16
        )
 
17
        # Attempt to obtain password. Short circuit evaluation at the first
 
18
        # sign of success.
 
19
        self.password = (
 
20
            self.password or
 
21
            self._load_password_from_keyring() or
 
22
            self._prompt_for_password()
 
23
        )
 
24
 
 
25
    def _load_password_from_keyring(self):
 
26
        """
 
27
        Attempt to load password from keyring. Suppress Exceptions.
 
28
        """
 
29
        try:
 
30
            keyring = __import__('keyring')
 
31
            return keyring.get_password(self.repository, self.username)
 
32
        except Exception:
 
33
            pass
 
34
 
 
35
    def _prompt_for_password(self):
 
36
        """
 
37
        Prompt for a password on the tty. Suppress Exceptions.
 
38
        """
 
39
        try:
 
40
            return getpass.getpass()
 
41
        except (Exception, KeyboardInterrupt):
 
42
            pass