コード例 #1
0
ファイル: cli.py プロジェクト: dastergon/pybugz
def login(conn):
	"""Authenticate a session.
	"""
	if conn.skip_auth:
		log_debug('Skipping authentication', 3)
		return

	conn.load_token()
	if conn.bz_token is not None:
		return

	# prompt for username if we were not supplied with it
	if getattr(conn, 'user', None) is None:
		log_info('No username given.')
		user = input('Username: '******'password', None) is None:
		if getattr(conn, 'passwordcmd', None) is None:
			log_info('No password given.')
			password = getpass.getpass()
		else:
			process = subprocess.Popen(conn.passwordcmd, shell=True,
				stdout=subprocess.PIPE)
			password, _ = process.communicate()
			password = password.splitlines()[0]
	else:
		password = conn.password

	# perform login
	params = {}
	params['login'] = user
	params['password'] = password
	log_info('Logging in')
	result = conn.call_bz(conn.bz.User.login, params)
	if 'token' in result:
		conn.save_token(result['token'])
コード例 #2
0
ファイル: connection.py プロジェクト: Charles-Long/pybugz
	def __init__(self, args, config):
		for key in vars(args):
			setattr(self, key, getattr(args, key))

		if not hasattr(self, 'connection'):
			if config.has_option('default', 'connection'):
				self.connection = get_config_option(config.get,
					'default', 'connection')
			else:
				log_error('No default connection specified')
				sys.exit(1)

		if self.connection not in config.sections():
			log_error('connection "{0}" not found'.format(self.connection))
			sys.exit(1)

		if not hasattr(self, 'base'):
			if config.has_option(self.connection, 'base'):
				self.base = get_config_option(config.get,
					self.connection, 'base')
			else:
				log_error('No base URL specified')
				sys.exit(1)

		if not hasattr(self, 'component'):
			if config.has_option(self.connection, 'component'):
				self.component = get_config_option(config.get,
					self.connection, 'component')

		if not hasattr(self, 'user'):
			if config.has_option(self.connection, 'user'):
				self.user = get_config_option(config.get,
					self.connection, 'user')

		if not hasattr(self, 'password'):
			if config.has_option(self.connection, 'password'):
				self.password = get_config_option(config.get,
					self.connection, 'password')

		if not hasattr(self, 'passwordcmd'):
			if config.has_option(self.connection, 'passwordcmd'):
				self.passwordcmd = get_config_option(config.get,
					self.connection, 'passwordcmd')

		if not hasattr(self, 'product'):
			if config.has_option(self.connection, 'product'):
				self.product = get_config_option(config.get,
					self.connection, 'product')

		if not hasattr(self, 'columns'):
			if config.has_option(self.connection, 'columns'):
				self.columns = get_config_option(config.getint,
					self.connection, 'columns')
			else:
				self.columns = terminal_width()

		if not hasattr(self, 'debug'):
			if config.has_option(self.connection, 'debug'):
				self.debug = get_config_option(config.getint,
					self.connection, 'debug')
			else:
				self.debug = 0
		log_setDebugLevel(self.debug)

		if not hasattr(self, 'quiet'):
			if config.has_option(self.connection, 'quiet'):
				self.quiet = get_config_option(config.getboolean,
					self.connection, 'quiet')
			else:
				self.quiet = False
		log_setQuiet(self.quiet)

		if config.has_option(self.connection, 'search_statuses'):
			self.search_statuses = get_config_option(config.get, self.connection,
					'search_statuses').split()

		if not hasattr(self, 'skip_auth'):
			if config.has_option(self.connection, 'skip_auth'):
				self.skip_auth = get_config_option(config.getboolean,
					self.connection, 'skip_auth')
			else:
				self.skip_auth = False

		if getattr(self, 'encoding', None) is not None:
			log_info('The encoding option is deprecated.')

		self.bz = xmlrpc.client.ServerProxy(self.base)
		self.connections = config.sections()

		parse_result = urllib.parse.urlparse(self.base)
		new_netloc = parse_result.netloc.split('@')[-1]
		self.safe_base = parse_result._replace(netloc=new_netloc).geturl()
		self.tokens = Tokens()
		self.bz_token = None

		old_token_file = os.path.join(os.environ['HOME'], '.bugz_token')
		try:
			old_token = open(old_token_file).read().strip()
			self.save_token(old_token)
			os.remove(old_token_file)
			print('Your ~/.bugz_token file was moved to ~/.bugz_tokens')
			print('The token was assigned to the {0} connection'
					.format(self.connection))
			print('If this is not correct, please edit ~/.bugz_tokens')
			print('and adjust the name of the connection.')
			print('This is the name enclosed in square brackets.')
			print('The connections command lists known connections.')
		except (IOError, OSError):
			pass

		log_info("Using [{0}] ({1})".format(self.connection, self.safe_base))

		log_debug('Command line debug dump:', 3)
		for key in vars(args):
			log_debug('{0}, {1}'.format(key, getattr(args, key)), 3)

		log_debug('Connection debug dump:', 3)
		for key in vars(self):
			log_debug('{0}, {1}'.format(key, getattr(self, key)), 3)
