dtk-common 0.5.15 → 0.5.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2I5MWQxMzAwMWI0MjdjNTEwNjc3NjhkYjU5OTliMTFiMjYxMjk2NQ==
4
+ ZmIxNGJmODM0YmY0NTRiMmFmZGQwM2I4OTg1Zjc0NTVjZTI2ZjI0ZA==
5
5
  data.tar.gz: !binary |-
6
- M2ZhODkzZjNhOTI3ODk4MGE5M2FiMzJjMGYwMDIwYThlYTRlYmFiMg==
6
+ ZGM5OGZlMTNmNDU4MjQwOWZiYmFkMDc2ZDZkNWFhZDQ5ZTAxN2U3Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDk3ZjRlMGExNTE2MWEyYTg5NDkzOGE3MzI5OTY3NDFlYjM3MDU2OTUxYmM2
10
- ZmQ3OWZmZGEwMjFkOWY3Nzg3YzhlZDVmMzdhMDI4NWIwOWUzOGRhMjQ0NDYx
11
- YzgyNmU2ZTJiZTY4ZDk5NGY0Y2YxYmQ0NmQxMTBkNTUxMDE1NDg=
9
+ YTZkNGUzNjk4NzBiMDg1YzVkYTMwMjE5MDAzMWUwMGRiNzQxMDg4MWUzYThj
10
+ ODAzZTM0OWJlYTQwZmQyMzVlMjEwNThhNzIzZWQxY2FmZmE1NGNmYmFiN2Mw
11
+ YWJkMWRjNjZlNTU2ZGJjY2U4YjYwMWQ2NDc3OTgwMTMwZmQ2NGE=
12
12
  data.tar.gz: !binary |-
13
- MmJhZmE0YTk0M2JhOGE3OThmODI3NWUwNDA0Y2M2NGQ4MmUyMzg1OThjNDJm
14
- MTlmNGY5ZWNlMzlmYTE4MTNmNzcwNDI5OGVjMzFlMjJhMmU5Yjk1YWZkZmU5
15
- NmJhZTRhOWVlMzc5NDQxZGY5YjJjODY3NzhiZWU4ZmFiMTVhMWU=
13
+ OWZjZmQwMWVmZDZjZjU2MjA3NzBiM2Y0M2ZjZWJjODFhYjUxNzEyOGQyZjY2
14
+ N2Y5MzA2OTk1ZWQ3ZjBhM2IxYzJjZjA3OGY5ZDljYzg1M2M3ZjdlNGMxNTYy
15
+ ODk4NGJiMGM0MTFlY2Y5OWM2MjIyMjBjYWNjMjQ5M2UxNTkwMTc=
@@ -23,7 +23,7 @@ module DtkCommon
23
23
  #if file_type is given returns DtkCommon::DSL::FileParser::OutputArray
24
24
  #otherwise returns hash at top level taht is indexed by file types found
25
25
  def parse_directory(file_type=nil,opts={})
26
- pruned_file_info =
26
+ pruned_file_info =
27
27
  if file_type
28
28
  matches = @file_info.select{|r|r[:file_type] == file_type}
29
29
  if matches.empty?
@@ -45,10 +45,28 @@ module DtkCommon
45
45
  file_type.nil? ? ret : ret[file_type]
46
46
  end
47
47
 
48
+ def self.default_rel_path?(directory_type,file_type)
49
+ if match = file_info_single_match?(directory_type,file_type)
50
+ match[:default_rel_path]
51
+ end
52
+ end
48
53
  private
49
- def file_info(directory_type)
54
+ def self.file_info_single_match?(directory_type,file_type)
55
+ matches = file_info(directory_type).select{|r|r[:file_type] == file_type}
56
+ if matches.empty? then nil
57
+ elsif matches.size == 1 then matches.first
58
+ else
59
+ raise Error.new("Unexpected to get multiple matches")
60
+ end
61
+ end
62
+ def self.file_info(directory_type)
50
63
  DirectoryTypeFiles[directory_type]
51
64
  end
65
+
66
+ def file_info(directory_type)
67
+ self.class.file_info(directory_type)
68
+ end
69
+
52
70
  def instantiate_rel_path_patterns(rel_file_info)
53
71
  ret = Array.new
54
72
  all_files_from_root = nil
@@ -56,24 +74,44 @@ module DtkCommon
56
74
  if rel_path = r[:rel_path]
57
75
  ret << r
58
76
  else
