Open
Conversation
eepp
requested changes
Sep 30, 2017
Owner
eepp
left a comment
There was a problem hiding this comment.
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.
| @@ -79,6 +81,11 @@ def _yes_no(v): | |||
| False: colored('no', 'red', attrs=['bold']), | |||
| }[v] | |||
|
|
|||
| True: 1, | ||
| False: 0, | ||
| }[v] | ||
|
|
eboxbw/cli.py
Outdated
| print_table_border() | ||
|
|
||
| def _print_machine(usage_info, conv_func, punit, details): | ||
|
|
| 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')) | ||
|
|
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)) |
Owner
There was a problem hiding this comment.
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 |
eboxbw/cli.py
Outdated
| dl_txt = dl.effective_gb | ||
| ul_txt = ul.effective_gb | ||
| cb_txt = cb.effective_gb | ||
|
|
eboxbw/cli.py
Outdated
| print('{}::{}'.format('capacity', | ||
| usage_info.plan_cap.real_gb)) | ||
| print('{}::{}'.format('available_usage', | ||
| usage_info.available_usage.real_gb)) |
Owner
There was a problem hiding this comment.
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] |
Owner
There was a problem hiding this comment.
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: |
Owner
There was a problem hiding this comment.
Duplicate code: create a function for this warning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes it easier to use the output of this script in other places (eg. cron).