예제 #1
0
파일: cli.py 프로젝트: bergmannf/osc2
def _init(apiurl):
    """Initialize osc library.

    apiurl is the apiurl which should be used.

    """
    if hasattr(apiurl, 'extend') and len(set(apiurl)) > 1:
        msg = ("Different apiurls are not supported at the moment: "
               "%s (using %s)" % (', '.join(apiurl), apiurl[0]))
        logger().info(msg)
        apiurl = apiurl[0]
    conf_filename = os.environ.get('OSC_CONFIG', '~/.oscrc')
    conf_filename = os.path.expanduser(conf_filename)
    cp = SafeConfigParser({'plaintext_password': True, 'aliases': ''})
    cp.read(conf_filename)
    apiurl = apiurl.strip('/')
    if apiurl == 'api':
        apiurl = 'https://api.opensuse.org'
    for section in cp.sections():
        aliases = cp.get(section, 'aliases', raw=True)
        aliases = aliases.split(',')
        if section.strip('/') == apiurl or apiurl in aliases:
            user = cp.get(section, 'user', raw=True)
            password = None
            if cp.has_option(section, 'pass'):
                password = cp.get(section, 'pass', raw=True)
            if cp.has_option(section, 'passx'):
                password = cp.get(section, 'pass', raw=True)
                password = password.decode('base64').decode('bz2')
            if (cp.has_option(section, 'keyring')
                    and cp.getboolean(section, 'keyring')):
                try:
                    import keyring
                    host = urlparse.urlparse(apiurl).hostname
                    password = keyring.get_password(host, user)
                except ImportError:
                    msg = ("keyring module not available but '%s' "
                           "stores password there") % conf_filename
                    raise ValueError(msg)
            if password is None:
                msg = "No password provided for %s" % section
                raise ValueError(msg)
            if '://' not in section:
                section = 'https://{0}'.format(section)
            Osc.init(section, username=user, password=password)
            return section
예제 #2
0
파일: cli.py 프로젝트: vikas-lamba/osc2
def _init(apiurl):
    """Initialize osc library.

    apiurl is the apiurl which should be used.

    """
    if hasattr(apiurl, 'extend') and len(set(apiurl)) > 1:
        msg = ("Different apiurls are not supported at the moment: "
               "%s (using %s)" % (', '.join(apiurl), apiurl[0]))
        logger().info(msg)
        apiurl = apiurl[0]
    conf_filename = os.environ.get('OSC_CONFIG', '~/.oscrc')
    conf_filename = os.path.expanduser(conf_filename)
    cp = SafeConfigParser({'plaintext_password': True, 'aliases': ''})
    cp.read(conf_filename)
    apiurl = apiurl.strip('/')
    if apiurl == 'api':
        apiurl = 'https://api.opensuse.org'
    for section in cp.sections():
        aliases = cp.get(section, 'aliases', raw=True)
        aliases = aliases.split(',')
        if section.strip('/') == apiurl or apiurl in aliases:
            user = cp.get(section, 'user', raw=True)
            password = None
            if cp.has_option(section, 'pass'):
                password = cp.get(section, 'pass', raw=True)
            if cp.has_option(section, 'passx'):
                password = cp.get(section, 'pass', raw=True)
                password = password.decode('base64').decode('bz2')
            if (cp.has_option(section, 'keyring')
                    and cp.getboolean(section, 'keyring')):
                try:
                    import keyring
                    host = urlparse.urlparse(apiurl).hostname
                    password = keyring.get_password(host, user)
                except ImportError:
                    msg = ("keyring module not available but '%s' "
                           "stores password there") % conf_filename
                    raise ValueError(msg)
            if password is None:
                msg = "No password provided for %s" % section
                raise ValueError(msg)
            if '://' not in section:
                section = 'https://{0}'.format(section)
            Osc.init(section, username=user, password=password)
            return section
예제 #3
0
파일: example.py 프로젝트: vikas-lamba/osc2
def _init(apiurl):
    conf_filename = os.environ.get('OSC_CONFIG', '~/.oscrc')
    conf_filename = os.path.expanduser(conf_filename)
    cp = SafeConfigParser({'plaintext_password': True, 'aliases': ''})
    cp.read(conf_filename)
    apiurl = apiurl.strip('/')
    if apiurl == 'api':
        apiurl = 'https://api.opensuse.org'
    for section in cp.sections():
        aliases = cp.get(section, 'aliases', raw=True)
        aliases = aliases.split(',')
        if section.strip('/') == apiurl or apiurl in aliases:
            user = cp.get(section, 'user', raw=True)
            password = cp.get(section, 'pass', raw=True)
            if cp.has_option(section, 'passx'):
                password = cp.get(section, 'pass', raw=True)
                password = password.decode('base64').decode('bz2')
            Osc.init(section, username=user, password=password)
            return section
예제 #4
0
파일: example.py 프로젝트: bergmannf/osc2
def _init(apiurl):
    conf_filename = os.environ.get('OSC_CONFIG', '~/.oscrc')
    conf_filename = os.path.expanduser(conf_filename)
    cp = SafeConfigParser({'plaintext_password': True, 'aliases': ''})
    cp.read(conf_filename)
    apiurl = apiurl.strip('/')
    if apiurl == 'api':
        apiurl = 'https://api.opensuse.org'
    for section in cp.sections():
        aliases = cp.get(section, 'aliases', raw=True)
        aliases = aliases.split(',')
        if section.strip('/') == apiurl or apiurl in aliases:
            user = cp.get(section, 'user', raw=True)
            password = cp.get(section, 'pass', raw=True)
            if cp.has_option(section, 'passx'):
                password = cp.get(section, 'pass', raw=True)
                password = password.decode('base64').decode('bz2')
            Osc.init(section, username=user, password=password)
            return section
예제 #5
0
파일: osctest.py 프로젝트: pombreda/osc2
 def setUp(self):
     super(OscTest, self).setUp()
     Osc.init(self.apiurl, validate=True)