def resolve_projector(projector):
password = None
# host:port
if projector is not None and ':' in projector:
host, port = projector.rsplit(':', 1)
port = int(port)
# maybe defined in config
else:
appdir = appdirs.user_data_dir('pjlink')
conf_file = path.join(appdir, 'pjlink.conf')
try:
config = ConfigParser({'port': '4352', 'password': ''})
with open(conf_file, 'r') as f:
config.readfp(f)
section = projector
if projector is None:
section = 'default'
host = config.get(section, 'host')
port = config.getint(section, 'port')
password = config.get(section, 'password') or None
except (NoSectionError, IOError):
if projector is None:
raise KeyError('No default projector defined in %s' % conf_file)
# no config file, or no projector defined for this host
# thus, treat the projector as a hostname w/o port
host = projector
port = 4352
return host, port, password
评论列表
文章目录