class NetLinx::SRC::Package
A NetLinx
.src source code package.
Public Class Methods
new(**kvargs)
click to toggle source
Parameters:
Mode: :standard - Intelligently package all files pertaining to a NetLinx project. :classic - Emulates the AMX file packager, including only .axs and .axi files in the package. Also mimicks the same folder structure.
# File lib/netlinx/src/package.rb, line 19 def initialize **kvargs @file = kvargs.fetch :file, '' @mode = kvargs.fetch :mode, :standard @warning_file = '_FILE_EXTRACTION_WARNING.txt' end
Public Instance Methods
copy_to_zip()
click to toggle source
Copy the NetLinx
.src file to .zip for easy browsing without unpacking.
# File lib/netlinx/src/package.rb, line 67 def copy_to_zip FileUtils.cp @file, "#{@file}.zip" end
load_exclusions()
click to toggle source
Load a list of file exclusions (glob format) from .srcignore.
# File lib/netlinx/src/package.rb, line 57 def load_exclusions return [] unless File.exists? '.srcignore' lines = File.read('.srcignore').lines.map(&:strip) .reject { |l| l.empty? } # Remove empty lines. .reject { |l| l.start_with? '#' } # Remove commented lines. .map { |l| l.include?('/') ? l : "**/#{l}" } # Append **/ if a specific path isn't referenced. end
make_srcignore()
click to toggle source
Create a standard .srcignore file in the current directory. Raises exception if file exists.
# File lib/netlinx/src/package.rb, line 78 def make_srcignore raise IOError, "A .srcignore file already exists in this directory." \ if File.exists? '.srcignore' string = <<-EOS # --------------------------------------------------- # # Files to exclude from .SRC package (glob format). # # --------------------------------------------------- # # AMX *.src *.tp4 # Graphics *.ai *.bmp *.eps *.gif *.jpg *.jpeg *.png *.psd *.svg # Archives *.gz *.tar *.zip # Documentation *.pdf EOS File.write '.srcignore', string end
make_warning_file()
click to toggle source
Returns a string for the unpack warning file.
# File lib/netlinx/src/package.rb, line 120 def make_warning_file <<-EOS # ---------------------------------------------------------------------- # # WARNING: This archive should be unpacked with the netlinx-src utility # # ---------------------------------------------------------------------- # Download -------- http://sourceforge.net/p/netlinx-src/wiki/Home/ About ----- netlinx-src is a third-party utility for creating and extracting NetLinx .src source code package files. Unlike the standard utility that ships with NetLinx Studio, netlinx-src will retain the project's folder structure when the project is extracted. This becomes increasingly more important based on the number of files a project contains. Packaging a project with netlinx-src is also more comprehensive than using the standard utility. Not only is netlinx-src courteous enough to package files necessary for maintenance of the system (IR libraries, Duet modules, NetLinx modules, etc.), it also features a fine-grained file exclusion list that can prevent bulky touch panel files or graphics from filling up the disk space on the master. EOS .gsub("\n", "\r\n") # Format for readability in Notepad. end
pack()
click to toggle source
Pack the project into a NetLinx
.src package.
# File lib/netlinx/src/package.rb, line 27 def pack File.delete @file if File.exists? @file files = Dir['**/*'] - Dir[@file] + Dir['.srcignore'] # Exclude ignored files. exclusions = load_exclusions.map { |e| Dir[e] }.flatten files = files - exclusions Zip::File.open @file, Zip::File::CREATE do |zip| files.each { |file| zip.add file, file } zip.get_output_stream(@warning_file) { |f| f.puts make_warning_file } end end
remove_zip()
click to toggle source
Remove the .zip version of this NetLinx
.src file if it exists.
# File lib/netlinx/src/package.rb, line 72 def remove_zip File.delete "#{@file}.zip" if File.exists? "#{@file}.zip" end
unpack(dir = nil)
click to toggle source
Unpack a NetLinx
.src project package. Unpacks to the given directory, if provided.
# File lib/netlinx/src/package.rb, line 47 def unpack dir = nil Zip::File.open @file do |zip| zip.each_entry do |e| path = dir.nil? ? e.name : "#{dir}/#{e.name}" e.extract path unless e.name == @warning_file end end end