add default config, fix flash issue

This commit is contained in:
mingyang 2021-07-16 22:31:12 +08:00
parent 64cc2c57cf
commit 714b9e9e4d
2 changed files with 11 additions and 4 deletions

View File

@ -6,7 +6,7 @@ A naive tool for observing gpu status and auto set visible gpu in python code.
1. install the package.
```shell
pip install https://git.zmy.pub/zmyme/gpuutil/archive/v0.0.4.tar.gz
pip install https://git.zmy.pub/zmyme/gpuutil/archive/v0.0.5.tar.gz
```
2. for observing gpu status, just input

View File

@ -59,7 +59,7 @@ if __name__ == '__main__':
recommended_cols = ['ID', 'Fan', 'Temp', 'Pwr', 'Freq', 'Util', 'Vmem']
parser = argparse.ArgumentParser()
parser.add_argument('--profile', '-p', default=None, type=str, help='profile keyword, corresponding configuration are saved in ~/.gpuutil.conf')
parser.add_argument('--profile', '-p', default='default', type=str, help='profile keyword, corresponding configuration are saved in ~/.gpuutil.conf')
parser.add_argument('--cols', '-c', type=csv2list, help='colums to show.(Availabel cols: {0}'.format(avaliable_cols))
parser.add_argument('--style', '-sty', type=str, default=None, help='column style, format: |c|l:15|r|c:14rl:13|, c,l,r are align methods, | is line and :(int) are width limit.')
parser.add_argument('--show-process', '-sp', default=True, type=str2bool, help='whether show process or not')
@ -92,6 +92,14 @@ if __name__ == '__main__':
save_config(config)
elif args.profile is not None:
config = load_config()
if 'default' not in config:
config['default'] = {
"cols": cols,
"style": style,
"limit": limit,
"show-process": show_process,
"vertical": vertical
}
if args.profile in config:
params = config[args.profile]
cols = params["cols"]
@ -105,7 +113,6 @@ if __name__ == '__main__':
limit = params["limit"]
if "vertical" in params:
vertical = params["vertical"]
else:
raise ValueError('Profile do not exist.\nAvaliable Profiles:{0}'.format(','.join(list(config.keys()))))
info = stat.show(enabled_cols = cols, colsty=style, colsz=limit, vertical=vertical, show_command=show_process, tostdout=False)
@ -126,7 +133,7 @@ if __name__ == '__main__':
break
curses.flushinp()
hint = "Interval: {0} S | CurrentTime: {1}".format(args.watch, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
stdscr.clear()
stdscr.erase()
stdscr.addstr(0, 0, hint + '\n' + info)
stdscr.refresh()
passed_time = time.time() - lasttime