commit 6012d3472ddc37bfd6d7350a3e3f44fa7a5553b8
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Mon Mar 7 04:09:49 2011 +0100

    [evol] Clerk work §1

diff --git a/bin/clerk b/bin/clerk
new file mode 100755
index 0000000..0224a18
--- /dev/null
+++ b/bin/clerk
@@ -0,0 +1,67 @@
+#!/usr/bin/ruby -Ku
+
+#--
+# CyborgHood, a distributed system management software.
+# Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#++
+
+# to allow in-place run for test
+$: << File.join(File.dirname(__FILE__), "..", "lib")
+
+require 'cyborghood/cyborg'
+
+
+module CyborgHood
+  module ClerkLand
+    include I18nTranslation
+    bindtextdomain("cyborghood_clerk", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
+
+    class Clerk < Cyborg
+      # load config before modules are included
+      Config.load(self.human_name)
+
+      include BotNet
+
+      def setup
+        super
+
+        define_interface "0.1~"
+      end
+    end
+  end # ClerkLand
+end
+
+
+reg = Needle::Registry.new
+reg.define do |b|
+  b.require 'cyborghood', CyborgHood
+  b.require 'cyborghood-clerk/land', CyborgHood::ClerkLand
+
+  b.bot { CyborgHood::ClerkLand::Clerk.new(b.clerk_land) }
+end
+
+
+bot = reg.bot
+
+
+trap('INT') do
+  bot.stop(:quickly)
+end
+trap('TERM') do
+  bot.stop(:quickly)
+end
+
+bot.run
diff --git a/data/cyborghood/default_config/clerk.yaml b/data/cyborghood/default_config/clerk.yaml
new file mode 100644
index 0000000..ed97d53
--- /dev/null
+++ b/data/cyborghood/default_config/clerk.yaml
@@ -0,0 +1 @@
+---
diff --git a/data/cyborghood/schema/clerk.yaml b/data/cyborghood/schema/clerk.yaml
new file mode 100644
index 0000000..9b0561c
--- /dev/null
+++ b/data/cyborghood/schema/clerk.yaml
@@ -0,0 +1,4 @@
+---
+type: map
+mapping:
+  "schemacannotbeempty": {type: str}
\ No newline at end of file
diff --git a/lib/cyborghood-clerk/interface/0_base.rb b/lib/cyborghood-clerk/interface/0_base.rb
new file mode 100644
index 0000000..f49f5df
--- /dev/null
+++ b/lib/cyborghood-clerk/interface/0_base.rb
@@ -0,0 +1,5 @@
+node 'Commands', :dir => '_commands'
+
+node 'Batch' do
+  # TODO
+end
diff --git a/lib/cyborghood-clerk/interface/_commands/0_base.rb b/lib/cyborghood-clerk/interface/_commands/0_base.rb
new file mode 100644
index 0000000..618302d
--- /dev/null
+++ b/lib/cyborghood-clerk/interface/_commands/0_base.rb
@@ -0,0 +1 @@
+node 'DNS', :dir => '_dns'
diff --git a/lib/cyborghood-clerk/interface/_commands/_dns/get_set.rb b/lib/cyborghood-clerk/interface/_commands/_dns/get_set.rb
new file mode 100644
index 0000000..03b5ae3
--- /dev/null
+++ b/lib/cyborghood-clerk/interface/_commands/_dns/get_set.rb
@@ -0,0 +1,12 @@
+node ['GET', 'SET'], :case_insensitive => true do
+  action = node_name
+
+  node nil do
+    zone_name = node_name
+
+#    on_request do |request|
+#      task 'dns_manage_zone' do
+#      end
+#    end
+  end
+end
diff --git a/lib/cyborghood-clerk/interface/_commands/_dns/info.rb b/lib/cyborghood-clerk/interface/_commands/_dns/info.rb
new file mode 100644
index 0000000..2cb5470
--- /dev/null
+++ b/lib/cyborghood-clerk/interface/_commands/_dns/info.rb
@@ -0,0 +1,43 @@
+node 'INFO', :case_insensitive => true do
+
+  on_request do |request|
+    task 'dns_list_managed_zones' do
+      logger.warn "User: #{request.env.user}"
+
+      # do later requests using provided token
+      set_user request.env.user
+
+      # cannot search directly 'person/<user>' until LdapShadows is used,
+      # then searching the user DN first
+      ask "Librarian", :user_info, Proc.new{ "/Records/Persons/#{user}" }
+
+      on_error do
+        logger.warn "FUCK"
+        request.reply.errors << "Internal error"
+        request.send_reply
+      end
+
+      on_success do
+        unless results[:user_info]
+          logger.warn "User not found!"
+        else
+          ask "Librarian", :managed_zones, "/Records/DnsDomains/?", :manager => "#{results[:user_info][:dn]}"
+
+          on_success do
+            logger.info "COIN"
+            # request.reply.results[<key>] fail with: wrong number of arguments (2 for 1)
+            msg = results[:managed_zones].empty? ?
+            _("You do not manage any zone.") :
+              _("You are manager of the following zones: %{zone_list}.",
+              :zone_list => results[:managed_zones].keys.join(', '))
+            request.reply.results = msg.translate(request.env.preferred_locales)
+            logger.info "COIN END"
+            request.send_reply
+          end
+        end
+      end
+
+    end # task dns_list_managed_zones
+  end
+
+end
diff --git a/lib/cyborghood-clerk/land.rb b/lib/cyborghood-clerk/land.rb
new file mode 100644
index 0000000..1d08be5
--- /dev/null
+++ b/lib/cyborghood-clerk/land.rb
@@ -0,0 +1,33 @@
+#--
+# CyborgHood, a distributed system management software.
+# Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#++
+
+
+module CyborgHood
+  module ClerkLand
+    def register_services(container)
+      container.namespace_define(:clerk_land) do |b|
+        b.records do
+          require 'cyborghood-clerk/records'
+          Records.new
+        end
+      end
+    end
+
+    module_function :register_services
+  end # ClerkLand
+end
diff --git a/po/cyborghood_clerk.pot b/po/cyborghood_clerk.pot
new file mode 100644
index 0000000..e4ef03c
--- /dev/null
+++ b/po/cyborghood_clerk.pot
@@ -0,0 +1,26 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: CyborgHood 0.4.0\n"
+"POT-Creation-Date: 2011-03-07 02:42+0100\n"
+"PO-Revision-Date: 2011-03-07 02:39+0100\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
+
+#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:30
+msgid "You do not manage any zone."
+msgstr ""
+
+#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:31
+msgid "You are manager of the following zones: %{zone_list}."
+msgstr ""
diff --git a/po/fr/cyborghood_clerk.po b/po/fr/cyborghood_clerk.po
new file mode 100644
index 0000000..64e4515
--- /dev/null
+++ b/po/fr/cyborghood_clerk.po
@@ -0,0 +1,24 @@
+# CyborgHood
+# Copyright (C) 2009-2011 DuckCorp
+# This file is distributed under the same license as the CyborgHood package.
+# Marc Dequènes (Duck) <Duck@DuckCorp.org>, 2009-2010.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: CyborgHood 0.4.0\n"
+"POT-Creation-Date: 2011-03-07 02:42+0100\n"
+"PO-Revision-Date: 2011-03-07 02:39+0100\n"
+"Last-Translator: Marc Dequènes (Duck) <Duck@DuckCorp.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:30
+msgid "You do not manage any zone."
+msgstr "iVous ne gérez aucune zone."
+
+#: lib/cyborghood-clerk/interface/_commands/_dns/info.rb:31
+msgid "You are manager of the following zones: %{zone_list}."
+msgstr "Vous êtes administrateur des zones suivantes : %{zone_list}."
