#14 More Pythonic Interface
Opened 6 years ago by coderforlife. Modified 3 years ago

It would be great if the Python interface was actually something similar to any of Python module. However, it is great that these features are exposed.

I have created a basic one which is attached. It currently has a few missing features (doesn't do anything with prompts, only allows for the default admin() constructor, and doesn't expose any shadow properties except SHADOWPASSWORD) and is lacking in documentation. Also, edge cases (like a user not having a name) are not taken care of.

Even with these faults, it is still a big step up from your code (unless you need one of those features).

The basic idea is that a user is wrapped in a User class while a group is in a Group object. These fundamentally wrap an Entity but also provide convenient ways to work with them through all the other functions.

user = User('jeff')
print user
<user 500="" jeff="">
print user.primary_group
<group 500="" jeff="">
print user.home
user.home = '/home/jeff-alt' # would move home directory
user.password = '....' # set the use password
del user.password # remove the password
new_user = User.create('new-user')

And plenty more. One problem I have found is that skeleton (for createHome and indirectly addUser) cannot accept None but must be a string. Looking at lu_homedir_populate shows that for default you are supposed to send NULL.

Please tell me what you think.

Thanks for the code. I'll take a more detailed look later; for now just one comment - there is a plan to consolidate on a single primary API for user management, centered around sssd, probably a D-Bus API + a library, with libuser only wrapping the sssd API for compatibility. So addition of features to libuser is slowing down.

At a first look, using {{{del user.homedir}}} to remove a directory structure seems rather unexpected. However I really haven't tried to understand the general design yet, so perhaps it is fitting well.

Thinking about it now, you are right. del should not be used for that - I guess I was just in a do everything with special Python that I can mode! It is definitely a prototype though.

Login to comment on this ticket.