59
- rel_path_pattern = r[:rel_path_pattern]
60
-
61
- (all_files_from_root ||= all_files_from_root()).each do |f|
62
- if f =~ rel_path_pattern
63
- file_key = $1
64
- ret << {:rel_path => f, :file_type => r[:file_type], :key => file_key}
65
- end
77
+ all_files_from_root ||= all_files_from_root()
78
+ ret += find_rel_path_matches(r,all_files_from_root)
79
+ end
80
+ end
81
+ ret
82
+ end
83
+
84
+ def find_rel_path_matches(r,all_files_from_root)
85
+ ret = Array.new
86
+ unless r[:rel_path_pattern]
87
+ return ret
88
+ end
89
+
90
+ rel_path_pattern = r[:rel_path_pattern]
91
+ rel_path_patterns = (rel_path_pattern.kind_of?(Array) ? rel_path_pattern : [rel_path_pattern])
92
+ rel_path_patterns.each do |pat|
93
+ all_files_from_root.each do |f|
94
+ if f =~ pat
95
+ file_key = $1
96
+ ret << {:rel_path => f, :file_type => r[:file_type], :key => file_key}
66
97
  end
67
98
  end
99
+ return ret unless ret.empty?
68
100
  end
69
101
  ret
70
102
  end
71
- #TODO: may put version info here too
72
103
  DirectoryTypeFiles = {
73
- :service_module =>
104
+ :service_module =>
74
105
  [
75
- {:rel_path => "global_module_refs.json", :file_type => :component_module_refs},
76
- {:rel_path_pattern => /^assemblies\/([^\/]+)\/assembly\.yaml$/, :file_type => :assembly}
106
+ {
107
+ :file_type => :component_module_refs,
108
+ :rel_path_pattern => [/(^module_refs.yaml$)/,/(^global_module_refs.json$)/],
109
+ :default_rel_path => 'module_refs.yaml',
110
+ },
111
+ {
112
+ :file_type => :assembly,
113
+ :rel_path_pattern => /^assemblies\/([^\/]+)\/assembly\.yaml$/
114
+ }
77
115
  ]
78
116
  }
79
117
  end
@@ -13,7 +13,13 @@ module DtkCommon; module DSL; class FileParser
13
13
  parse_error = true
14
14
  if v.kind_of?(InputHash) and v.only_has_keys?(:version,:remote_namespace,:namespace) and not v.empty?()
15
15
  parse_error = false
16
- new_el.merge_non_empty!(:version_info => v[:version], :remote_namespace => v[:remote_namespace]||v[:namespace])
16
+ # v[index] if index not found returns empty InputHash, not nil
17
+ new_el.merge_non_empty!(:version_info => v[:version])
18
+ namespace = v[:namespace]
19
+ namespace = v[:remote_namespace] if namespace.empty? # TODO: for legacy
20
+ # TODO: change this to new_el.merge_non_empty!(:namespace => namespace) while coordinating with users
21
+ # of api
22
+ new_el.merge_non_empty!(:remote_namespace => namespace)
17
23
  elsif v.kind_of?(String)
18
24
  parse_error = false
19
25
  new_el.merge_non_empty!(:version_info => v)
@@ -1,3 +1,3 @@
1
1
  module DtkCommon
2
- VERSION = "0.5.15"
2
+ VERSION = "0.5.16"
3
3
  end
