示例#1
0
文件: conf.py 项目: myMeow/osc
def add_section(filename, url, user, passwd):
    """
    Add a section to config file for new api url.
    """
    global config
    cp = get_configParser(filename)
    try:
        cp.add_section(url)
    except OscConfigParser.ConfigParser.DuplicateSectionError:
        # Section might have existed, but was empty
        pass
    if config["use_keyring"] and GENERIC_KEYRING:
        protocol, host = parse_apisrv_url(None, url)
        keyring.set_password(host, user, passwd)
        cp.set(url, "keyring", "1")
        cp.set(url, "user", user)
        cp.remove_option(url, "pass")
        cp.remove_option(url, "passx")
    elif config["gnome_keyring"] and GNOME_KEYRING:
        protocol, host = parse_apisrv_url(None, url)
        gnomekeyring.set_network_password_sync(user=user, password=passwd, protocol=protocol, server=host)
        cp.set(url, "keyring", "1")
        cp.remove_option(url, "pass")
        cp.remove_option(url, "passx")
    else:
        cp.set(url, "user", user)
        if not config["plaintext_passwd"]:
            cp.remove_option(url, "pass")
            cp.set(url, "passx", base64.b64encode(passwd.encode("bz2")))
        else:
            cp.remove_option(url, "passx")
            cp.set(url, "pass", passwd)
    write_config(filename, cp)
示例#2
0
文件: conf.py 项目: myMeow/osc
def write_initial_config(conffile, entries, custom_template=""):
    """
    write osc's intial configuration file. entries is a dict which contains values
    for the config file (e.g. { 'user' : 'username', 'pass' : 'password' } ).
    custom_template is an optional configuration template.
    """
    conf_template = custom_template or new_conf_template
    config = DEFAULTS.copy()
    config.update(entries)
    # at this point use_keyring and gnome_keyring are str objects
    if config["use_keyring"] == "1" and GENERIC_KEYRING:
        protocol, host = parse_apisrv_url(None, config["apiurl"])
        keyring.set_password(host, config["user"], config["pass"])
        config["pass"] = ""
        config["passx"] = ""
    elif config["gnome_keyring"] == "1" and GNOME_KEYRING:
        protocol, host = parse_apisrv_url(None, config["apiurl"])
        gnomekeyring.set_network_password_sync(
            user=config["user"], password=config["pass"], protocol=protocol, server=host
        )
        config["user"] = ""
        config["pass"] = ""
        config["passx"] = ""
    if not config["plaintext_passwd"]:
        config["pass"] = ""
    else:
        config["passx"] = base64.b64encode(config["pass"].encode("bz2"))

    sio = StringIO.StringIO(conf_template.strip() % config)
    cp = OscConfigParser.OscConfigParser(DEFAULTS)
    cp.readfp(sio)
    write_config(conffile, cp)
示例#3
0
文件: Calendar.py 项目: jessevdk/jft
	def on_authentication_response(self, dlg, response, handler):
		if response == gtk.RESPONSE_ACCEPT:
			print gnomekeyring.set_network_password_sync(None, self.entry_username.get_text(), 'gmail.com', None, None, None, None, 0, self.entry_passwd.get_text())
		else:
			handler(None, None)
		
		dlg.destroy()
示例#4
0
文件: conf.py 项目: mmohring/osc
def write_initial_config(conffile, entries, custom_template=''):
    """
    write osc's intial configuration file. entries is a dict which contains values
    for the config file (e.g. { 'user' : 'username', 'pass' : 'password' } ).
    custom_template is an optional configuration template.
    """
    conf_template = custom_template or new_conf_template
    config = DEFAULTS.copy()
    config.update(entries)
    # at this point use_keyring and gnome_keyring are str objects
    if config['use_keyring'] == '1' and GENERIC_KEYRING:
        protocol, host = \
            parse_apisrv_url(None, config['apiurl'])
        keyring.set_password(host, config['user'], config['pass'])
        config['pass'] = ''
        config['passx'] = ''
    elif config['gnome_keyring'] == '1' and GNOME_KEYRING:
        protocol, host = \
            parse_apisrv_url(None, config['apiurl'])
        gnomekeyring.set_network_password_sync(user=config['user'],
                                               password=config['pass'],
                                               protocol=protocol,
                                               server=host)
        config['user'] = ''
        config['pass'] = ''
        config['passx'] = ''
    if not config['plaintext_passwd']:
        config['pass'] = ''
    else:
        config['passx'] = base64.b64encode(config['pass'].encode('bz2'))

    sio = StringIO(conf_template.strip() % config)
    cp = OscConfigParser.OscConfigParser(DEFAULTS)
    cp.readfp(sio)
    write_config(conffile, cp)
示例#5
0
 def set_password(self, url, user, password):
     scheme, host, path = self._urlsplit(url)
     gnomekeyring.set_network_password_sync(user=user,
                                            password=password,
                                            protocol=scheme,
                                            server=host,
                                            object=path)
     self._cp.set(url, self.config_entry, self._qualified_name())
示例#6
0
文件: mm_util.py 项目: e-bacho/mm
def put_password_by_key(key, password):
    if sys.platform == 'linux2':
        try:
            gnomekeyring.set_network_password_sync(None, key, 'MavensMate: '+key,
                None, None, None, None, 0, password)
        except gnomekeyring.CancelledError:
            raise MMException('Unable to set password')
    else:
        keyring.set_password('MavensMate: '+key, key, password)
示例#7
0
 def set_password(self, service, username, password):
     """Set password for the username of the service
     """
     try:
         gnomekeyring.set_network_password_sync(None, username, service,
             None, None, None, None, 0, password)
     except gnomekeyring.CancelledError:
         # The user pressed "Cancel" when prompted to unlock their keyring.
         raise PasswordSetError()
