Permalink
Browse files

First import.

Converted only the main Facter class to Perl6.
Just started on Facter::Util:: namespace.
  • Loading branch information...
0 parents commit 0ecf903de4b28ac6a32f991811443a89aeea9d21 @cosimo committed Nov 19, 2010
Showing with 3,300 additions and 0 deletions.
  1. +9 −0 README
  2. +181 −0 lib/Facter.pm
  3. +42 −0 lib/Facter/Cfkey.rb
  4. +135 −0 lib/Facter/Util/Collection.pm
  5. +100 −0 lib/Facter/Util/Loader.pm
  6. +41 −0 lib/Facter/Util/confine.rb
  7. +122 −0 lib/Facter/Util/fact.rb
  8. +171 −0 lib/Facter/Util/ip.rb
  9. +28 −0 lib/Facter/Util/macaddress.rb
  10. +72 −0 lib/Facter/Util/macosx.rb
  11. +63 −0 lib/Facter/Util/manufacturer.rb
  12. +54 −0 lib/Facter/Util/memory.rb
  13. +40 −0 lib/Facter/Util/netmask.rb
  14. +24 −0 lib/Facter/Util/plist.rb
  15. +228 −0 lib/Facter/Util/plist/generator.rb
  16. +226 −0 lib/Facter/Util/plist/parser.rb
  17. +169 −0 lib/Facter/Util/resolution.rb
  18. +54 −0 lib/Facter/Util/uptime.rb
  19. +14 −0 lib/Facter/Util/values.rb
  20. +69 −0 lib/Facter/Util/virtual.rb
  21. +24 −0 lib/Facter/Util/vlans.rb
  22. +10 −0 lib/Facter/Util/xendomains.rb
  23. +121 −0 lib/Facter/application.rb
  24. +33 −0 lib/Facter/architecture.rb
  25. +44 −0 lib/Facter/domain.rb
  26. +35 −0 lib/Facter/ec2.rb
  27. +3 −0 lib/Facter/facterversion.rb
  28. +11 −0 lib/Facter/fqdn.rb
  29. +4 −0 lib/Facter/hardwareisa.rb
  30. +21 −0 lib/Facter/hardwaremodel.rb
  31. +25 −0 lib/Facter/hostname.rb
  32. +15 −0 lib/Facter/id.rb
  33. +32 −0 lib/Facter/interfaces.rb
  34. +167 −0 lib/Facter/ipaddress.rb
  35. +18 −0 lib/Facter/iphostnumber.rb
  36. +11 −0 lib/Facter/kernel.rb
  37. +5 −0 lib/Facter/kernelmajversion.rb
  38. +23 −0 lib/Facter/kernelrelease.rb
  39. +10 −0 lib/Facter/kernelversion.rb
  40. +38 −0 lib/Facter/lsb.rb
  41. +15 −0 lib/Facter/lsbmajdistrelease.rb
  42. +82 −0 lib/Facter/macaddress.rb
  43. +54 −0 lib/Facter/macosx.rb
  44. +30 −0 lib/Facter/manufacturer.rb
  45. +87 −0 lib/Facter/memory.rb
  46. +17 −0 lib/Facter/netmask.rb
  47. +9 −0 lib/Facter/network.rb
  48. +62 −0 lib/Facter/operatingsystem.rb
  49. +76 −0 lib/Facter/operatingsystemrelease.rb
  50. +5 −0 lib/Facter/path.rb
  51. +7 −0 lib/Facter/physicalprocessorcount.rb
  52. +90 −0 lib/Facter/processor.rb
  53. +8 −0 lib/Facter/ps.rb
  54. +10 −0 lib/Facter/puppetversion.rb
  55. +8 −0 lib/Facter/rubysitedir.rb
  56. +3 −0 lib/Facter/rubyversion.rb
  57. +45 −0 lib/Facter/selinux.rb
  58. +33 −0 lib/Facter/ssh.rb
  59. +5 −0 lib/Facter/timezone.rb
  60. +4 −0 lib/Facter/uniqueid.rb
  61. +23 −0 lib/Facter/uptime.rb
  62. +7 −0 lib/Facter/uptime_days.rb
  63. +7 −0 lib/Facter/uptime_hours.rb
  64. +10 −0 lib/Facter/uptime_seconds.rb
  65. +93 −0 lib/Facter/virtual.rb
  66. +8 −0 lib/Facter/vlans.rb
  67. +10 −0 lib/Facter/xendomains.rb