コード例 #3
0
ファイル: connection.py プロジェクト: dastergon/pybugz
	def __init__(self, args, config):
		for attr, value in args.__dict__.items():
			sv = getattr(self, attr, None)
			if sv != value:
				setattr(self, attr, value)

		if not hasattr(self, 'connection'):
			if config.has_option('default', 'connection'):
				self.connection = get_config_option(config.get,
					'default', 'connection')
			else:
				log_error('No default connection specified')
				sys.exit(1)

		self.token_file = os.path.join(os.environ['HOME'], DEFAULT_TOKEN_FILE)
		self.bz_token = None

		if self.connection not in config.sections():
			log_error('connection "{0}" not found'.format(self.connection))
			sys.exit(1)

		if not hasattr(self, 'base'):
			if config.has_option(self.connection, 'base'):
				self.base = get_config_option(config.get,
					self.connection, 'base')
			else:
				log_error('No base URL specified')
				sys.exit(1)

		self.bz = BugzillaProxy(self.base)

		if not hasattr(self, 'user'):
			if config.has_option(self.connection, 'user'):
				self.user = get_config_option(config.get,
					self.connection, 'user')

		if not hasattr(self, 'password'):
			if config.has_option(self.connection, 'password'):
				self.password = get_config_option(config.get,
					self.connection, 'password')

		if not hasattr(self, 'passwordcmd'):
			if config.has_option(self.connection, 'passwordcmd'):
				self.passwordcmd = get_config_option(config.get,
					self.connection, 'passwordcmd')

		if not hasattr(self, 'columns'):
			if config.has_option(self.connection, 'columns'):
				self.columns = get_config_option(config.getint,
					self.connection, 'columns')
			else:
				self.columns = terminal_width()

		if not hasattr(self, 'debug'):
			if config.has_option(self.connection, 'debug'):
				self.debug = get_config_option(config.getint,
					self.connection, 'debug')
			else:
				self.debug = 0

		if not hasattr(self, 'quiet'):
			if config.has_option(self.connection, 'quiet'):
				self.quiet = get_config_option(config.getboolean,
					self.connection, 'quiet')
			else:
				self.quiet = False

		if not hasattr(self, 'skip_auth'):
			if config.has_option(self.connection, 'skip_auth'):
				self.skip_auth = get_config_option(config.getboolean,
					self.connection, 'skip_auth')
			else:
				self.skip_auth = False

		if getattr(self, 'encoding', None) is not None:
			log_info('The encoding option is deprecated.')

		log_setDebugLevel(self.debug)
		log_setQuiet(self.quiet)

		log_debug('Connection debug dump:', 3)
		for attr, value in self.__dict__.items():
			log_debug('{0}, {1}'.format(attr, getattr(self, attr)), 3)

		log_info("Using [{0}] ({1})".format(self.connection, self.base))
コード例 #4
0
ファイル: connection.py プロジェクト: dastergon/pybugz
	def load_token(self):
		try:
			self.bz_token = open(self.token_file).read().strip()
			log_debug('successfully loaded token', 3)
		except IOError:
			pass
