-
Notifications
You must be signed in to change notification settings - Fork 3
Add machine-readable output option #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
eepp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too bad, but since the two functions (human and machine) do almost the same thing, some sort of template method with callbacks would be interesting.
| True: colored('yes', 'green', attrs=['bold']), | ||
| False: colored('no', 'red', attrs=['bold']), | ||
| }[v] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two newlines here.
| True: 1, | ||
| False: 0, | ||
| }[v] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two newlines here.
eboxbw/cli.py
Outdated
| print_table_border() | ||
|
|
||
| def _print_machine(usage_info, conv_func, punit, details): | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
| for du in cur_month_usage.days_usage: | ||
| print_row(du.date, du.dl_usage, du.ul_usage, du.combined_usage, | ||
| lambda d: d.strftime('%Y-%m-%d')) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two newlines here.
eboxbw/cli.py
Outdated
| date_txt = date_cb(date) | ||
| fmt_row1 = '{}::{}::{}::{}' | ||
|
|
||
| print(fmt_row1.format(date_txt, dl.real_gb, ul.real_gb, cb.real_gb)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use conv_func here to print either GiBs or MiBs.
| print(fmt_row1.format(date_txt, dl.real_gb, ul.real_gb, cb.real_gb)) | ||
|
|
||
| if dl.effective_gb is not None: | ||
| dl_txt = dl.effective_gb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use conv_func.
eboxbw/cli.py
Outdated
| dl_txt = dl.effective_gb | ||
| ul_txt = ul.effective_gb | ||
| cb_txt = cb.effective_gb | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
eboxbw/cli.py
Outdated
| print('{}::{}'.format('capacity', | ||
| usage_info.plan_cap.real_gb)) | ||
| print('{}::{}'.format('available_usage', | ||
| usage_info.available_usage.real_gb)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all the print() above:
- Use CSV format.
- Use hyphens instead of underscores, e.g.
super-off-peak. - Follow PEP 8 to align parameters.
- Use
conv_func.
| return { | ||
| True: 1, | ||
| False: 0, | ||
| }[v] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer non-colored yes and no.
| cur_month_usage = usage_info.cur_month_usage | ||
| date = cur_month_usage.date | ||
|
|
||
| if date is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate code: create a function for this warning.
Makes it easier to use the output of this script in other places (eg. cron).