Closed TonyLianLong closed 5 years ago
ocflib.lab.stats
uses the anonymous MySQL user, whereas this uses credentials, so I think it's OK for this to be in a separate module.
the functions in that module can/should have the ability to take credentials. splitting this functionality out like this without good reason breaks the logical design of ocflib.
the functions in that module can/should have the ability to take credentials. splitting this functionality out like this without good reason breaks the logical design of ocflib.
So probably I can put the code into that module and refractor a little bit so that when specified with some arguments it does not connect with anonymous username? This is not so easy though since in what step should we connect to the database? @abizer
Look at how the other functions call get_connection
. It's actually a partial function, which means you can call get_connection(user='username', password='aaaaa', db='db')
, etc.
Now I put those functions into stats.py with some slight modifications.
This lgtm, to fix the last errors you should make sure to run make install-hooks
on your local environment. Then running git commit
will automatically fix the style errors. You can also run pre-commit
manually to fix the errors.
There are still issues with this PR that ought to be fixed.
I added a last used function since it would be useful if we can figure out who is the last user in cases such as (https://github.com/ocf/utils/issues/96).
We can use
last_used(...)["end"] == None
to determine whether the user is currently using the machine.