Class: Pione::Command::PionePackageBuildContext

Inherits:
Rootage::CommandContext show all
Defined in:
lib/pione/command/pione-package-build.rb

Overview

PionePackageBuildContext is a context for pione package build.

Instance Attribute Summary

Attributes inherited from Rootage::ProcessContext

#model, #scenario

Instance Method Summary collapse

Methods inherited from Rootage::CommandContext

#quit, #stop

Methods inherited from Rootage::ProcessContext

#fail, #initialize, make, #test

Constructor Details

This class inherits a constructor from Rootage::ProcessContext

Instance Method Details

#archive_package(location, output) ⇒ Location

Update package information file.

Parameters:

  • location (Location)

    package directory location

Returns:

  • (Location)

    location of the generated PPG file



190
191
192
193
194
195
196
197
198
199
# File 'lib/pione/command/pione-package-build.rb', line 190

def archive_package(location, output)
  handler = Package::PackageReader.read(location)
  cache_location = Package::PackageCache.directory_cache(handler.digest)

  # make archiver
  archiver = Package::PackageArchiver.new(cache_location)

  # archive
  return archiver.archive(model[:output], false)
end

#build_package(location) ⇒ Location

Build a package of the location.

Parameters:

  • location (Location)

    package directory location

Returns:

  • (Location)

    location of the generated PPG file



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/pione/command/pione-package-build.rb', line 108

def build_package(location)
  local_location = location.local

  # action documents
  actions = read_action_documents(local_location)

  # compile
  compile_pnml(local_location, actions)

  # update
  update_package_info(local_location)

  # make archiver
  return archive_package(local_location, model[:output])
end

#compile_pnml(location, actions) ⇒ void

This method returns an undefined value.

Compile all PNML files in the location.

Parameters:

  • location (Location)

    package directory location

  • actions (Hash{String=>String})

    relation table for rule name and the action content



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/pione/command/pione-package-build.rb', line 150

def compile_pnml(location, actions)
  location.each_entry do |entry|
    if (entry.extname == ".pnml")
      begin
        flow_name = entry.basename(".pnml")
        net = PNML::Reader.read(entry)
        option = {
          :flow_rule_name => flow_name,
          :literate_actions => actions,
          :package_pione => location + "Package.pione"
        }
        content = PNML::Compiler.new(net, option).compile
        file = entry.dirname + (flow_name + ".pione")
        file.write(content)
      rescue
        Log::SystemLog.fatal("Error has occured when compiling the PNML file %s." % entry.address)
        raise
      end
    end
  end
end

#read_action_documents(location) ⇒ Hash{String=>String}

Read actions from action documents(files that named "*.action.md").

Parameters:

  • location (Location)

    package directory location

Returns:

  • (Hash{String=>String})

    relation table for rule name and the action content



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/pione/command/pione-package-build.rb', line 130

def read_action_documents(location)
  location.entries.each_with_object(Hash.new) do |entry, actions|
    if entry.basename.end_with?(".action.md")
      begin
        actions.merge!(LiterateAction::MarkdownParser.parse(entry.read))
      rescue
        Log::SystemLog.fatal("Error has occured when parsing the action document %s." % entry.address)
        raise
      end
    end
  end
end

#update_package_info(location) ⇒ void

This method returns an undefined value.

Update package information file.

Parameters:

  • location (Location)

    package directory location



177
178
179
180
181
182
# File 'lib/pione/command/pione-package-build.rb', line 177

def update_package_info(location)
  Package::PackageHandler.write_info_files(location, force: true)
rescue
  Log::SystemLog.fatal("Error has occured when updating package information file.")
  raise
end