コード例 #5
0
ファイル: settings.py プロジェクト: vieri1983/pybugz
    def __init__(self, args, config):
        for key in vars(args):
            setattr(self, key, getattr(args, key))

        if not hasattr(self, 'connection'):
            if config.has_option('default', 'connection'):
                self.connection = get_config_option(config.get,
                                                    'default', 'connection')
            else:
                log_error('No default connection specified')
                sys.exit(1)

        if self.connection not in config.sections():
            log_error('connection "{0}" not found'.format(self.connection))
            sys.exit(1)

        if not hasattr(self, 'base'):
            if config.has_option(self.connection, 'base'):
                self.base = get_config_option(config.get,
                                              self.connection, 'base')
            else:
                log_error('No base URL specified')
                sys.exit(1)

        if not hasattr(self, 'component'):
            if config.has_option(self.connection, 'component'):
                self.component = get_config_option(config.get,
                                                   self.connection,
                                                   'component')

        if not hasattr(self, 'user'):
            if config.has_option(self.connection, 'user'):
                self.user = get_config_option(config.get,
                                              self.connection, 'user')

        if not hasattr(self, 'password'):
            if config.has_option(self.connection, 'password'):
                self.password = get_config_option(config.get,
                                                  self.connection, 'password')

        if not hasattr(self, 'passwordcmd'):
            if config.has_option(self.connection, 'passwordcmd'):
                self.passwordcmd = get_config_option(config.get,
                                                     self.connection,
                                                     'passwordcmd')

        if not hasattr(self, 'key'):
            if config.has_option(self.connection, 'key'):
                self.key = get_config_option(config.get,
                                             self.connection,
                                             'key')

        if not hasattr(self, 'product'):
            if config.has_option(self.connection, 'product'):
                self.product = get_config_option(config.get,
                                                 self.connection, 'product')

        if not hasattr(self, 'columns'):
            if config.has_option(self.connection, 'columns'):
                self.columns = get_config_option(config.getint,
                                                 self.connection, 'columns')
            else:
                self.columns = terminal_width()

        if not hasattr(self, 'debug'):
            if config.has_option(self.connection, 'debug'):
                self.debug = get_config_option(config.getint,
                                               self.connection, 'debug')
            else:
                self.debug = 0
        log_setDebugLevel(self.debug)

        if not hasattr(self, 'quiet'):
            if config.has_option(self.connection, 'quiet'):
                self.quiet = get_config_option(config.getboolean,
                                               self.connection, 'quiet')
            else:
                self.quiet = False
        log_setQuiet(self.quiet)

        if not hasattr(self, 'search_statuses'):
            if config.has_option(self.connection, 'search_statuses'):
                s = get_config_option(config.get, self.connection,
                        'search_statuses')
                self.search_statuses = [x.strip() for x in s.split(',')]

        if not hasattr(self, 'skip_auth'):
            if config.has_option(self.connection, 'skip_auth'):
                self.skip_auth = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'skip_auth')
            else:
                self.skip_auth = False

        if not hasattr(self, 'interactive'):
            if config.has_option(self.connection, 'interactive'):
                self.interactive = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'interactive')
            else:
                self.interactive = False

        if not hasattr(self, 'insecure'):
            if config.has_option(self.connection, 'insecure'):
                self.insecure = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'insecure')
            else:
                self.insecure = False

        if getattr(self, 'encoding', None) is not None:
            log_info('The encoding option is deprecated.')

        if self.insecure:
            context=ssl._create_unverified_context()
        else:
            context = None

        self.bz = xmlrpc.client.ServerProxy(self.base, context=context)
        self.connections = config.sections()

        parse_result = urllib.parse.urlparse(self.base)
        new_netloc = parse_result.netloc.split('@')[-1]
        self.safe_base = parse_result._replace(netloc=new_netloc).geturl()
        log_info("Using [{0}] ({1})".format(self.connection, self.safe_base))

        log_debug('Command line debug dump:', 3)
        for key in vars(args):
            log_debug('{0}, {1}'.format(key, getattr(args, key)), 3)

        log_debug('Settings debug dump:', 3)
        for key in vars(self):
            log_debug('{0}, {1}'.format(key, getattr(self, key)), 3)
コード例 #6
0
ファイル: connection.py プロジェクト: CMB/pybugz
    def __init__(self, args, config):
        for attr, value in args.__dict__.items():
            sv = getattr(self, attr, None)
            if sv != value:
                setattr(self, attr, value)

        if not hasattr(self, "connection"):
            if config.has_option("default", "connection"):
                self.connection = get_config_option(config.get, "default", "connection")
            else:
                log_error("No default connection specified")
                sys.exit(1)

        if not self.connection in config.sections():
            log_error('connection "{0}" not found'.format(self.connection))
            sys.exit(1)

        if not hasattr(self, "base"):
            if config.has_option(self.connection, "base"):
                self.base = get_config_option(config.get, self.connection, "base")
            else:
                log_error("No base URL specified")
                sys.exit(1)

        if not hasattr(self, "user"):
            if config.has_option(self.connection, "user"):
                self.user = get_config_option(config.get, self.connection, "user")

        if not hasattr(self, "password"):
            if config.has_option(self.connection, "password"):
                self.password = get_config_option(config.get, self.connection, "password")

        if not hasattr(self, "passwordcmd"):
            if config.has_option(self.connection, "passwordcmd"):
                self.passwordcmd = get_config_option(config.get, self.connection, "passwordcmd")

        if not hasattr(self, "columns"):
            if config.has_option(self.connection, "columns"):
                self.columns = get_config_option(config.getint, self.connection, "columns")
            else:
                self.columns = terminal_width()

        if not hasattr(self, "debug"):
            if config.has_option(self.connection, "debug"):
                self.debug = get_config_option(config.getint, self.connection, "debug")
            else:
                self.debug = 0

        if not hasattr(self, "quiet"):
            if config.has_option(self.connection, "quiet"):
                self.quiet = get_config_option(config.getboolean, self.connection, "quiet")
            else:
                self.quiet = False

        if not hasattr(self, "skip_auth"):
            if config.has_option(self.connection, "skip_auth"):
                self.skip_auth = get_config_option(config.getboolean, self.connection, "skip_auth")
            else:
                self.skip_auth = False

        if getattr(self, "encoding", None) is not None:
            log_info("The encoding option is deprecated.")

        log_setDebugLevel(self.debug)
        log_setQuiet(self.quiet)

        log_debug("Connection debug dump:", 3)
        for attr, value in self.__dict__.items():
            log_debug("{0}, {1}".format(attr, getattr(self, attr)), 3)

        log_info("Using [{0}] ({1})".format(self.connection, self.base))
