ocf / ocflib

Python libraries for account and server management
https://pypi.python.org/pypi/ocflib
Other
15 stars 32 forks source link

Add last used function #159

Closed TonyLianLong closed 5 years ago

TonyLianLong commented 5 years ago

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.

dkess commented 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.

abizer commented 5 years ago

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.

TonyLianLong commented 5 years ago

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

dkess commented 5 years ago

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.

TonyLianLong commented 5 years ago

Now I put those functions into stats.py with some slight modifications.

dkess commented 5 years ago

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.

abizer commented 5 years ago

There are still issues with this PR that ought to be fixed.