9 README
@@ -0,0 +1,9 @@
+perl6-facter
+============
+
+a Perl6 port of puppetlabs facter!
+
+http://github.com/cosimo/perl6-facter/
+
+Cosimo, 19/11/2010
+
@@ -0,0 +1,181 @@
+#
+# a Perl 6 port of ruby facter
+#
+# http://github.com/puppetlabs/facter/
+#
+
+#--
+# Copyright 2006 Luke Kanies <luke@madstop.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+#--
+
+use v6;
+#use Facter::Util::Fact;
+use Facter::Util::Collection;
+
+class Facter:auth<cosimo>:ver<0.01>;
+
+our $VERSION = '0.01';
+
+# TODO When outputting something
+#$*ENV<LANG> = 'C';
+
+# Private members
+has @!collection is rw;
+has $!debug is rw = 0;
+has $!timing is rw = 0;
+has @!search_path is rw = ();
+
+method collection {
+ unless defined @!collection {
+ @!collection = Facter::Util::Collection.new
+ }
+ return @!collection;
+}
+
+method version () {
+ return $VERSION
+}
+
+multi method debugging () {
+ return $!debug != 0
+}
+
+# Set debugging on or off (1/0)
+multi method debugging($bit) {
+ if $bit {
+ $!debug = 1;
+ }
+ else {
+ $!debug = 0;
+ }
+}
+
+method debug($string) {
+ if ! defined $string {
+ return
+ }
+ if self.debugging() {
+ say $string
+ }
+ return;
+}
+
+method show_time($string) {
+ if $string and self.timing {
+ say $string
+ }
+ return;
+}
+
+multi method timing () {
+ return $!timing != 0;
+}
+
+# Set timing on or off.
+multi method timing($bit) {
+ if $bit {
+ $!timing = 1;
+ } else {
+ $!timing = 0;
+ }
+}
+
+# Return a fact object by name. If you use this, you still have to call
+# 'value' on it to retrieve the actual value.
+method get_fact($name) {
+ self.collection.fact($name);
+}
+
+=begin ruby
+ class << self
+ [:fact, :flush, :list, :value].each do |method|
+ define_method(method) do |*args|
+ collection.send(method, *args)
+ end
+ end
+
+ [:list, :to_hash].each do |method|
+ define_method(method) do |*args|
+ collection.load_all
+ collection.send(method, *args)
+ end
+ end
+ end
+=end ruby
+
+for 'fact', 'flush', 'value' -> $name {
+ Facter.^add_method($name, method (*@args) {
+ self.collection.^can($name).(@args);
+ });
+}
+
+for 'list', 'to_hash' -> $name {
+ Facter.^add_method($name, method (*@args) {
+ self.collection.load_all();
+ self.collection.^can($name, @args);
+ });
+}
+
+# Add a resolution mechanism for a named fact. This does not distinguish
+# between adding a new fact and adding a new way to resolve a fact.
+method add ($name, %options = (), &block) {
+ self.collection.add($name, %options, &block)
+}
+
+method each () {
+ self.collection.load_all();
+ for self.collection.each -> $fact {
+ yield($fact)
+ }
+}
+
+# Clear all facts. Mostly used for testing.
+method clear () {
+ self.flush();
+ self.reset();
+ return;
+}
+
+method warn ($msg) {
+ if self.debugging and $msg and $msg != "" {
+ $msg = [ $msg ] unless $msg.^can('each');
+ for $msg -> $line {
+ warn $line;
+ }
+ }
+}
+
+method reset () {
+ @!collection = ();
+}
+
+# Load all of the default facts, and then everything from disk.
+method loadfacts () {
+ self.collection.load_all();
+}
+
+# Register a directory to search through.
+method search(*@dirs) {
+ @!search_path.push(@dirs);
+}
+
+# Return our registered search directories.
+method search_path () {
+ return @!search_path;
+}
+
@@ -0,0 +1,42 @@
+## Cfkey.rb
+## Facts related to cfengine
+##
+## 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 (version 2 of the License)
+## 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, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
+##
+
+Facter.add(:Cfkey) do
+ setcode do
+ value = nil
+ ["/usr/local/etc/cfkey.pub",
+ "/etc/cfkey.pub",
+ "/var/cfng/keys/localhost.pub",
+ "/var/cfengine/ppkeys/localhost.pub",
+ "/var/lib/cfengine/ppkeys/localhost.pub",
+ "/var/lib/cfengine2/ppkeys/localhost.pub"
+ ].each do |file|
+ if FileTest.file?(file)
+ File.open(file) { |openfile|
+ value = openfile.readlines.reject { |line|
+ line =~ /PUBLIC KEY/
+ }.collect { |line|
+ line.chomp
+ }.join("")
+ }
+ end
+ if value
+ break
+ end
+ end
+
+ value
+ end
+end
@@ -0,0 +1,135 @@
+use Facter;
+use Facter::Util::Fact;
+use Facter::Util::Loader;
+
+# Manage which facts exist and how we access them. Largely just a wrapper
+# around a hash of facts.
+class Facter::Util::Collection;
+
+# Return a fact object by name. If you use this, you still have to call
+# 'value' on it to retrieve the actual value.
+method get($name) {
+ return self.value($name);
+}
+
+=begin ruby
+
+# Add a resolution mechanism for a named fact. This does not distinguish
+# between adding a new fact and adding a new way to resolve a fact.
+def add(name, options = {}, &block)
+ name = canonize(name)
+
+ unless fact = @facts[name]
+ fact = Facter::Util::Fact.new(name)
+
+ @facts[name] = fact
+ end
+
+ # Set any fact-appropriate options.
+ options.each do |opt, value|
+ method = opt.to_s + "="
+ if fact.respond_to?(method)
+ fact.send(method, value)
+ options.delete(opt)
+ end
+ end
+
+ if block
+ resolve = fact.add(&block)
+ # Set any resolve-appropriate options
+ options.each do |opt, value|
+ method = opt.to_s + "="
+ if resolve.respond_to?(method)
+ resolve.send(method, value)
+ options.delete(opt)
+ end
+ end
+ end
+
+ unless options.empty?
+ raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",")
+ end
+
+ return fact
+end
+
+include Enumerable
+
+# Iterate across all of the facts.
+def each
+ @facts.each do |name, fact|
+ value = fact.value
+ unless value.nil?
+ yield name.to_s, value
+ end
+ end
+end
+
+# Return a fact by name.
+def fact(name)
+ name = canonize(name)
+
+ loader.load(name) unless @facts[name]
+
+ return @facts[name]
+end
+
+# Flush all cached values.
+def flush
+ @facts.each { |name, fact| fact.flush }
+end
+
+def initialize
+ @facts = Hash.new
+end
+
+# Return a list of all of the facts.
+def list
+ return @facts.keys
+end
+
+=end ruby
+
+# Load all known facts.
+method load_all () {
+ self.loader.load_all();
+}
+
+# The thing that loads facts if we don't have them.
+method loader () {
+ unless defined $!loader {
+ $!loader = Facter::Util::Loader.new
+ }
+ return $!loader;
+}
+
+=begin ruby
+
+# Return a hash of all of our facts.
+def to_hash
+ @facts.inject({}) do |h, ary|
+ value = ary[1].value
+ if ! value.nil?
+ # For backwards compatibility, convert the fact name to a string.
+ h[ary[0].to_s] = value
+ end
+ h
+ end
+end
+
+def value(name)
+ if fact = fact(name)
+ fact.value
+ end
+end
+
+private
+
+# Provide a consistent means of getting the exact same fact name
+# every time.
+def canonize(name)
+ name.to_s.downcase.to_sym
+end
+
+=end ruby
+
Oops, something went wrong.

0 comments on commit 0ecf903

Please sign in to comment.