Class: NetLinx::SRC::Package
- Inherits:
-
Object
- Object
- NetLinx::SRC::Package
- Defined in:
- lib/netlinx/src/package.rb
Overview
A NetLinx .src source code package.
Instance Method Summary collapse
-
#copy_to_zip ⇒ Object
Copy the NetLinx .src file to .zip for easy browsing without unpacking.
-
#initialize(**kvargs) ⇒ Package
constructor
Parameters:.
-
#load_exclusions ⇒ Object
Load a list of file exclusions (glob format) from .srcignore.
-
#make_srcignore ⇒ Object
Create a standard .srcignore file in the current directory.
-
#make_warning_file ⇒ Object
Returns a string for the unpack warning file.
-
#pack ⇒ Object
Pack the project into a NetLinx .src package.
-
#remove_zip ⇒ Object
Remove the .zip version of this NetLinx .src file if it exists.
-
#unpack(dir = nil) ⇒ Object
Unpack a NetLinx .src project package.
Constructor Details
#initialize(**kvargs) ⇒ Package
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.
19 20 21 22 23 24 |
# 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 |
Instance Method Details
#copy_to_zip ⇒ Object
Copy the NetLinx .src file to .zip for easy browsing without unpacking.
67 68 69 |
# File 'lib/netlinx/src/package.rb', line 67 def copy_to_zip FileUtils.cp @file, "#{@file}.zip" end |
#load_exclusions ⇒ Object
Load a list of file exclusions (glob format) from .srcignore.
57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
Create a standard .srcignore file in the current directory. Raises exception if file exists.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# 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 ⇒ Object
Returns a string for the unpack warning file.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/netlinx/src/package.rb', line 120 def make_warning_file <<-EOS .gsub("\n", "\r\n") # Format for readability in Notepad. # ---------------------------------------------------------------------- # # 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 end |
#pack ⇒ Object
Pack the project into a NetLinx .src package.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
Remove the .zip version of this NetLinx .src file if it exists.
72 73 74 |
# File 'lib/netlinx/src/package.rb', line 72 def remove_zip File.delete "#{@file}.zip" if File.exists? "#{@file}.zip" end |
#unpack(dir = nil) ⇒ Object
Unpack a NetLinx .src project package. Unpacks to the given directory, if provided.
47 48 49 50 51 52 53 54 |
# 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 |