fig 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changes CHANGED
@@ -1,3 +1,46 @@
1
+ v1.1.0
2
+
3
+ Backwards incompatibilities:
4
+
5
+ - Package names and versions and config names can no longer be "." or "..".
6
+ Attempting to use one of these would produce bad effects before, so this
7
+ should not be a big deal.
8
+
9
+ - The FIG_USERNAME and FIG_PASSWORD environment variables take precedence
10
+ over values in ~/.netrc. This is a better fit with the general *nix idea
11
+ that the command-line should take precedence over the environment which
12
+ should take precedence over dotfiles.
13
+
14
+ - Removed support for SSH. It was never fully functional and depended upon
15
+ fig being installed at the same absolute path on the remote machine as it
16
+ was on the local one. Use SFTP instead.
17
+
18
+ New features:
19
+
20
+ - Graphviz (http://graphviz.org/) output for --list-dependencies and
21
+ --list-variables via --graphviz option. You'll need something that can
22
+ interpret .dot files to use this.
23
+
24
+ fig package/v1.2.3 --list-dependencies --graphviz |
25
+ dot -Tpng -o package-1.2.3.png
26
+
27
+ fig package/v1.2:config --list-variables --list-all-configs --graphviz |
28
+ dot -Tpng -o package-1.2.3.png
29
+
30
+ Since Fig just emits DOT (http://graphviz.org/content/dot-language), Fig
31
+ doesn't have a dependency upon Graphviz libraries, etc.
32
+
33
+ - Support for SFTP. Set FIG_REMOTE_URL to something like
34
+ «sftp://host:port/some/path». Note that this *requires* the use of
35
+ ~/.netrc or FIG_USERNAME/FIG_PASSWORD in order to authenticate; there is no
36
+ anonymous SFTP. Thus, the use of the --login option is superfluous with
37
+ SFTP.
38
+
39
+ v1.0.1.beta.2
40
+ v1.0.1.beta.1
41
+
42
+ - Test releases.
43
+
1
44
  v1.0.0
2
45
 
3
46
  New features:
data/lib/fig.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fig
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/fig/command.rb CHANGED
@@ -167,6 +167,9 @@ class Fig::Command
167
167
 
168
168
  def configure()
169
169
  set_up_update_lock()
170
+
171
+ @operating_system = Fig::OperatingSystem.new(@options.login?)
172
+
170
173
  set_up_application_configuration()
171
174
 
172
175
  Fig::Logging.initialize_post_configuration(
@@ -174,8 +177,6 @@ class Fig::Command
174
177
  @options.log_level()
175
178
  )
176
179
 
177
- @operating_system = Fig::OperatingSystem.new(@options.login?)
178
-
179
180
  prepare_repository()
180
181
  prepare_environment()
181
182
  end
@@ -205,10 +206,10 @@ class Fig::Command
205
206
 
206
207
  def set_up_application_configuration()
207
208
  @application_configuration = Fig::FigRC.find(
208
- @options.figrc(),
209
+ @options.figrc,
209
210
  ENV['FIG_REMOTE_URL'],
210
- @options.login?,
211
- @options.home(),
211
+ @operating_system,
212
+ @options.home,
212
213
  @options.no_figrc?
213
214
  )
214
215
 
@@ -0,0 +1,42 @@
1
+ require 'fig/command/action'
2
+ require 'fig/command/action/role/list_as_graphviz'
3
+ require 'fig/command/action/role/list_base_config'
4
+ require 'fig/command/action/role/list_dependencies_as_graphviz'
5
+ require 'fig/command/action/role/list_walking_dependency_tree'
6
+
7
+ module Fig; end
8
+ class Fig::Command; end
9
+ module Fig::Command::Action; end
10
+ class Fig::Command::Action::ListDependencies; end
11
+
12
+ class Fig::Command::Action::ListDependencies::Graphviz
13
+ include Fig::Command::Action
14
+ include Fig::Command::Action::Role::ListAsGraphviz
15
+ include Fig::Command::Action::Role::ListBaseConfig
16
+ include Fig::Command::Action::Role::ListDependenciesAsGraphviz
17
+ include Fig::Command::Action::Role::ListWalkingDependencyTree
18
+
19
+ def options()
20
+ return %w<--list-dependencies --graphviz>
21
+ end
22
+
23
+ def descriptor_requirement()
24
+ return nil
25
+ end
26
+
27
+ def load_base_package?()
28
+ return true
29
+ end
30
+
31
+ def register_base_package?()
32
+ return nil # don't care
33
+ end
34
+
35
+ def apply_config?()
36
+ return nil # don't care
37
+ end
38
+
39
+ def apply_base_config?()
40
+ return nil # don't care
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ require 'fig/command/action'
2
+ require 'fig/command/action/role/list_all_configs'
3
+ require 'fig/command/action/role/list_as_graphviz'
4
+ require 'fig/command/action/role/list_dependencies_as_graphviz'
5
+ require 'fig/command/action/role/list_walking_dependency_tree'
6
+
7
+ module Fig; end
8
+ class Fig::Command; end
9
+ module Fig::Command::Action; end
10
+ class Fig::Command::Action::ListDependencies; end
11
+
12
+ class Fig::Command::Action::ListDependencies::GraphvizAllConfigs
13
+ include Fig::Command::Action
14
+ include Fig::Command::Action::Role::ListAllConfigs
15
+ include Fig::Command::Action::Role::ListAsGraphviz
16
+ include Fig::Command::Action::Role::ListDependenciesAsGraphviz
17
+ include Fig::Command::Action::Role::ListWalkingDependencyTree
18
+
19
+ def options()
20
+ return %w<--list-dependencies --graphviz --list-all-configs>
21
+ end
22
+
23
+ def descriptor_requirement()
24
+ return nil
25
+ end
26
+
27
+ def load_base_package?()
28
+ return true
29
+ end
30
+
31
+ def register_base_package?()
32
+ return nil # don't care
33
+ end
34
+
35
+ def apply_config?()
36
+ return nil # don't care
37
+ end
38
+
39
+ def apply_base_config?()
40
+ return nil # don't care
41
+ end
42
+ end
@@ -40,7 +40,7 @@ class Fig::Command::Action::ListVariables::AllConfigs
40
40
  variable_names = Set.new()
41
41
 
42
42
  walk_dependency_tree(
43
- @execution_context.base_package, base_display_config_names(), nil, 0
43
+ @execution_context.base_package, base_display_config_names()
44
44
  ) do
45
45
  |package, config_name, depth|
46
46
 
@@ -0,0 +1,22 @@
1
+ require 'fig/command/action'
2
+ require 'fig/command/action/role/list_as_graphviz'
3
+ require 'fig/command/action/role/list_base_config'
4
+ require 'fig/command/action/role/list_variables_as_graphviz'
5
+ require 'fig/command/action/role/list_walking_dependency_tree'
6
+
7
+ module Fig; end
8
+ class Fig::Command; end
9
+ module Fig::Command::Action; end
10
+ class Fig::Command::Action::ListVariables; end
11
+
12
+ class Fig::Command::Action::ListVariables::Graphviz
13
+ include Fig::Command::Action
14
+ include Fig::Command::Action::Role::ListAsGraphviz
15
+ include Fig::Command::Action::Role::ListBaseConfig
16
+ include Fig::Command::Action::Role::ListVariablesAsGraphviz
17
+ include Fig::Command::Action::Role::ListWalkingDependencyTree
18
+
19
+ def options()
20
+ return %w<--list-variables --graphviz>
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'fig/command/action'
2
+ require 'fig/command/action/role/list_all_configs'
3
+ require 'fig/command/action/role/list_as_graphviz'
4
+ require 'fig/command/action/role/list_variables_as_graphviz'
5
+ require 'fig/command/action/role/list_walking_dependency_tree'
6
+
7
+ module Fig; end
8
+ class Fig::Command; end
9
+ module Fig::Command::Action; end
10
+ class Fig::Command::Action::ListVariables; end
11
+
12
+ class Fig::Command::Action::ListVariables::GraphvizAllConfigs
13
+ include Fig::Command::Action
14
+ include Fig::Command::Action::Role::ListAllConfigs
15
+ include Fig::Command::Action::Role::ListAsGraphviz
16
+ include Fig::Command::Action::Role::ListVariablesAsGraphviz
17
+ include Fig::Command::Action::Role::ListWalkingDependencyTree
18
+
19
+ def options()
20
+ return %w<--list-variables --graphviz --list-all-configs>
21
+ end
22
+ end
@@ -0,0 +1,80 @@
1
+ require 'set'
2
+
3
+ module Fig; end
4
+ class Fig::Command; end
5
+ module Fig::Command::Action; end
6
+ module Fig::Command::Action::Role; end
7
+
8
+ # Requires a #node_content(package, config_name) method.
9
+ module Fig::Command::Action::Role::ListAsGraphviz
10
+ def execute()
11
+ @subgraphs = {}
12
+
13
+ puts 'digraph {'
14
+ puts ' node [shape = box];'
15
+ walk_dependency_tree(
16
+ @execution_context.base_package,
17
+ base_display_config_names(),
18
+ include_emit,
19
+ &package_gather
20
+ )
21
+ emit_subgraphs
22
+ puts '}'
23
+
24
+ return Fig::Command::Action::EXIT_SUCCESS
25
+ end
26
+
27
+ private
28
+
29
+ def include_emit
30
+ visited = Set.new
31
+
32
+ return lambda do
33
+ |including_package, including_config, included_package, included_config|
34
+
35
+ including_name = node_name(including_package, including_config)
36
+ included_name = node_name(included_package, included_config)
37
+ edge = %Q/ "#{including_name}" -> "#{included_name}";/
38
+
39
+ if ! visited.include? edge
40
+ visited << edge
41
+ puts edge
42
+ end
43
+ end
44
+ end
45
+
46
+ def package_gather
47
+ visited = Set.new
48
+
49
+ return lambda do
50
+ |package, config_name, depth|
51
+
52
+ name = node_name package, config_name
53
+
54
+ if ! visited.include? name
55
+ visited << name
56
+
57
+ package_name = node_name package, nil
58
+ @subgraphs[package_name] ||= []
59
+ @subgraphs[package_name] << node_content(package, config_name)
60
+ end
61
+ end
62
+ end
63
+
64
+ def emit_subgraphs()
65
+ @subgraphs.each do
66
+ |package_name, nodes|
67
+
68
+ cluster = nodes.size > 1 ? 'cluster ' : ''
69
+ puts %Q< subgraph "#{cluster}#{package_name}" {>
70
+ nodes.each { |node| puts %Q< #{node}> }
71
+ puts %q< }>
72
+ end
73
+
74
+ return
75
+ end
76
+
77
+ def node_name(package, config_name)
78
+ return package.to_s_with_config(config_name)
79
+ end
80
+ end
@@ -0,0 +1,25 @@
1
+ module Fig; end
2
+ class Fig::Command; end
3
+ module Fig::Command::Action; end
4
+ module Fig::Command::Action::Role; end
5
+
6
+ module Fig::Command::Action::Role::ListDependenciesAsGraphviz
7
+ private
8
+
9
+ def node_content(package, config_name)
10
+ name = node_name package, config_name
11
+
12
+ style = ''
13
+ color = ''
14
+ if package == @execution_context.base_package
15
+ if base_display_config_names.include?(config_name)
16
+ style = ' style = "rounded, bold"'
17
+ end
18
+ if config_name == @execution_context.base_config
19
+ color = ' color = blue'
20
+ end
21
+ end
22
+
23
+ return %Q<"#{name}" [label = "#{name}"#{style}#{color}];>
24
+ end
25
+ end
@@ -8,7 +8,7 @@ module Fig::Command::Action::Role; end
8
8
  module Fig::Command::Action::Role::ListDependenciesInATree
9
9
  def execute()
10
10
  walk_dependency_tree(
11
- @execution_context.base_package, base_display_config_names(), nil, 0
11
+ @execution_context.base_package, base_display_config_names()
12
12
  ) do
13
13
  |package, config_name, depth|
14
14
 
@@ -0,0 +1,76 @@
1
+ require 'cgi'
2
+
3
+ module Fig; end
4
+ class Fig::Command; end
5
+ module Fig::Command::Action; end
6
+ module Fig::Command::Action::Role; end
7
+
8
+ module Fig::Command::Action::Role::ListVariablesAsGraphviz
9
+ def descriptor_requirement()
10
+ return nil
11
+ end
12
+
13
+ def load_base_package?()
14
+ return true
15
+ end
16
+
17
+ def register_base_package?()
18
+ return nil # don't care
19
+ end
20
+
21
+ def apply_config?()
22
+ return nil # don't care
23
+ end
24
+
25
+ private
26
+
27
+ def node_content(package, config_name)
28
+ style = ''
29
+ color = ''
30
+ if package == @execution_context.base_package
31
+ if base_display_config_names.include?(config_name)
32
+ style = ' style = "rounded, bold"'
33
+ end
34
+ if config_name == @execution_context.base_config
35
+ color = ' color = blue'
36
+ end
37
+ end
38
+
39
+ name = node_name package, config_name
40
+ rows = variable_statement_rows package, config_name
41
+ label = nil
42
+ if rows.empty?
43
+ label = %Q<"#{name}">
44
+ else
45
+ label = %Q[<<table border="0"><tr><td border="0" colspan="3"><b>#{name}</b></td></tr>#{rows}</table>>]
46
+ end
47
+
48
+ return %Q<"#{name}" [label = #{label}#{style}#{color}];>
49
+ end
50
+
51
+ def variable_statement_rows(package, config_name)
52
+ string = ''
53
+
54
+ package[config_name].walk_statements do
55
+ |statement|
56
+
57
+ if statement.is_environment_variable?
58
+ string << format_variable_statement(statement)
59
+ end
60
+ end
61
+
62
+ return string
63
+ end
64
+
65
+ def format_variable_statement(statement)
66
+ string = '<tr><td align="right">'
67
+ string << statement.statement_type
68
+ string << '</td><td align="left">$'
69
+ string << CGI.escape_html(statement.name)
70
+ string << '</td><td align="left">'
71
+ string << CGI.escape_html(statement.tokenized_value.to_escaped_string)
72
+ string << '</td></tr>'
73
+
74
+ return string
75
+ end
76
+ end
@@ -53,7 +53,7 @@ module Fig::Command::Action::Role::ListVariablesInATree
53
53
  current_parent = tree
54
54
 
55
55
  walk_dependency_tree(
56
- @execution_context.base_package, base_display_config_names(), nil, 0
56
+ @execution_context.base_package, base_display_config_names()
57
57
  ) do
58
58
  |package, config_name, depth|
59
59
 
@@ -13,44 +13,12 @@ module Fig::Command::Action::Role::ListWalkingDependencyTree
13
13
  return false
14
14
  end
15
15
 
16
- def walk_dependency_tree(base_package, config_names, backtrace, depth, &block)
17
- config_names.each do
18
- |config_name|
19
-
20
- if depth < 1
21
- @execution_context.repository.reset_cached_data
22
- end
23
-
24
- yield base_package, config_name, depth
25
-
26
- new_backtrace = Fig::IncludeBacktrace.new(
27
- backtrace,
28
- Fig::PackageDescriptor.new(
29
- base_package.name(),
30
- base_package.version(),
31
- config_name,
32
- :description => base_package.description
33
- )
34
- )
35
-
36
- base_package.package_dependencies(config_name, new_backtrace).each do
37
- |descriptor|
38
-
39
- package = nil
40
- if descriptor.name
41
- package =
42
- @execution_context.repository.get_package(
43
- descriptor, :allow_any_version
44
- )
45
- else
46
- package = base_package
47
- end
48
-
49
- walk_dependency_tree(
50
- package, [descriptor.config], new_backtrace, depth + 1, &block
51
- )
52
- end
53
- end
16
+ def walk_dependency_tree(
17
+ base_package, config_names, include_block = nil, &package_block
18
+ )
19
+ do_walk_dependency_tree(
20
+ base_package, config_names, nil, 0, include_block, &package_block
21
+ )
54
22
 
55
23
  return
56
24
  end
@@ -68,7 +36,7 @@ module Fig::Command::Action::Role::ListWalkingDependencyTree
68
36
  packages[base_package] = starting_config_names.to_set
69
37
  end
70
38
 
71
- walk_dependency_tree(base_package, starting_config_names, nil, 0) do
39
+ do_walk_dependency_tree(base_package, starting_config_names, nil, 0, nil) do
72
40
  |package, config_name, depth|
73
41
 
74
42
  if (
@@ -92,4 +60,67 @@ module Fig::Command::Action::Role::ListWalkingDependencyTree
92
60
 
93
61
  return packages
94
62
  end
63
+
64
+ private
65
+
66
+ def do_walk_dependency_tree(
67
+ base_package, config_names, backtrace, depth, include_block, &package_block
68
+ )
69
+ config_names.each do
70
+ |config_name|
71
+
72
+ if depth < 1
73
+ @execution_context.repository.reset_cached_data
74
+ end
75
+
76
+ package_block.call base_package, config_name, depth
77
+
78
+ new_backtrace = new_backtrace(backtrace, base_package, config_name)
79
+
80
+ base_package.package_dependencies(config_name, new_backtrace).each do
81
+ |descriptor|
82
+
83
+ package = package_for_descriptor descriptor, base_package
84
+
85
+ do_walk_dependency_tree(
86
+ package,
87
+ [descriptor.config],
88
+ new_backtrace,
89
+ depth + 1,
90
+ include_block,
91
+ &package_block
92
+ )
93
+
94
+ if include_block
95
+ include_block.call(
96
+ base_package, config_name, package, descriptor.config
97
+ )
98
+ end
99
+ end
100
+ end
101
+
102
+ return
103
+ end
104
+
105
+ def new_backtrace(backtrace, base_package, config_name)
106
+ return Fig::IncludeBacktrace.new(
107
+ backtrace,
108
+ Fig::PackageDescriptor.new(
109
+ base_package.name(),
110
+ base_package.version(),
111
+ config_name,
112
+ :description => base_package.description
113
+ )
114
+ )
115
+ end
116
+
117
+ def package_for_descriptor(descriptor, base_package)
118
+ if descriptor.name
119
+ return @execution_context.repository.get_package(
120
+ descriptor, :allow_any_version
121
+ )
122
+ end
123
+
124
+ return base_package
125
+ end
95
126
  end