|
@@ -0,0 +1,117 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Loader
|
|
|
+
|
|
|
+
|
|
|
+ PATH = 'droits_h.txt'
|
|
|
+
|
|
|
+ attr_accessor :items
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def load_item_data
|
|
|
+ line_types = {
|
|
|
+ 'path' => { 'default' => 'trustee_head'},
|
|
|
+ 'trustee_head' => { 'default' => 'trustee_row'},
|
|
|
+ 'trustee_row' => { 'default' => 'trustee_row', 'head' => 'trustee_head', 'path' => 'path'},
|
|
|
+ 'separator' => { 'default' => 'trustee_head'},
|
|
|
+ 'empty' => { 'default' => 'path'}
|
|
|
+ }
|
|
|
+
|
|
|
+ line_type = 'path'
|
|
|
+ @items = {}
|
|
|
+ path = ''
|
|
|
+ trustee_type = 'invalid'
|
|
|
+ File.open(PATH) do |data_file|
|
|
|
+ data_file.readlines.each do |line|
|
|
|
+ line.chomp!
|
|
|
+
|
|
|
+ new_line_key = 'default'
|
|
|
+ case line_type
|
|
|
+ when 'path' then
|
|
|
+ path = line
|
|
|
+ items[path] = { 'user' => [], 'group' => [], 'other' => []}
|
|
|
+
|
|
|
+ when 'trustee_head'
|
|
|
+
|
|
|
+ case line
|
|
|
+ when /[uU]ser/ then
|
|
|
+ trustee_type = 'user'
|
|
|
+ when /[gG]roup/ then
|
|
|
+ trustee_type = 'group'
|
|
|
+ when /Other/ then
|
|
|
+ trustee_type = 'other'
|
|
|
+ else
|
|
|
+ trustee_type = 'invalid'
|
|
|
+ end
|
|
|
+
|
|
|
+ when 'trustee_row'
|
|
|
+ case line
|
|
|
+ when /----/ then
|
|
|
+ new_line_key = 'head'
|
|
|
+ when '' then
|
|
|
+ new_line_key = 'path'
|
|
|
+ else
|
|
|
+
|
|
|
+ pattern = / *(.*?) *\[(.*)\]/
|
|
|
+ matches = line.match pattern
|
|
|
+
|
|
|
+ @items[path][trustee_type] << [ matches[1], matches[2] ]
|
|
|
+ end
|
|
|
+ when 'separator'
|
|
|
+ trustee_type = 'invalid'
|
|
|
+ when 'empty'
|
|
|
+ trustee_type = 'invalid'
|
|
|
+ path = ''
|
|
|
+ else
|
|
|
+ raise "Invalid line type '#{line}'\n"
|
|
|
+ end
|
|
|
+ line_type = line_types[line_type][new_line_key]
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ def dump
|
|
|
+ @items.keys.sort.each do |path|
|
|
|
+ puts path
|
|
|
+ @items[path].keys.sort.each do |kind|
|
|
|
+ @items[path][kind].sort.each do |assignment|
|
|
|
+ printf(" %-6s|%8s|%s\n", kind, assignment[1], assignment[0])
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ def initialize
|
|
|
+ self.load_item_data
|
|
|
+ end
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+class Main
|
|
|
+
|
|
|
+
|
|
|
+ def initialize
|
|
|
+ loader = Loader.new
|
|
|
+ loader.dump
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+Main.new
|