class Drupid::Platform

Attributes

contrib_path[RW]

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

drupal_project[R]

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

local_path[R]

The absolute path to this platform.

sites_dir[R]

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

Public Class Methods

new(pathname) click to toggle source

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

   # File lib/drupid/platform.rb
40 def initialize(pathname)
41   @local_path     = Pathname.new(pathname).realpath # must exist
42   @sites_dir      = Pathname.new('sites')
43   @contrib_path   = @sites_dir + 'all'
44   @drupal_project = nil       # Project
45   @projects       = Hash.new  # String -> PlatformProject
46   @libraries      = Hash.new  # String -> Library
47 end

Public Instance Methods

analyze() click to toggle source

Analyzes this platform.

    # File lib/drupid/platform.rb
126 def analyze
127   blah "Analyzing #{local_path}"
128   analyze_drupal_core
129   analyze_projects
130   analyze_libraries
131   return self
132 end
analyze_drupal_core() click to toggle source

Retrieves information about Drupal core in this platform.

    # File lib/drupid/platform.rb
135 def analyze_drupal_core
136   debug 'Analyzing Drupal Core...'
137   @drupal_project = nil
138   load_drupal_version
139 end
analyze_libraries() click to toggle source

 TODO: implement method

    # File lib/drupid/platform.rb
165 def analyze_libraries
166 end
analyze_projects() click to toggle source

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.

    # File lib/drupid/platform.rb
144 def analyze_projects
145   @projects = Hash.new
146   count = 0
147   search_paths = Array.new
148   search_paths << local_path+'modules/**/*.info'
149   search_paths << local_path+'themes/**/*.info'
150   search_paths << local_path+'profiles/*/*.info'
151   search_paths << local_path+contrib_path+'modules/**/*.info'
152   search_paths << local_path+contrib_path+'themes/**/*.info'
153   search_paths.uniq! # contrib_path may be ''
154   search_paths.each do |sp|
155     Dir[sp.to_s].each do |p|
156       pp = Drupid::PlatformProject.new(self, p)
157       @projects[pp.name] = pp
158       count += 1
159     end
160   end
161   count
162 end
bootstrapped?(site = nil) click to toggle source

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')
    # File lib/drupid/platform.rb
115 def bootstrapped?(site = nil)
116   sites_list = (site) ? [site] : site_names
117   sites_list.each do |s|
118     p = sites_path + s
119     next unless p.exist?
120     return true if Drupid::Drush.bootstrapped?(p)
121   end
122   return false
123 end
core_project_names() click to toggle source

Returns a list of the names of all core projects.

    # File lib/drupid/platform.rb
178 def core_project_names
179   @projects.values.select { |p| p.core_project? }.map { |p| p.name }
180 end
dependency_graph() click to toggle source

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.

    # File lib/drupid/platform.rb
199 def dependency_graph
200   silence_warnings do
201     begin
202       require 'rgl/adjacency'
203       require 'rgl/dot'
204     rescue LoadError
205       odie "Please install the RGL gem with 'gem install rgl'"
206     end
207   end
208   analyze
209   # We use this instead of a dag, because there may be circular dependencies...
210   graph = ::RGL::DirectedAdjacencyGraph.new
211   each_project do |p|
212     graph.add_vertex(p.name)
213     p.dependencies(:subprojects => false).each do |depname|
214       graph.add_vertex(depname) # does nothing if depname already exists
215       graph.add_edge(p.name, depname)
216     end
217   end
218   each_core_project do |p|
219     next if p.name.match(/test/) # Skip test modules
220     graph.add_vertex('node' == p.name ? '"node"' : p.name) # 'node' is a Dot keyword
221     p.dependencies.each do |depname|
222       graph.add_vertex(depname)
223       graph.add_edge(p.name, depname)
224     end
225   end
226   outfile = graph.write_to_graphic_file('svg')
227   if which('dot').nil?
228     owarn "The 'dot' program is required to get an SVG image."
229     return outfile.sub('.svg','.dot')
230   else
231     return outfile
232   end
233 end
dest_path(component) click to toggle source

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

   # File lib/drupid/platform.rb
