class Pione::Command::PionePackageBuildContext

‘PionePackageBuildContext` is a context for `pione package build`.

Public Instance Methods

archive_package(location, output) click to toggle source

Update package information file.

@param location [Location]

package directory location

@return [Location]

location of the generated PPG file
# 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) click to toggle source

Build a package of the location.

@param location [Location]

package directory location

@return [Location]

location of the generated PPG file
# 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) click to toggle source

Compile all PNML files in the location.

@param location [Location]

package directory location

@param actions [Hash{String=>String}]

relation table for rule name and the action content

@return [void]

# 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) click to toggle source

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

@param location [Location]

package directory location

@return [Hash{String=>String}]

relation table for rule name and the action content
# 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) click to toggle source

Update package information file.

@param location [Location]

package directory location

@return [void]

# 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