This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: The great Etc debate
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
I was griping the other day about how the File.stat Ruby method doesn't work as well as it could on Win32 because it uses Ruby's 'etc' package internally. For those few who don't know, the 'etc' package is named after the '/etc' directory on Unix systems, and it returns information about users and groups, i.e. /etc/passwd and /etc/groups. Unfortunately, the 'etc' package only works on Unix platforms.
A while back I created the 'win32-etc' package. I managed to keep the API identical to (and actually, slightly more powerful than) the version for Unix. While the name may be inappropriate for Windows, the information it returns is the same. It uses the various Net* functions behind the scenes to get user and group information. I didn't fret about the name, because I was more interested in creating portable code. Plus, I figured the admins who are doing both Unix and Win32 administration would be comfortable with 'etc' and its API.
While talking on IRC, and discussing whether or not win32-etc should be merged into core Ruby, we more or less came to the conclusion that 'etc' is a crappy name, and the API itself is too literal, e.g. Etc.passwd{ |user| ... }. Plus there's no way to *set* user and group information with it (which may be a difficult thing to do in a cross platform way on Unix). What Ruby needs is a "Sys" class of some kind. This would be a more generic API that would serve as a base for all user and group related information. Something that would let you get and set user and group information.
So, our hypothetical, cross-platform API would look something like this:
ua = Sys.users # returns an array of Sys::User objects
ga = Sys.groups # returns an array of Sys::Group objects
Sys::User.add{ |u|
u.name = "Dan"
u.home_dir = "/home/djberge"
# ... and so on
}
Sys::Group.configure{ |g|
g.name = "kvm"
g.gid = 501
}
Sys::User.delete("Dan")
Or something along those lines. This removes the "etc" association, and creates a more flexible and cross platform API to boot.
On a final note, you *can* add, configure and delete users with the win32-etc package. See the Admin module. :)