ref: refs/heads/master
commit 8f99449192bd9e5e549da4a2a9d07a2713ce59df
Author: Ladislav Slezak
Date: Fri Aug 14 15:11:31 2009 +0200
added system client
initial commit
---
plugins/system/.gitignore | 2 +
plugins/system/README | 7 ++
plugins/system/Rakefile | 10 +++
.../system/app/controllers/system_controller.rb | 47 ++++++++++++
plugins/system/app/models/system.rb | 19 +++++
plugins/system/config/rails_parent.rb | 15 ++++
plugins/system/config/routes.rb | 4 +
plugins/system/doc/README_FOR_APP | 7 ++
plugins/system/init.rb | 15 ++++
plugins/system/install.rb | 1 +
plugins/system/package/yast2-webclient-system.spec | 79 ++++++++++++++++++++
plugins/system/po/de/yast_webclient_systemtime.po | 49 ++++++++++++
plugins/system/po/en/yast_webclient_systemtime.po | 49 ++++++++++++
plugins/system/tasks/systemtime_tasks.rake | 6 ++
.../test/functional/system_controller_test.rb | 10 +++
plugins/system/test/test_helper.rb | 56 ++++++++++++++
plugins/system/uninstall.rb | 1 +
17 files changed, 377 insertions(+), 0 deletions(-)
diff --git a/plugins/system/.gitignore b/plugins/system/.gitignore
new file mode 100644
index 0000000..09a651e
--- /dev/null
+++ b/plugins/system/.gitignore
@@ -0,0 +1,2 @@
+package/www
+package/www.tar.bz2
diff --git a/plugins/system/README b/plugins/system/README
new file mode 100644
index 0000000..46164a2
--- /dev/null
+++ b/plugins/system/README
@@ -0,0 +1,7 @@
+Systemtime
+==========
+
+Plugin for accessing basic system functionlity like reboot and shutdown.
+
+
+Copyright (c) 2009 Novell, released under the GPL2 license
diff --git a/plugins/system/Rakefile b/plugins/system/Rakefile
new file mode 100644
index 0000000..ca63e76
--- /dev/null
+++ b/plugins/system/Rakefile
@@ -0,0 +1,10 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require File.join(File.dirname(__FILE__), 'config', 'rails_parent')
+require File.join(RailsParent.parent, 'config', 'boot')
+require 'tasks/rails'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
diff --git a/plugins/system/app/controllers/system_controller.rb b/plugins/system/app/controllers/system_controller.rb
new file mode 100644
index 0000000..2bd2aa7
--- /dev/null
+++ b/plugins/system/app/controllers/system_controller.rb
@@ -0,0 +1,47 @@
+
+class SystemController < ApplicationController
+ before_filter :login_required
+
+ def initialize
+ @sys = System.new rescue nil
+ @host = Host.find(session[:host]) rescue 'computer'
+ end
+
+ def reboot
+ if request.put?
+ begin
+ if !@sys.nil? and @sys.reboot
+ flash[:message] = "Rebooting #{@host}..."
+ else
+ flash[:error] = "Cannot reboot #{@host}!"
+ end
+ rescue Exception => e
+ flash[:error] = "Cannot reboot #{@host}!"
+ end
+ else
+ flash[:error] = 'Reboot request is accepted only via PUT method!'
+ end
+
+ redirect_to :controller => :controlpanel, :action => :index
+ end
+
+ def shutdown
+ if request.put?
+ begin
+ if !@sys.nil? and @sys.shutdown
+ flash[:message] = "Shuting down #{@host}..."
+ else
+ flash[:error] = "Cannot shutdown #{@host}!"
+ end
+ rescue Exception => e
+ flash[:error] = "Cannot shutdown #{@host}!"
+ end
+ else
+ flash[:error] = 'Shutdown request is accepted only via PUT method!'
+ end
+
+ redirect_to :controller => :controlpanel, :action => :index
+ end
+end
+
+# vim: ft=ruby
diff --git a/plugins/system/app/models/system.rb b/plugins/system/app/models/system.rb
new file mode 100644
index 0000000..47196ed
--- /dev/null
+++ b/plugins/system/app/models/system.rb
@@ -0,0 +1,19 @@
+
+class System
+
+ def initialize
+ @client = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.system')
+ @sys = @client.find
+ end
+
+ def reboot
+ @sys.reboot.active = true
+ @sys.save
+ end
+
+ def shutdown
+ @sys.shutdown.active = true
+ @sys.save
+ end
+
+end
diff --git a/plugins/system/config/rails_parent.rb b/plugins/system/config/rails_parent.rb
new file mode 100644
index 0000000..c7bd94f
--- /dev/null
+++ b/plugins/system/config/rails_parent.rb
@@ -0,0 +1,15 @@
+class RailsParent
+
+ def RailsParent.parent
+ parent = ENV["RAILS_PARENT"]
+ unless parent
+ parent = File.expand_path(File.join('..','..','..', 'webclient'), File.dirname(__FILE__))
+ unless File.directory?( parent || "" )
+ $stderr.puts "Nope: #{parent}\nPlease set RAILS_PARENT environment"
+ exit 1
+ end
+ end
+ parent
+ end
+
+end
diff --git a/plugins/system/config/routes.rb b/plugins/system/config/routes.rb
new file mode 100644
index 0000000..63da86a
--- /dev/null
+++ b/plugins/system/config/routes.rb
@@ -0,0 +1,4 @@
+ActionController::Routing::Routes.draw do |map|
+ map.connect "/system", :controller => 'system', :action => 'index'
+end
+
diff --git a/plugins/system/doc/README_FOR_APP b/plugins/system/doc/README_FOR_APP
new file mode 100644
index 0000000..a991b9c
--- /dev/null
+++ b/plugins/system/doc/README_FOR_APP
@@ -0,0 +1,7 @@
+Language
+=========
+
+Plugin for setting time and timezones.
+
+
+Copyright (c) 2009 Novell, released under the GPL2 license
diff --git a/plugins/system/init.rb b/plugins/system/init.rb
new file mode 100644
index 0000000..59b5313
--- /dev/null
+++ b/plugins/system/init.rb
@@ -0,0 +1,15 @@
+# Include hook code here
+
+# always reload all files in development mode
+if ENV['RAILS_ENV'] == 'development'
+ # get all subdirectories in app/
+ dirs = Dir[File.join(directory, 'app', '*')].reject{|x| not File.directory?(x)}
+
+ dirs.each do |dir|
+ $LOAD_PATH << dir
+ ActiveSupport::Dependencies.load_paths << dir
+ ActiveSupport::Dependencies.load_once_paths.delete(dir)
+ end
+end
+
+# vim: ft=ruby
diff --git a/plugins/system/install.rb b/plugins/system/install.rb
new file mode 100644
index 0000000..f7732d3
--- /dev/null
+++ b/plugins/system/install.rb
@@ -0,0 +1 @@
+# Install hook code here
diff --git a/plugins/system/package/yast2-webclient-system.changes b/plugins/system/package/yast2-webclient-system.changes
new file mode 100644
index 0000000..e69de29
diff --git a/plugins/system/package/yast2-webclient-system.spec b/plugins/system/package/yast2-webclient-system.spec
new file mode 100644
index 0000000..15603c2
--- /dev/null
+++ b/plugins/system/package/yast2-webclient-system.spec
@@ -0,0 +1,79 @@
+#
+# spec file for package yast2-webclient-system
+#
+# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# This file and all modifications and additions to the pristine
+# package are under the same license as the package itself.
+#
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+
+
+Name: yast2-webclient-system
+PreReq: yast2-webclient >= 0.0.2
+License: GPL
+Group: Productivity/Networking/Web/Utilities
+Autoreqprov: on
+Version: 0.0.1
+Release: 0
+Summary: YaST2 - Webclient - System
+Source: www.tar.bz2
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+BuildArch: noarch
+BuildRequires: ruby
+BuildRequires: yast2-webclient
+
+#
+%define pkg_user yast
+%define plugin_name system
+#
+
+
+%description
+YaST2 - Webclient - UI for YaST-webservice for rebooting/shuting down the system.
+Authors:
+--------
+ Ladislav Slezak
+%prep
+%setup -q -n www
+
+%build
+export RAILS_PARENT=/srv/www/yast
+rake makemo
+
+%install
+
+#
+# Install all web and frontend parts.
+#
+mkdir -p $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+cp -a * $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+%dir /srv/www/%{pkg_user}
+%dir /srv/www/%{pkg_user}/vendor
+%dir /srv/www/%{pkg_user}/vendor/plugins
+%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/README
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/Rakefile
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/init.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/install.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/uninstall.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/lib
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/tasks
+#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/test
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/locale
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/po
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/shortcuts.yml
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config/routes.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config/rails_parent.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/doc/README_FOR_APP
+
+%changelog
diff --git a/plugins/system/po/de/yast_webclient_systemtime.po b/plugins/system/po/de/yast_webclient_systemtime.po
new file mode 100644
index 0000000..b10e0c4
--- /dev/null
+++ b/plugins/system/po/de/yast_webclient_systemtime.po
@@ -0,0 +1,49 @@
+# 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 , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: yast_webclient systemtime 1.0.0\n"
+"POT-Creation-Date: 2009-05-04 13:02+0200\n"
+"PO-Revision-Date: 2009-05-04 13:02+0200\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: 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"
+
+#: app/controllers/system_time_controller.rb:39
+msgid "Settings have been written."
+msgstr "Einstellungen wurden gespeichert."
+
+#: app/views/system_time/index.rhtml:2
+msgid "Configure time"
+msgstr "Zeiteinstellungen"
+
+#: app/views/system_time/index.rhtml:14
+msgid "Timezone:"
+msgstr "Zeitzone:"
+
+#: app/views/system_time/index.rhtml:20
+msgid "UTC (Universal Time Coordinated)"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:24
+msgid "Date"
+msgstr "Datum"
+
+#: app/views/system_time/index.rhtml:30
+msgid "Time"
+msgstr "Zeit"
+
+#: app/views/system_time/index.rhtml:36
+msgid "Save"
+msgstr "Speichern"
+
+#: app/views/system_time/index.rhtml:37
+msgid "Back"
+msgstr "Zurück"
diff --git a/plugins/system/po/en/yast_webclient_systemtime.po b/plugins/system/po/en/yast_webclient_systemtime.po
new file mode 100644
index 0000000..1bdcc7e
--- /dev/null
+++ b/plugins/system/po/en/yast_webclient_systemtime.po
@@ -0,0 +1,49 @@
+# 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 , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: yast_webclient systemtime 1.0.0\n"
+"POT-Creation-Date: 2009-05-04 13:02+0200\n"
+"PO-Revision-Date: 2009-05-04 13:02+0200\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: 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"
+
+#: app/controllers/system_time_controller.rb:39
+msgid "Settings have been written."
+msgstr ""
+
+#: app/views/system_time/index.rhtml:2
+msgid "Configure time"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:14
+msgid "Timezone:"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:20
+msgid "UTC (Universal Time Coordinated)"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:24
+msgid "Date"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:30
+msgid "Time"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:36
+msgid "Save"
+msgstr ""
+
+#: app/views/system_time/index.rhtml:37
+msgid "Back"
+msgstr ""
diff --git a/plugins/system/tasks/systemtime_tasks.rake b/plugins/system/tasks/systemtime_tasks.rake
new file mode 100644
index 0000000..1568c54
--- /dev/null
+++ b/plugins/system/tasks/systemtime_tasks.rake
@@ -0,0 +1,6 @@
+begin
+ require 'tasks/webservice'
+rescue LoadError => e
+ $stderr.puts "Install rubygem-yast2-webservice-tasks.rpm"
+end
+
diff --git a/plugins/system/test/functional/system_controller_test.rb b/plugins/system/test/functional/system_controller_test.rb
new file mode 100644
index 0000000..3c7843f
--- /dev/null
+++ b/plugins/system/test/functional/system_controller_test.rb
@@ -0,0 +1,10 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require 'test/unit'
+require File.expand_path( File.join("test","validation_assert"), RailsParent.parent )
+require 'rubygems'
+
+class SystemControllerTest < ActionController::TestCase
+
+ # TODO FIXME: write the tests
+
+end
diff --git a/plugins/system/test/test_helper.rb b/plugins/system/test/test_helper.rb
new file mode 100644
index 0000000..ca844a2
--- /dev/null
+++ b/plugins/system/test/test_helper.rb
@@ -0,0 +1,56 @@
+# find the rails parent
+require File.join(File.dirname(__FILE__), '..', 'config', 'rails_parent')
+# first config rails
+require File.expand_path( File.join("config","environment"), RailsParent.parent )
+# then enable testing, this will get the routing right
+ENV["RAILS_ENV"] = "test"
+require 'test_help'
+
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
+
+class ActiveSupport::TestCase
+ # Transactional fixtures accelerate your tests by wrapping each test method
+ # in a transaction that's rolled back on completion. This ensures that the
+ # test database remains unchanged so your fixtures don't have to be reloaded
+ # between every test method. Fewer database queries means faster tests.
+ #
+ # Read Mike Clark's excellent walkthrough at
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
+ #
+ # Every Active Record database supports transactions except MyISAM tables
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
+ # is recommended.
+ #
+ # The only drawback to using transactional fixtures is when you actually
+ # need to test transactions. Since your test is bracketed by a transaction,
+ # any transactions started in your code will be automatically rolled back.
+ self.use_transactional_fixtures = true
+
+ # Instantiated fixtures are slow, but give you @david where otherwise you
+ # would need people(:david). If you don't want to migrate your existing
+ # test cases which use the @david style and don't mind the speed hit (each
+ # instantiated fixtures translates to a database query per test method),
+ # then set this back to true.
+ self.use_instantiated_fixtures = false
+
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+
+ # See http://pennysmalls.com/2009/03/04/rails-23-breakage-and-fixage/
+ def clean_backtrace(&block)
+ yield
+ rescue ActiveSupport::TestCase::Assertion => error
+ framework_path = Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
+ error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
+ raise
+ end
+
+end
\ No newline at end of file
diff --git a/plugins/system/uninstall.rb b/plugins/system/uninstall.rb
new file mode 100644
index 0000000..9738333
--- /dev/null
+++ b/plugins/system/uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org