Module: Puppet::Util::Portage
Defined Under Namespace
Classes: AtomError
Constant Summary collapse
- CATEGORY_PATTERN =
'[\w+][\w+.-]*'
- NAME_PATTERN =
'[\w+][\w+-]*?'
- PACKAGE_PATTERN =
"(#{CATEGORY_PATTERN}/#{NAME_PATTERN})"
- COMPARE_PATTERN =
'([<>=~]|[<>]=)'
- VERSION_PATTERN =
'((?:cvs\.)?(?:\d+)(?:(?:\.\d+)*)(?:[a-z]?)(?:(?:_(?:pre|p|beta|alpha|rc)\d*)*)(?:-r(?:\d+))?)'
- WILDCARD_PATTERN =
"(#{VERSION_PATTERN}\\*)"
- SLOT_PATTERN =
'([\w+./*=-]+)'
- BASE_ATOM_REGEX =
Regexp.new "^#{PACKAGE_PATTERN}$"
- VERSIONED_ATOM_REGEX =
Regexp.new "^#{COMPARE_PATTERN}#{PACKAGE_PATTERN}-#{VERSION_PATTERN}$"
- SLOTTED_ATOM_REGEX =
Regexp.new "^#{PACKAGE_PATTERN}:#{SLOT_PATTERN}$"
- VERSIONED_SLOTTED_ATOM_REGEX =
Regexp.new "^#{COMPARE_PATTERN}#{PACKAGE_PATTERN}-#{VERSION_PATTERN}:#{SLOT_PATTERN}$"
- WILDCARD_ATOM_REGEX =
Regexp.new "^(=?)#{PACKAGE_PATTERN}-#{WILDCARD_PATTERN}$"
- WILDCARD_SLOTTED_ATOM_REGEX =
Regexp.new "^(=?)#{PACKAGE_PATTERN}-#{WILDCARD_PATTERN}:#{SLOT_PATTERN}$"
- DEPEND_ATOM_REGEX =
Regexp.union BASE_ATOM_REGEX, VERSIONED_ATOM_REGEX, SLOTTED_ATOM_REGEX, VERSIONED_SLOTTED_ATOM_REGEX, WILDCARD_ATOM_REGEX, WILDCARD_SLOTTED_ATOM_REGEX
Instance Method Summary collapse
-
#format_atom(hash) ⇒ String
Convert a hash describing an atom into a string.
-
#parse_atom(atom) ⇒ Hash<Symbol, String>
Parse a string into the different components of a DEPEND atom.
-
#parse_cmpver(cmpver) ⇒ Hash
Parse out a combined compare and version into a hash.
-
#valid_atom?(atom) ⇒ TrueClass, FalseClass
Determine if a string is a valid DEPEND atom.
-
#valid_package?(package_name) ⇒ TrueClass, FalseClass
Determine if a string is a valid package name.
-
#valid_slot?(slot_str) ⇒ TrueClass
Determine if a string is a valid DEPEND atom slot.
-
#valid_version?(version_str) ⇒ TrueClass
Determine if a string is a valid DEPEND atom version.
Instance Method Details
#format_atom(hash) ⇒ String
Convert a hash describing an atom into a string
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppet/util/portage.rb', line 118 def format_atom(hash) str = "" if hash[:version] ver_hash = parse_cmpver(hash[:version]) str << ver_hash[:compare] str << hash[:name] str << '-' str << ver_hash[:version] else str = hash[:name].dup end if hash[:slot] str << ':' str << hash[:slot] end str end |
#parse_atom(atom) ⇒ Hash<Symbol, String>
Parse a string into the different components of a DEPEND atom.
If the atom is versioned, the returned value will contain the keys :package, :compare, and :version. If the atom is unversioned then it will contain the key :package. If the atom is slotted then it will contain the key :slot.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/puppet/util/portage.rb', line 85 def parse_atom(atom) if (match = atom.match(BASE_ATOM_REGEX)) {:package => match[1]} elsif (match = atom.match(VERSIONED_ATOM_REGEX)) {:compare => (match[1] || '='), :package => match[2], :version => match[3]} elsif (match = atom.match(WILDCARD_ATOM_REGEX)) {:compare => match[1], :package => match[2], :version => match[3]} elsif (match = atom.match(SLOTTED_ATOM_REGEX)) {:package => match[1], :slot => match[2]} elsif (match = atom.match(VERSIONED_SLOTTED_ATOM_REGEX)) {:compare => (match[1] || '='), :package => match[2], :version => match[3], :slot => match[4]} elsif (match = atom.match(WILDCARD_SLOTTED_ATOM_REGEX)) {:compare => match[1], :package => match[2], :version => match[3], :slot => match[4]} else raise AtomError, "#{atom} is not a valid atom" end end |
#parse_cmpver(cmpver) ⇒ Hash
Parse out a combined compare and version into a hash
106 107 108 109 110 111 112 113 |
# File 'lib/puppet/util/portage.rb', line 106 def parse_cmpver(cmpver) regex = Regexp.new("^#{COMPARE_PATTERN}?#{VERSION_PATTERN}$") if (match = cmpver.match regex) {:compare => match[1] || '=', :version => match[2]} else raise AtomError, "#{cmpver} is not a valid compare version" end end |
#valid_atom?(atom) ⇒ TrueClass, FalseClass
Determine if a string is a valid DEPEND atom
31 32 33 34 |
# File 'lib/puppet/util/portage.rb', line 31 def valid_atom?(atom) # Normalize the regular expression output to a boolean !!(atom =~ DEPEND_ATOM_REGEX) end |
#valid_package?(package_name) ⇒ TrueClass, FalseClass
Determine if a string is a valid package name
42 43 44 |
# File 'lib/puppet/util/portage.rb', line 42 def valid_package?(package_name) !!(package_name =~ BASE_ATOM_REGEX) end |
#valid_slot?(slot_str) ⇒ TrueClass
Determine if a string is a valid DEPEND atom slot
This validates a standalone slot string.
68 69 70 71 |
# File 'lib/puppet/util/portage.rb', line 68 def valid_slot?(slot_str) regex = Regexp.new "^#{SLOT_PATTERN}$" !!(slot_str =~ regex) end |
#valid_version?(version_str) ⇒ TrueClass
Determine if a string is a valid DEPEND atom version
This validates a standalone version string. The format is an optional comparator and a version string.
55 56 57 58 |
# File 'lib/puppet/util/portage.rb', line 55 def valid_version?(version_str) regex = Regexp.new "^#{COMPARE_PATTERN}?#{VERSION_PATTERN}$|^=?#{WILDCARD_PATTERN}$" !!(version_str =~ regex) end |