Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,2 @@
|
|||
/bistu_wifi.egg-info
|
||||
/**/__pycache__
|
||||
/build
|
||||
|
|
|
@ -16,7 +16,7 @@ else:
|
|||
XDG_CONFIG_HOME = os.path.join(os.environ['HOME'], '.config')
|
||||
|
||||
DEFAULT_HOST = '10.1.206.13'
|
||||
DEFAULT_CONFIG_LOCATION = [ os.path.join(XDG_CONFIG_HOME, 'bistu-wifi/auth.ini'), '/etc/bistu-wifi/auth.ini' ]
|
||||
DEFAULT_CONFIG_LOCATION = os.path.join(XDG_CONFIG_HOME, 'bistu-wifi/auth.ini')
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -39,19 +39,17 @@ def main():
|
|||
type=str, help='host to send login/logout request to, default use 10.1.206.13')
|
||||
parser.add_argument('-o', '--logout', action='store_true',
|
||||
help='logout bistu wifi. try to login if not privided')
|
||||
parser.add_argument('-c', '--config', nargs='?', default=None,
|
||||
type=str, help=f'load info(username, password, host) from config file.'
|
||||
parser.add_argument('-c', '--config', nargs='?', default=DEFAULT_CONFIG_LOCATION,
|
||||
type=str, help='load info(username, password, host) from config file. '
|
||||
f'Will try {DEFAULT_CONFIG_LOCATION} if not provided.')
|
||||
parser.add_argument('--no-config', action='store_true',
|
||||
help='don\'t use any config file')
|
||||
parser.add_argument('--no-time', action='store_true',
|
||||
parser.add_argument('--notime', action='store_true',
|
||||
help='don\'t output time field in log')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
log_level = logging.DEBUG if 'BISTU_WIFI_DEBUG' in os.environ else logging.INFO
|
||||
log_fmt = '%(levelname)s : %(funcName)s : %(message)s'
|
||||
if not args.no_time:
|
||||
if not args.notime:
|
||||
log_fmt = '%(asctime)s : ' + log_fmt
|
||||
|
||||
logging.basicConfig(level=log_level, format=log_fmt)
|
||||
|
@ -61,31 +59,11 @@ def main():
|
|||
host = DEFAULT_HOST
|
||||
is_logout = False
|
||||
|
||||
# Load config from file
|
||||
# Try files [ global_default, user_default ] if args.config not provided,
|
||||
# Try file specified by user if args.config provided
|
||||
#
|
||||
# After these judgements, the config file must exist or is None
|
||||
config_file = None
|
||||
if args.config is not None:
|
||||
config_file = args.config
|
||||
logger.info('loading info from config file %s ...', args.config)
|
||||
|
||||
if not os.path.exists(config_file):
|
||||
logger.error('config file not exists: %s', config_file)
|
||||
else:
|
||||
for f in DEFAULT_CONFIG_LOCATION:
|
||||
if os.path.exists(f):
|
||||
config_file = f
|
||||
break
|
||||
|
||||
if args.no_config:
|
||||
config_file = None
|
||||
|
||||
# the config_file must exists now
|
||||
if config_file is not None:
|
||||
logger.info('loading info from config file %s ...', config_file)
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_file)
|
||||
config.read(args.config)
|
||||
|
||||
d_section = config['DEFAULT']
|
||||
|
||||
|
@ -93,7 +71,6 @@ def main():
|
|||
password = str(d_section['password']) if 'password' in d_section else password
|
||||
host = str(d_section['host']) if 'host' in d_section else host
|
||||
|
||||
# override with command paramter
|
||||
username = args.username if args.username is not None else username
|
||||
password = args.password if args.password is not None else password
|
||||
host = args.host if args.host is not None else host
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "bistu_wifi"
|
||||
version = "0.0.3"
|
||||
version = "0.0.1"
|
||||
dependencies = []
|
||||
[project.scripts]
|
||||
bistu-wifi = "bistu_wifi.__main__:main"
|
||||
|
|
Loading…
Reference in a new issue