コード例 #7
0
ファイル: connection.py プロジェクト: pombredanne/pybugz
    def __init__(self, args, config):
        for key in vars(args):
            setattr(self, key, getattr(args, key))

        if not hasattr(self, 'connection'):
            if config.has_option('default', 'connection'):
                self.connection = get_config_option(config.get, 'default',
                                                    'connection')
            else:
                log_error('No default connection specified')
                sys.exit(1)

        if self.connection not in config.sections():
            log_error('connection "{0}" not found'.format(self.connection))
            sys.exit(1)

        if not hasattr(self, 'base'):
            if config.has_option(self.connection, 'base'):
                self.base = get_config_option(config.get, self.connection,
                                              'base')
            else:
                log_error('No base URL specified')
                sys.exit(1)

        if not hasattr(self, 'component'):
            if config.has_option(self.connection, 'component'):
                self.component = get_config_option(config.get, self.connection,
                                                   'component')

        if not hasattr(self, 'user'):
            if config.has_option(self.connection, 'user'):
                self.user = get_config_option(config.get, self.connection,
                                              'user')

        if not hasattr(self, 'password'):
            if config.has_option(self.connection, 'password'):
                self.password = get_config_option(config.get, self.connection,
                                                  'password')

        if not hasattr(self, 'passwordcmd'):
            if config.has_option(self.connection, 'passwordcmd'):
                self.passwordcmd = get_config_option(config.get,
                                                     self.connection,
                                                     'passwordcmd')

        if not hasattr(self, 'product'):
            if config.has_option(self.connection, 'product'):
                self.product = get_config_option(config.get, self.connection,
                                                 'product')

        if not hasattr(self, 'columns'):
            if config.has_option(self.connection, 'columns'):
                self.columns = get_config_option(config.getint,
                                                 self.connection, 'columns')
            else:
                self.columns = terminal_width()

        if not hasattr(self, 'debug'):
            if config.has_option(self.connection, 'debug'):
                self.debug = get_config_option(config.getint, self.connection,
                                               'debug')
            else:
                self.debug = 0
        log_setDebugLevel(self.debug)

        if not hasattr(self, 'quiet'):
            if config.has_option(self.connection, 'quiet'):
                self.quiet = get_config_option(config.getboolean,
                                               self.connection, 'quiet')
            else:
                self.quiet = False
        log_setQuiet(self.quiet)

        if config.has_option(self.connection, 'search_statuses'):
            self.search_statuses = get_config_option(
                config.get, self.connection, 'search_statuses').split()

        if not hasattr(self, 'skip_auth'):
            if config.has_option(self.connection, 'skip_auth'):
                self.skip_auth = get_config_option(config.getboolean,
                                                   self.connection,
                                                   'skip_auth')
            else:
                self.skip_auth = False

        if getattr(self, 'encoding', None) is not None:
            log_info('The encoding option is deprecated.')

        self.bz = xmlrpc.client.ServerProxy(self.base)
        self.connections = config.sections()

        parse_result = urllib.parse.urlparse(self.base)
        new_netloc = parse_result.netloc.split('@')[-1]
        self.safe_base = parse_result._replace(netloc=new_netloc).geturl()
        self.tokens = Tokens()
        self.bz_token = None

        old_token_file = os.path.join(os.environ['HOME'], '.bugz_token')
        try:
            old_token = open(old_token_file).read().strip()
            self.save_token(old_token)
            os.remove(old_token_file)
            print('Your ~/.bugz_token file was moved to ~/.bugz_tokens')
            print('The token was assigned to the {0} connection'.format(
                self.connection))
            print('If this is not correct, please edit ~/.bugz_tokens')
            print('and adjust the name of the connection.')
            print('This is the name enclosed in square brackets.')
            print('The connections command lists known connections.')
        except (IOError, OSError):
            pass

        log_info("Using [{0}] ({1})".format(self.connection, self.safe_base))

        log_debug('Command line debug dump:', 3)
        for key in vars(args):
            log_debug('{0}, {1}'.format(key, getattr(args, key)), 3)

        log_debug('Connection debug dump:', 3)
        for key in vars(self):
            log_debug('{0}, {1}'.format(key, getattr(self, key)), 3)