Class: Drupid::Platform

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/drupid/platform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#blah, #bzr, #compare_paths, #curl, #cvs, #debug, #dont_debug, #git, #hg, #ignore_interrupts, #interactive_shell, #odie, #ofail, #ohai, #owarn, #runBabyRun, #svn, #tempdir, #uncompress, #which, #writeFile

Constructor Details

#initialize(pathname) ⇒ Platform

Creates a new platform object for the Drupal installation at the specified path.



41
42
43
44
45
46
47
48
# File 'lib/drupid/platform.rb', line 41

def initialize(pathname)
  @local_path     = Pathname.new(pathname).realpath # must exist
  @sites_dir      = Pathname.new('sites')
  @contrib_path   = @sites_dir + 'all'
  @drupal_project = nil       # Project
  @projects       = Hash.new  # String -> PlatformProject
  @libraries      = Hash.new  # String -> Library
end

Instance Attribute Details

#contrib_pathObject

The path for contrib modules and themes (e.g., ‘sites/all’), relative to #local_path.



34
35
36
# File 'lib/drupid/platform.rb', line 34

def contrib_path
  @contrib_path
end

#drupal_projectObject (readonly)

A Drupid::Platform::Project object with information about Drupal core, or nil if this platform does not contain Drupal core.



31
32
33
# File 'lib/drupid/platform.rb', line 31

def drupal_project
  @drupal_project
end

#local_pathObject (readonly)

The absolute path to this platform.



28
29
30
# File 'lib/drupid/platform.rb', line 28

def local_path
  @local_path
end

#sites_dirObject (readonly)

The path to the sites directory (default: ‘sites’), relative relative to #local_path.



37
38
39
# File 'lib/drupid/platform.rb', line 37

def sites_dir
  @sites_dir
end

Instance Method Details

#analyzeObject

Analyzes this platform.



127
128
129
130
131
132
133
# File 'lib/drupid/platform.rb', line 127

def analyze
  blah "Analyzing #{local_path}"
  analyze_drupal_core
  analyze_projects
  analyze_libraries
  return self
end

#analyze_drupal_coreObject

Retrieves information about Drupal core in this platform.



136
137
138
139
140
# File 'lib/drupid/platform.rb', line 136

def analyze_drupal_core
  debug 'Analyzing Drupal Core...'
  @drupal_project = nil
  load_drupal_version
end

#analyze_librariesObject

 TODO: implement method



166
167
# File 'lib/drupid/platform.rb', line 166

def analyze_libraries
end

#analyze_projectsObject

Extracts information about the projects in this platform. This method is invoked automatically by Drupid::Platform.analyze. In general, it does not need to be called by the user.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/drupid/platform.rb', line 145

def analyze_projects
  @projects = Hash.new
  count = 0
  search_paths = Array.new
  search_paths << local_path+'modules/**/*.info'
  search_paths << local_path+'themes/**/*.info'
  search_paths << local_path+'profiles/*/*.info'
  search_paths << local_path+contrib_path+'modules/**/*.info'
  search_paths << local_path+contrib_path+'themes/**/*.info'
  search_paths.uniq! # contrib_path may be ''
  search_paths.each do |sp|
    Dir[sp.to_s].each do |p|
      pp = Drupid::PlatformProject.new(self, p)
      @projects[pp.name] = pp
      count += 1
    end
  end
  count
end

#bootstrapped?(site = nil) ⇒ Boolean

Returns true if the specified site in this platform is bootstrapped. If no site is specified, returns true if the platform contains at least one bootstrapped site. Returns false otherwise. Example:

platform.bootstrapped?('default')

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
# File 'lib/drupid/platform.rb', line 116

def bootstrapped?(site = nil)
  sites_list = (site) ? [site] : site_names
  sites_list.each do |s|
    p = sites_path + s
    next unless p.exist?
    return true if Drupid::Drush.bootstrapped?(p)
  end
  return false
end

#core_project_namesObject

Returns a list of the names of all core projects.



179
180
181
# File 'lib/drupid/platform.rb', line 179

def core_project_names
  @projects.values.select { |p| p.core_project? }.map { |p| p.name }
end

#dependency_graphObject

Creates an SVG image depicting the relationships among the projects in this platform.

Requires: the dot program. Without dot, only a .dot file is created, but no SVG image.

Returns the name of the created file.



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/drupid/platform.rb', line 200

