The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
The great Etc debate

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
The great Etc debate Posted: Feb 7, 2005 3:04 AM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
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. :)

Read: The great Etc debate

Topic: A Coupon Previous Topic   Next Topic Topic: On Learning Japanese...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use