[DRE-commits] [librarian-puppet] 98/153: Remove monkey patched Parser and just extend the class
Stig Sandbeck Mathisen
ssm at debian.org
Wed Jun 1 20:30:50 UTC 2016
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository librarian-puppet.
commit cb433ad456eddcc3d613461f355f1dfcc626cf42
Author: Carlos Sanchez <carlos at apache.org>
Date: Fri Feb 27 17:40:17 2015 +0100
Remove monkey patched Parser and just extend the class
---
lib/librarian/puppet/environment.rb | 10 +++++-
lib/librarian/puppet/lockfile.rb | 39 +++++++++++++++++++++++
lib/librarian/puppet/lockfile/parser.rb | 55 ---------------------------------
3 files changed, 48 insertions(+), 56 deletions(-)
diff --git a/lib/librarian/puppet/environment.rb b/lib/librarian/puppet/environment.rb
index 4b4edff..d502415 100644
--- a/lib/librarian/puppet/environment.rb
+++ b/lib/librarian/puppet/environment.rb
@@ -1,7 +1,7 @@
require "librarian/environment"
require "librarian/puppet/dsl"
require "librarian/puppet/source"
-require "librarian/puppet/lockfile/parser"
+require "librarian/puppet/lockfile"
module Librarian
module Puppet
@@ -11,6 +11,14 @@ module Librarian
"puppet"
end
+ def lockfile
+ Lockfile.new(self, lockfile_path)
+ end
+
+ def ephemeral_lockfile
+ Lockfile.new(self, nil)
+ end
+
def tmp_path
part = config_db["tmp"] || ".tmp"
project_path.join(part)
diff --git a/lib/librarian/puppet/lockfile.rb b/lib/librarian/puppet/lockfile.rb
new file mode 100644
index 0000000..f2053eb
--- /dev/null
+++ b/lib/librarian/puppet/lockfile.rb
@@ -0,0 +1,39 @@
+# Extend Lockfile to normalize module names from acme/mod to acme-mod
+module Librarian
+ module Puppet
+ class Lockfile < Librarian::Lockfile
+
+ # Extend the parser to normalize module names in old .lock files, converting / to -
+ class Parser < Librarian::Lockfile::Parser
+
+ include Librarian::Puppet::Util
+
+ def extract_and_parse_sources(lines)
+ sources = super
+ sources.each do |source|
+ source[:manifests] = Hash[source[:manifests].map do |name,manifest|
+ [normalize_name(name), manifest]
+ end]
+ end
+ sources
+ end
+
+ def extract_and_parse_dependencies(lines, manifests_index)
+ # when looking up in manifests_index normalize the name beforehand
+ class << manifests_index
+ include Librarian::Puppet::Util
+ alias_method :old_lookup, :[]
+ define_method(:[]) { |k| self.old_lookup(normalize_name(k)) }
+ end
+ super(lines, manifests_index)
+ end
+
+ end
+
+ def load(string)
+ Parser.new(environment).parse(string)
+ end
+
+ end
+ end
+end
diff --git a/lib/librarian/puppet/lockfile/parser.rb b/lib/librarian/puppet/lockfile/parser.rb
deleted file mode 100644
index 22caa4f..0000000
--- a/lib/librarian/puppet/lockfile/parser.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-require 'librarian/manifest'
-require 'librarian/puppet/dependency'
-require 'librarian/manifest_set'
-
-module Librarian
- class Lockfile
- class Parser
- include Librarian::Puppet::Util
-
- def parse(string)
- string = string.dup
- source_type_names_map = Hash[dsl_class.source_types.map{|t| [t[1].lock_name, t[1]]}]
- source_type_names = dsl_class.source_types.map{|t| t[1].lock_name}
- lines = string.split(/(\r|\n|\r\n)+/).select{|l| l =~ /\S/}
- sources = []
- while source_type_names.include?(lines.first)
- source = {}
- source_type_name = lines.shift
- source[:type] = source_type_names_map[source_type_name]
- options = {}
- while lines.first =~ /^ {2}([\w\-\/]+):\s+(.+)$/
- lines.shift
- options[$1.to_sym] = $2
- end
- source[:options] = options
- lines.shift # specs
- manifests = {}
- while lines.first =~ /^ {4}([\w\-\/]+) \((.*)\)$/ # This change allows forward slash
- lines.shift
- name, version = normalize_name($1), $2
- manifests[name] = {:version => version, :dependencies => {}}
- while lines.first =~ /^ {6}([\w\-\/]+) \((.*)\)$/
- lines.shift
- manifests[name][:dependencies][$1] = $2.split(/,\s*/)
- end
- end
- source[:manifests] = manifests
- sources << source
- end
- manifests = compile(sources)
- manifests_index = Hash[manifests.map{|m| [m.name, m]}]
- raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
- dependencies = []
- while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/ # This change allows forward slash
- lines.shift
- name, requirement = normalize_name($1), $2.split(/,\s*/)
- dependencies << Librarian::Puppet::Dependency.new(name, requirement, manifests_index[name].source)
- end
-
- Resolution.new(dependencies, manifests)
- end
-
- end
- end
-end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git
More information about the Pkg-ruby-extras-commits
mailing list