def dependency_graph
  silence_warnings do
    begin
      require 'rgl/adjacency'
      require 'rgl/dot'
    rescue LoadError
      odie "Please install the RGL gem with 'gem install rgl'"
    end
  end
  analyze
  # We use this instead of a dag, because there may be circular dependencies...
  graph = ::RGL::DirectedAdjacencyGraph.new
  each_project do |p|
    graph.add_vertex(p.name)
    p.dependencies(:subprojects => false).each do |depname|
      graph.add_vertex(depname) # does nothing if depname already exists
      graph.add_edge(p.name, depname)
    end
  end
  each_core_project do |p|
    next if p.name.match(/test/) # Skip test modules
    graph.add_vertex('node' == p.name ? '"node"' : p.name) # 'node' is a Dot keyword
    p.dependencies.each do |depname|
      graph.add_vertex(depname)
      graph.add_edge(p.name, depname)
    end
  end
  outfile = graph.write_to_graphic_file('svg')
  if which('dot').nil?
    owarn "The 'dot' program is required to get an SVG image."
    return outfile.sub('.svg','.dot')
  else
    return outfile
  end
end

#dest_path(component) ⇒ Object

Returns the relative path where the given component should be placed in this platform.



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/drupid/platform.rb', line 79

def dest_path(component)
  if component.instance_of?(String) # assume it is the name of a platform project
    c = get_project(component)
    raise "No project called #{component} exists in this platform" if c.nil?
  else
    c = component
  end
  if c.core_project? or c.profile?
    return c.target_path
  else
    return contrib_path + c.target_path
  end
end

#each_core_projectObject

Iterates over all core projects in this platform.



189
190
191
# File 'lib/drupid/platform.rb', line 189

def each_core_project
  @projects.values.select { |p| p.core_project? }.each { |p| yield p }
end

#each_projectObject

Iterates over all contrib projects in this platform.



184
185
186
# File 'lib/drupid/platform.rb', line 184

def each_project
  @projects.values.reject { |p| p.core_project? }.each { |p| yield p }
end

#get_project(project_name) ⇒ Object

Returns the Drupid::PlatformProject object with the specified name, or nil if this platform does not contain a project with the given name.



102
103
104
105
# File 'lib/drupid/platform.rb', line 102

def get_project(project_name)
  return @drupal_project if @drupal_project and project_name == @drupal_project.name
  return @projects[project_name]
end

#has_project?(project_name) ⇒ Boolean

Returns true if this platform contains a project with the specified name.

Returns:

  • (Boolean)


108
109
110
# File 'lib/drupid/platform.rb', line 108

def has_project?(project_name)
  @projects.has_key?(project_name) or (@drupal_project and project_name == @drupal_project.name)
end

#libraries_pathObject

Returns the full path to the libraries folder.



72
73
74
# File 'lib/drupid/platform.rb', line 72

def libraries_path
  @local_path + @contrib_path + 'libraries'
end

#profilesObject

Returns a list of the names of the profiles that exist in this platform. For profiles to be found, they must be located inside the subdirectory of #local_path named ‘profiles’.



96
97
98
# File 'lib/drupid/platform.rb', line 96

def profiles
  Pathname.glob(local_path.to_s + '/profiles/*/*.profile').map { |p| p.basename('.profile').to_s }
end

#project_namesObject

Returns a list of the names of all contrib projects in this platform.



174
175
176
# File 'lib/drupid/platform.rb', line 174

def project_names
  @projects.values.reject { |p| p.core_project? }.map { |p| p.name }
end

#site_namesObject

Returns the (possibly empty) list of sites in this platform.



66
67
68
69
# File 'lib/drupid/platform.rb', line 66

def site_names
  return [] unless sites_path.exist?
  Pathname.glob(sites_path.to_s + '/*/').map { |s| s.basename.to_s }.reject { |s| s =~ /^all$/ }
end

#sites_pathObject

Returns the full path to the sites directory in this platform, e.g., ‘/path/to/drupal/sites’, as obtained by joining #local_path and #sites_dir.



61
62
63
# File 'lib/drupid/platform.rb', line 61

def sites_path
  @local_path + @sites_dir
end

#to_makefileObject

TODO: implement or throw away?



170
171
# File 'lib/drupid/platform.rb', line 170

def to_makefile()
end

#versionObject

Returns the version of Drupal core in this platform, or nil if the version cannot be determined.



52
53
54
55
56
57
# File 'lib/drupid/platform.rb', line 52

def version
  if (@drupal_project and @drupal_project.has_version?) or load_drupal_version
    return @drupal_project.version
  end
  return nil
end