78 def dest_path(component)
79   if component.instance_of?(String) # assume it is the name of a platform project
80     c = get_project(component)
81     raise "No project called #{component} exists in this platform" if c.nil?
82   else
83     c = component
84   end
85   if c.core_project? or c.profile?
86     return c.target_path
87   else
88     return contrib_path + c.target_path
89   end
90 end
each_core_project() { |p| ... } click to toggle source

Iterates over all core projects in this platform.

    # File lib/drupid/platform.rb
188 def each_core_project
189   @projects.values.select { |p| p.core_project? }.each { |p| yield p }
190 end
each_project() { |p| ... } click to toggle source

Iterates over all contrib projects in this platform.

    # File lib/drupid/platform.rb
183 def each_project
184   @projects.values.reject { |p| p.core_project? }.each { |p| yield p }
185 end
get_project(project_name) click to toggle source

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

    # File lib/drupid/platform.rb
101 def get_project(project_name)
102   return @drupal_project if @drupal_project and project_name == @drupal_project.name
103   return @projects[project_name]
104 end
has_project?(project_name) click to toggle source

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

    # File lib/drupid/platform.rb
107 def has_project?(project_name)
108   @projects.has_key?(project_name) or (@drupal_project and project_name == @drupal_project.name)
109 end
libraries_path() click to toggle source

Returns the full path to the libraries folder.

   # File lib/drupid/platform.rb
71 def libraries_path
72   @local_path + @contrib_path + 'libraries'
73 end
profiles() click to toggle source

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’.

   # File lib/drupid/platform.rb
95 def profiles
96   Pathname.glob(local_path.to_s + '/profiles/*/*.profile').map { |p| p.basename('.profile').to_s }
97 end
project_names() click to toggle source

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

    # File lib/drupid/platform.rb
173 def project_names
174   @projects.values.reject { |p| p.core_project? }.map { |p| p.name }
175 end
site_names() click to toggle source

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

   # File lib/drupid/platform.rb
65 def site_names
66   return [] unless sites_path.exist?
67   Pathname.glob(sites_path.to_s + '/*/').map { |s| s.basename.to_s }.reject { |s| s =~ /^all$/ }
68 end
sites_path() click to toggle source

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.

   # File lib/drupid/platform.rb
60 def sites_path
61   @local_path + @sites_dir
62 end
to_makefile() click to toggle source

TODO: implement or throw away?

    # File lib/drupid/platform.rb
169 def to_makefile()
170 end
version() click to toggle source

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

   # File lib/drupid/platform.rb
51 def version
52   if (@drupal_project and @drupal_project.has_version?) or load_drupal_version
53     return @drupal_project.version
54   end
55   return nil
56 end

Private Instance Methods

load_drupal_version() click to toggle source
    # File lib/drupid/platform.rb
237 def load_drupal_version
238   # Drupal 7 stores VERSION in bootstrap.inc. Drupal 8 moved that to /core/includes.
239   bootstrap_files = ['core/includes/bootstrap.inc', 'includes/bootstrap.inc', 'modules/system/system.module']
240   bootstrap_files.each do |bf|
241     f = self.local_path+bf
242     next unless f.exist?
243     f.open('r').each_line do |l|
244       if l =~ /define.*'VERSION'.*'(.+)'/
245         v = $1
246         debug "Drupal version detected: #{v}"
247         core = v.match(/^(\d+)\./)[1].to_i
248         @drupal_project = Drupid::Project.new('drupal', core, v)
249         @drupal_project.local_path = self.local_path
250         debug "Drupal platform has version: #{@drupal_project.version} (core: #{@drupal_project.version.core})"
251         return true
252       end
253     end
254   end
255   debug "Unable to detect version of Drupal at #{self.local_path}"
256   return false
257 end