@@ -0,0 +1,130 @@
1
+ require 'yaml'
2
+
3
+ module DTK
4
+ module Common
5
+
6
+ class ModuleParser
7
+
8
+ MODULE_REFS_FILE = 'module_refs.yaml'
9
+
10
+ def initialize(module_name, module_namespace, repos_path, module_type=:service_module, is_server=false, dtk_username=nil)
11
+ @module_name = module_name
12
+ @module_namespace = module_namespace
13
+ @module_type = module_type
14
+ @repos_path = repos_path
15
+ @is_server = is_server
16
+ @dtk_username = dtk_username
17
+ @dependency_map = nil
18
+ @errors = []
19
+ end
20
+
21
+ def calculate!()
22
+ @dependency_map = recursive_calculation(@module_name, @module_namespace, @module_type)
23
+ @dependency_map
24
+ end
25
+
26
+ #
27
+ # Errors will return latest calculated changes
28
+ #
29
+ def errors()
30
+ @dependency_map ||= recursive_calculation(@module_name, @module_namespace, @module_type)
31
+ @errors
32
+ end
33
+
34
+ private
35
+
36
+ def recursive_calculation(cm_name, cm_namespace, cm_type, chain_link = [])
37
+ # if namespace not found user parent namespace (service namespace)
38
+ cm_namespace = @module_namespace
39
+
40
+ chain_identifier = "#{cm_namespace}::#{cm_name}(#{ModuleParser.resolve_module_type(cm_type)})"
41
+
42
+ # !CHECK ERROR DETECTED CIRCUALAR DEPENDENCY
43
+ if chain_link.include?(chain_identifier)
44
+ return element(cm_name, cm_namespace, cm_type, chain_link, "Circular dependency detected for '#{chain_identifier}'!")
45
+ end
46
+
47
+ # STARTING PROCESSING (ID ADDED)
48
+ chain_link << chain_identifier
49
+
50
+ # READ COMPONENT MODULE FILE
51
+ repo_path = ModuleParser.resolve_module_path(cm_type, cm_name, cm_namespace, @repos_path, @is_server, @dtk_username)
52
+
53
+ begin
54
+ module_refs = Gitolite::Git::FileAccess.new(repo_path).file_content(MODULE_REFS_FILE)
55
+ rescue Exception => e
56
+ return element(cm_name, cm_namespace, cm_type, chain_link, "Repo module '#{chain_identifier}' cannot be found")
57
+ end
58
+
59
+ # !CHECK ERROR MODEL DESCRIPTION IS MISSING
60
+ unless module_refs
61
+ return element(cm_name, cm_namespace, cm_type)
62
+ end
63
+
64
+ module_refs = YAML.load(module_refs)
65
+
66
+ module_refs_cm = module_refs['component_modules']||[]
67
+ module_refs_tm = module_refs['test_modules']||[]
68
+
69
+ cm_results = []
70
+ tm_results = []
71
+
72
+ module_refs_cm.each do |cm_name, cm_values|
73
+ cm_results << recursive_calculation(cm_name, cm_values['namespace'], :component_module, chain_link.dup)
74
+ end
75
+
76
+ module_refs_tm.each do |cm_name, cm_values|
77
+ tm_results << recursive_calculation(cm_name, cm_values['namespace'], :test_module, chain_link.dup)
78
+ end
79
+
80
+ element = element(cm_name, cm_namespace, cm_type)
81
+ element[:component_modules] = cm_results
82
+ element[:test_modules] = tm_results
83
+
84
+ element
85
+ end
86
+
87
+ def element(module_name, module_namespace, module_type, chain_info = [], error = nil)
88
+ if error
89
+ error_string = error
90
+ error_string += ", dependency location #{chain_info.join(' >> ')}" unless chain_info.empty?
91
+ @errors << error_string
92
+ end
93
+
94
+ {
95
+ :module_name => module_name,
96
+ :module_namespace => module_namespace,
97
+ :module_type => module_type,
98
+ :location => chain_info.empty? ? nil : chain_info.join(' >> '),
99
+ :error => error
100
+ }
101
+ end
102
+
103
+ def self.resolve_module_path(module_type, module_name, module_namespace, repos_path, is_server=false, dtk_username=nil)
104
+ if is_server
105
+ repo_name = "#{dtk_username}-#{module_namespace}-#{module_name}.git"
106
+ repo_name = "#{resolve_module_type(module_type)}-#{repo_name}" unless module_type == :component_module
107
+ else
108
+ repo_name = "#{module_namespace}--#{resolve_module_type(module_type)}--#{module_name}.git"
109
+ end
110
+
111
+ File.join(repos_path, repo_name)
112
+ end
113
+
114
+ def self.resolve_module_type(module_type)
115
+ case module_type
116
+ when :service_module
117
+ 'sm'
118
+ when :component_module
119
+ 'cm'
120
+ when :test_module
121
+ 'tm'
122
+ else
123
+ raise "Not supported module type when resolving dependnecies #{module_type}"
124
+ end
125
+ end
126
+
127
+
128
+ end
129
+ end
130
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.15
4
+ version: 0.5.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich PELAVIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -97,6 +97,7 @@ files:
97
97
  - lib/grit_adapter/file_access/diff.rb
98
98
  - lib/grit_adapter/file_access/status.rb
99
99
  - lib/grit_adapter/object_access.rb
100
+ - lib/module_parser/module_parser.rb
100
101
  - lib/module_version.rb
101
102
  - lib/require_first.rb
102
103
  - rich_tests/README.md
@@ -177,7 +178,6 @@ files:
177
178
  - rich_tests/fixtures/rugged_test1/repo1.git/refs/heads/branch1
178
179
  - rich_tests/fixtures/rugged_test1/repo1.git/refs/heads/master
179
180
  - rich_tests/rugged_test1.rb
180
- - test.rb
181
181
  homepage: https://github.com/rich-reactor8/dtk-common
182
182
  licenses:
183
183
  - GPL-3.0
data/test.rb DELETED
@@ -1,13 +0,0 @@
1
- require File.expand_path('lib/gitolite/init.rb', File.dirname(__FILE__))
2
-
3
-
4
- manager = Gitolite::Manager.new('/home/git/gitolite-admin')
5
-
6
- # DEBUG SNIPPET >>>> REMOVE <<<<
7
- require 'pp'
8
- pp "Start >>>"
9
-
10
- pp manager.open_repo('r8--cm--bootstrap')
11
-
12
-
13
- pp "DOne!"