Top Level Namespace
Constant Summary collapse
- MD5_COMMMAND =
"md5"
Instance Method Summary collapse
- #bundle ⇒ Object
- #generate_manifest ⇒ Object
- #generate_manifest_3_02(file_list) ⇒ Object
- #generate_manifest_3_3(file_list) ⇒ Object
- #get_cksum(filename) ⇒ Object
- #get_git_revision(filename) ⇒ Object
- #get_spaceport_options ⇒ Object
- #get_svn_revision(filename) ⇒ Object
- #get_total_size(file_list) ⇒ Object
- #get_version(filename, version_type) ⇒ Object
- #print_size_information(file_list) ⇒ Object
- #spaceport_options ⇒ Object
Instance Method Details
#bundle ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bundle.rb', line 5 def bundle # bundlePath = ARGV[0] # output_dir = ARGV[1] = {} opts = OptionParser.new do |opts| opts. ="Usage: " opts.on( "-c", "--config CONFIG", "Path to your config file" ) do |path| [:bundle_config_path] = path end opts.on("-o", "--output BUNDLE_DIR", "Directory you would like bundle to go to") do |path| [:bundle_dir] = path end opts.on("-m", "--manifest MANIFEST_DIR", "Directory you would like the manifest to go to") do |path| [:manifest_output_dir] = path end opts.on("--no-manifest" "Do not generate a manifest or fuller_asset_list") do |value| [:no_manifest] = true end end opts.parse! bundle_config_path = [:bundle_config_path] || [:bundle_config_path] bundle_dir = [:bundle_dir] || [:bundle_dir] manifest_output_dir = [:manifest_output_dir] || [:manifest_output_dir] if ( !bundle_dir || !manifest_output_dir || !bundle_config_path) bundle_config_path = ARGV[0] manifest_output_dir = ARGV[1] bundle_dir = ARGV[2] puts "You are using this in the deprecated way! Please do not" exit end current_dir = File.(File.dirname(__FILE__)) built_client_dir = File.join(bundle_dir, "built_client", "assets") = File.join(current_dir, "generate_manifest.rb") full_asset_list_path = File.join(manifest_output_dir, "full_asset_list.txt") manifest_path = File.join(manifest_output_dir, "manifest.xml") if ( ![:no_manifest] ) puts `spaceport generate_manifest --config #{bundle_config_path} --output #{manifest_output_dir}` end `rm -rf #{built_client_dir}` `mkdir -p #{built_client_dir}` `rsync -rvmL --exclude='#{built_client_dir}/*' --include-from=#{full_asset_list_path} --include='*/' --exclude='*' #{manifest_output_dir}/ #{built_client_dir}` `cp #{manifest_path} #{built_client_dir}` # TODO: # Zip stuff up for Android #( cd built_client && zip -r built_client.zip *.js content *.html manifest.xml ) #cp built_client/built_client.zip $DESTINATION #echo "copying built_client.zip to $DESTINATION" end |
#generate_manifest ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 118 119 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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/generate_manifest.rb', line 10 def generate_manifest # bundlePath = ARGV[0] # output_dir = ARGV[1] = {} opts = OptionParser.new do |opts| opts. ="Usage: This will create two output files; a manifest.xml, and a full_asset_list.txt" opts.on( "-c", "--config CONFIG", "Path to your config file" ) do |path| [:bundle_config_path] = path end opts.on("-o", "--output OUTPUT", "Directory you would like the two output files to go to") do |path| [:manifest_output_dir] = path end end opts.parse! bundlePath = [:bundle_config_path] || [:bundle_config_path] output_dir = [:manifest_output_dir] || [:manifest_output_dir] app_root_dir = output_dir if ( !bundlePath || !output_dir ) puts opts exit end wants = [] doNotWants = [] completeFileList = {} File.open(bundlePath, "r") do |f| while !f.eof? line = f.readline matchData = /^\s#(.*)$/.match(line) if matchData next end matchData = /^\s*$/.match(line) if( matchData ) next end matchData = /^-([^\s]*)/.match(line) if matchData doNotWants.push( {:path => matchData[1]}) next; end matchData = /^([^\s]*)[\s]*([^\s]*)/.match(line) if( matchData ) wants.push( {:path => matchData[1], :version => matchData[2]}) end end end original_dir = Dir.pwd Dir.chdir( app_root_dir ) wants.each do |w| Dir.glob( w[:path] ) do |filename| next if File.directory?(filename) completeFileList[filename] = w[:version] end end doNotWants.each do |d| Dir.glob( d[:path] ) do |filename| next if File.directory?(filename) completeFileList.delete( filename ) end end file_list=completeFileList.keys.sort def get_cksum( filename ) if MD5_COMMMAND=="md5" `#{MD5_COMMMAND} #{filename} | awk '-F= ' '{ print $2 }'`.strip elsif MD5_COMMMAND=="md5sum" `#{MD5_COMMMAND} #{filename}`.split(" ")[0].strip end end def get_svn_revision( filename ) `svn info -- '#{filename}' | grep "Last Changed Rev" | awk '-F: ' '{ print $2 }'`.strip end def get_git_revision( filename ) `git log --format=%h -1 -- #{filename}`.strip end def get_version(filename, version_type) if ( version_type == 'svn') get_svn_revision( filename ) elsif ( version_type == 'git') get_git_revision( filename ) elsif( version_type=='md5') get_cksum( filename ) else raise "version scheme: \"#{version_type}\" specified for filename: \"#{filename}\" is invalid." end end file_list = file_list.map do |filename| version = get_version( filename, completeFileList[filename] ) if !version || version == "" puts "#{filename} is unversioned" nil else {:version => version, :name => filename, :filesize => File.size( filename ) } end end.compact def get_total_size( file_list ) total_size = file_list.inject(0){|sum,x| sum + x[:filesize].to_i} puts (total_size / 1024).to_s + " KB" puts (total_size / (1024*1024)).to_s + " MB" total_size end def print_size_information( file_list ) file_extensions ={} file_list.each do |a| ext = File.extname( a[:name] ) file_extensions[ ext ] = file_extensions[ ext ] || [] file_extensions[ext].push(a) end file_extensions.keys.each do |ext| puts ext get_total_size( file_extensions[ ext] ) puts "" end puts "Total" total_file_size = get_total_size( file_list )/( 1024 * 1024 ); puts "" file_sizes_hsh = {} file_extensions.keys.each do |ext| file_size = get_total_size( file_extensions[ ext] )/(1024*1024) file_sizes_hsh[ ext + "(" + file_size.to_s + "MB)"] = file_size end puts "http://chart.apis.google.com/chart?chs=800x225&cht=p&chd=t:#{file_sizes_hsh.values.join(',')}&chdl=#{file_sizes_hsh.keys.join('|')}&chl=#{file_sizes_hsh.keys.join('|')}&chtt=Disk+Usage(#{total_file_size}+MB)" end def generate_manifest_3_3( file_list ) prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="THIS_DOES_NOTHING" platform="3.3"> eos plugins = <<-eos <plugins> <entry id="io.spaceport.plugins.chartboost" version="3.3.0"/> <entry id="io.spaceport.plugins.facebook" version="3.3.0"/> <entry id="io.spaceport.plugins.flurry" version="3.3.0"/> <entry id="io.spaceport.plugins.localnotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.mail" version="3.3.0"/> <entry id="io.spaceport.plugins.market" version="3.3.0"/> <entry id="io.spaceport.plugins.remotenotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.sms" version="3.3.0"/> <entry id="io.spaceport.plugins.tapjoy" version="3.3.0"/> <entry id="io.spaceport.plugins.twitter" version="3.3.0"/> <entry id="io.spaceport.plugins.particle" version="3.3.0"/> </plugins> eos xml_file_list = file_list.map do |_value| value = _value.dup value[:id] = value[:name] value.delete(:name) "\t<entry " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end startup = <<-eos <startup> #{xml_file_list.join("\n")} </startup> eos suffix = <<-eos <code></code> <assets></assets> </manifest> eos output = prefix + plugins + startup + suffix end def generate_manifest_3_02( file_list ) xml_file_list = file_list.map do |value| "\t<file " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="3.02"> <files> eos suffix = <<-eos </files> </manifest> eos output = prefix + xml_file_list.join("\n") + suffix output end print_size_information( file_list ) output = generate_manifest_3_3( file_list ) Dir.chdir( original_dir ) File.open( File.join(output_dir, "manifest.xml"), 'w' ) do |file| file.write( output ) end asset_file_name = File.join( output_dir, "full_asset_list.txt" ) File.open( asset_file_name , 'w' ) do |file| file.write( file_list.map{|k| k[:name] }.map do |k| if k[0,2] == "./" k[2, k.length - 1] else k end end.join("\n") ) end end |
#generate_manifest_3_02(file_list) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/generate_manifest.rb', line 218 def generate_manifest_3_02( file_list ) xml_file_list = file_list.map do |value| "\t<file " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="3.02"> <files> eos suffix = <<-eos </files> </manifest> eos output = prefix + xml_file_list.join("\n") + suffix output end |
#generate_manifest_3_3(file_list) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/generate_manifest.rb', line 174 def generate_manifest_3_3( file_list ) prefix = <<-eos <?xml version="1.0" encoding="utf-8"?> <manifest version="THIS_DOES_NOTHING" platform="3.3"> eos plugins = <<-eos <plugins> <entry id="io.spaceport.plugins.chartboost" version="3.3.0"/> <entry id="io.spaceport.plugins.facebook" version="3.3.0"/> <entry id="io.spaceport.plugins.flurry" version="3.3.0"/> <entry id="io.spaceport.plugins.localnotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.mail" version="3.3.0"/> <entry id="io.spaceport.plugins.market" version="3.3.0"/> <entry id="io.spaceport.plugins.remotenotifications" version="3.3.0"/> <entry id="io.spaceport.plugins.sms" version="3.3.0"/> <entry id="io.spaceport.plugins.tapjoy" version="3.3.0"/> <entry id="io.spaceport.plugins.twitter" version="3.3.0"/> <entry id="io.spaceport.plugins.particle" version="3.3.0"/> </plugins> eos xml_file_list = file_list.map do |_value| value = _value.dup value[:id] = value[:name] value.delete(:name) "\t<entry " + value.map {|k,v| k.to_s + "=\"#{v}\"" }.join(" ") + "/>" end startup = <<-eos <startup> #{xml_file_list.join("\n")} </startup> eos suffix = <<-eos <code></code> <assets></assets> </manifest> eos output = prefix + plugins + startup + suffix end |
#get_cksum(filename) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/generate_manifest.rb', line 94 def get_cksum( filename ) if MD5_COMMMAND=="md5" `#{MD5_COMMMAND} #{filename} | awk '-F= ' '{ print $2 }'`.strip elsif MD5_COMMMAND=="md5sum" `#{MD5_COMMMAND} #{filename}`.split(" ")[0].strip end end |
#get_git_revision(filename) ⇒ Object
106 107 108 |
# File 'lib/generate_manifest.rb', line 106 def get_git_revision( filename ) `git log --format=%h -1 -- #{filename}`.strip end |
#get_spaceport_options ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/lib.rb', line 3 def if File.exists?(".spaceport") opts = JSON.parse( File.open( ".spaceport", "r" ).read ) out = {} opts.each do |k,v| out[k] = v out[k.intern] = v end return out else return {} end end |
#get_svn_revision(filename) ⇒ Object
102 103 104 |
# File 'lib/generate_manifest.rb', line 102 def get_svn_revision( filename ) `svn info -- '#{filename}' | grep "Last Changed Rev" | awk '-F: ' '{ print $2 }'`.strip end |
#get_total_size(file_list) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/generate_manifest.rb', line 135 def get_total_size( file_list ) total_size = file_list.inject(0){|sum,x| sum + x[:filesize].to_i} puts (total_size / 1024).to_s + " KB" puts (total_size / (1024*1024)).to_s + " MB" total_size end |
#get_version(filename, version_type) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/generate_manifest.rb', line 111 def get_version(filename, version_type) if ( version_type == 'svn') get_svn_revision( filename ) elsif ( version_type == 'git') get_git_revision( filename ) elsif( version_type=='md5') get_cksum( filename ) else raise "version scheme: \"#{version_type}\" specified for filename: \"#{filename}\" is invalid." end end |
#print_size_information(file_list) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/generate_manifest.rb', line 143 def print_size_information( file_list ) file_extensions ={} file_list.each do |a| ext = File.extname( a[:name] ) file_extensions[ ext ] = file_extensions[ ext ] || [] file_extensions[ext].push(a) end file_extensions.keys.each do |ext| puts ext get_total_size( file_extensions[ ext] ) puts "" end puts "Total" total_file_size = get_total_size( file_list )/( 1024 * 1024 ); puts "" file_sizes_hsh = {} file_extensions.keys.each do |ext| file_size = get_total_size( file_extensions[ ext] )/(1024*1024) file_sizes_hsh[ ext + "(" + file_size.to_s + "MB)"] = file_size end puts "http://chart.apis.google.com/chart?chs=800x225&cht=p&chd=t:#{file_sizes_hsh.values.join(',')}&chdl=#{file_sizes_hsh.keys.join('|')}&chl=#{file_sizes_hsh.keys.join('|')}&chtt=Disk+Usage(#{total_file_size}+MB)" end |
#spaceport_options ⇒ Object
18 19 20 |
# File 'lib/lib.rb', line 18 def () () end |