示例#8
0
文件: util.py 项目: cpurodriguez/mm
def put_password_by_key(key, password):
    if sys.platform == 'linux2':
        try:
            gnomekeyring.set_network_password_sync(None, key, 'MavensMate: '+key,
                None, None, None, None, 0, password)
        except gnomekeyring.CancelledError:
            raise MMException('Unable to set password')
    else:
        keyring.set_password('MavensMate: '+key, key, password)
示例#9
0
 def set_password(self, service, username, password):
     """Set password for the username of the service
     """
     try:
         gnomekeyring.set_network_password_sync(None, username, service,
                                                None, None, None, None, 0,
                                                password)
     except gnomekeyring.CancelledError:
         # The user pressed "Cancel" when prompted to unlock their keyring.
         raise PasswordSetError()
示例#10
0
def put_password_by_key(key, password):
    use_keyring = config.connection.get_plugin_client_setting('mm_use_keyring', False)
    if use_keyring:
        if sys.platform == 'linux2':
            try:
                gnomekeyring.set_network_password_sync(None, key, 'MavensMate: '+key,
                    None, None, None, None, 0, password)
            except gnomekeyring.CancelledError:
                raise MMException('Unable to set password')
        else:
            keyring.set_password('MavensMate: '+key, key, password)
    else: #not recommend! we only use this for CI
        encoded = encode(key, password)
        src = open(os.path.join(config.connection.get_app_settings_directory(),key+'.json'), "wb")
        src.write(json.dumps({'value':encoded}))
        src.close()
示例#11
0
文件: gktool.py 项目: ssato/misc
    def create(self, name, attrs, secret, keyring=gk.get_default_keyring_sync(), force=False):
        self.check_attributes(attrs)
        attrs2 = self.del_empty_attributes(attrs)

        if not force and self.find(attrs, True) != []:
            logging.warn(" Secret already exists for display_name = '%s', attrs = '%s'" % (name, str(attrs)))
            return -1

        return gk.set_network_password_sync(keyring, password=secret, **attrs2)
示例#12
0
文件: conf.py 项目: hmonika/osc
def add_section(filename, url, user, passwd):
    """
    Add a section to config file for new api url.
    """
    global config
    cp = get_configParser(filename)
    try:
        cp.add_section(url)
    except OscConfigParser.configparser.DuplicateSectionError:
        # Section might have existed, but was empty
        pass
    if config['use_keyring'] and GENERIC_KEYRING:
        protocol, host, path = parse_apisrv_url(None, url)
        keyring.set_password(host, user, passwd)
        cp.set(url, 'keyring', '1')
        cp.set(url, 'user', user)
        cp.remove_option(url, 'pass')
        cp.remove_option(url, 'passx')
    elif config['gnome_keyring'] and GNOME_KEYRING:
        protocol, host, path = parse_apisrv_url(None, url)
        gnomekeyring.set_network_password_sync(
            user=user,
            password=passwd,
            protocol=protocol,
            server=host,
            object=path)
        cp.set(url, 'keyring', '1')
        cp.remove_option(url, 'pass')
        cp.remove_option(url, 'passx')
    else:
        cp.set(url, 'user', user)
        if not config['plaintext_passwd']:
            cp.remove_option(url, 'pass')
            cp.set(url, 'passx', passx_encode(passwd))
        else:
            cp.remove_option(url, 'passx')
            cp.set(url, 'pass', passwd)
    write_config(filename, cp)
示例#13
0
文件: conf.py 项目: cav71/osc
def write_initial_config(conffile, entries, custom_template=''):
    """
    write osc's intial configuration file. entries is a dict which contains values
    for the config file (e.g. { 'user' : 'username', 'pass' : 'password' } ).
    custom_template is an optional configuration template.
    """
    conf_template = custom_template or new_conf_template
    config = DEFAULTS.copy()
    config.update(entries)
    # at this point use_keyring and gnome_keyring are str objects
    if config['use_keyring'] == '1' and GENERIC_KEYRING:
        protocol, host, path = \
            parse_apisrv_url(None, config['apiurl'])
        keyring.set_password(host, config['user'], config['pass'])
        config['pass'] = ''
        config['passx'] = ''
    elif config['gnome_keyring'] == '1' and GNOME_KEYRING:
        protocol, host, path = \
            parse_apisrv_url(None, config['apiurl'])
        gnomekeyring.set_network_password_sync(
            user=config['user'],
            password=config['pass'],
            protocol=protocol,
            server=host,
            object=path)
        config['user'] = ''
        config['pass'] = ''
        config['passx'] = ''
    if not config['plaintext_passwd']:
        config['pass'] = ''
    else:
        config['passx'] = passx_encode(config['pass'])

    sio = StringIO(conf_template.strip() % config)
    cp = OscConfigParser.OscConfigParser(DEFAULTS)
    cp.readfp(sio)
    write_config(conffile, cp)
                  help="The port", metavar="PORT")
parser.add_option("-?", "--help", action="help", help="show this help message and exit")

parser.set_defaults(user=None,
                    domain=None,
                    server=None,
                    object=None,
                    protocol=None,
                    authtype=None,
                    port=0)
(options, args) = parser.parse_args()

password=None
password=getpass.getpass("Enter the password: ")

# This is the only required argument
if password is None:
    parser.print_help()
    sys.exit(1)

gnomekeyring.set_network_password_sync(
    user=options.user,
    domain=options.domain,
    server=options.server,
    object=options.object,
    protocol=options.protocol,
    authtype=options.authtype,
    port=options.port,
    password=password)

示例#15
0
def set_password(**kwargs):
    password = getpass.getpass('New password: ')

    gkey.set_network_password_sync(password=password, **kwargs)