diff -ur tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/README tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/README
--- tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/README 2003-10-19 19:17:19.000000000 +0200
+++ tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/README 2004-12-03 23:10:19.000000000 +0100
@@ -1,6 +1,10 @@
-Usage: ruby init.rb application.tar [application.rb [licence.txt]]
- or
- ruby init.rb application[/] [application.rb [licence.txt]]
+The best way to use Tar2RubyScript is the RB, not this TAR.GZ.
+The latter is just for playing with the internals. Both are
+available on the site.
+
+ Usage: ruby init.rb application.tar [application.rb [licence.txt]]
+ or
+ ruby init.rb application[/] [application.rb [licence.txt]]
If "application.rb" is not provided or equals to "-", it will
be derived from "application.tar" or "application/".
@@ -8,5 +12,8 @@
If a license is provided, it will be put at the beginning of
The Application.
+Parts of the code for Tar2RubyScript are based on code from
+Thomas Hurst <tom@hur.st>.
+
For more information, see
-http://www.erikveen.dds.nl/tar2rubyscript/ .
+http://www.erikveen.dds.nl/tar2rubyscript/index.html .
diff -ur tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb
--- tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb 2004-03-26 15:12:40.000000000 +0100
+++ tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb 2004-12-03 23:13:40.000000000 +0100
@@ -1,11 +1,34 @@
-ENV["OLDDIR"] = Dir.pwd if not ENV.include?("OLDDIR")
-ENV["NEWDIR"] = Dir.pwd if not ENV.include?("NEWDIR")
+temp = (ENV["TMPDIR"] or ENV["TMP"] or ENV["TEMP"] or "/tmp").gsub(/\\/, "/")
+dir = "#{temp}/oldandnewlocation.#{Process.pid}"
+
+ENV["OLDDIR"] = Dir.pwd unless ENV.include?("OLDDIR")
+ENV["NEWDIR"] = File.dirname($0) unless ENV.include?("NEWDIR")
+ENV["TEMPDIR"] = dir unless ENV.include?("TEMPDIR")
+
+class Dir
+ def self.rm_rf(entry)
+ if File.ftype(entry) == "directory"
+ pdir = Dir.pwd
+
+ Dir.chdir(entry)
+ Dir.new(".").each do |e|
+ Dir.rm_rf(e) if not [".", ".."].include?(e)
+ end
+ Dir.chdir(pdir)
+
+ Dir.delete(entry)
+ else
+ File.delete(entry)
+ end
+ end
+end
begin
oldlocation
rescue NameError
def oldlocation(file="")
dir = ENV["OLDDIR"]
+ res = nil
if block_given?
pdir = Dir.pwd
@@ -14,7 +37,7 @@
res = yield
Dir.chdir(pdir)
else
- res = File.expand_path(file, dir) if not file.nil?
+ res = File.expand_path(file, dir) unless file.nil?
end
res
@@ -26,6 +49,41 @@
rescue NameError
def newlocation(file="")
dir = ENV["NEWDIR"]
+ res = nil
+
+ if block_given?
+ pdir = Dir.pwd
+
+ Dir.chdir(dir)
+ res = yield
+ Dir.chdir(pdir)
+ else
+ res = File.expand_path(file, dir) unless file.nil?
+ end
+
+ res
+ end
+end
+
+begin
+ tmplocation
+rescue NameError
+ dir = ENV["TEMPDIR"]
+
+ Dir.rm_rf(dir) if File.directory?(dir)
+ Dir.mkdir(dir)
+
+ at_exit do
+ if File.directory?(dir)
+ Dir.chdir(dir)
+ Dir.chdir("..")
+ Dir.rm_rf(dir)
+ end
+ end
+
+ def tmplocation(file="")
+ dir = ENV["TEMPDIR"]
+ res = nil
if block_given?
pdir = Dir.pwd
@@ -34,7 +92,7 @@
res = yield
Dir.chdir(pdir)
else
- res = File.expand_path(file, dir) if not file.nil?
+ res = File.expand_path(file, dir) unless file.nil?
end
res
diff -ur tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/init.rb tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/init.rb
--- tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/init.rb 2004-03-20 18:42:23.000000000 +0100
+++ tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/init.rb 2004-12-03 23:09:07.000000000 +0100
@@ -1,46 +1,61 @@
require "ev/oldandnewlocation"
+exit if ARGV.include?("--tar2rubyscript-exit")
+
scriptfile = "tarrubyscript.rb"
tarfile = oldlocation(ARGV.shift)
rbfile = oldlocation(ARGV.shift)
licensefile = oldlocation(ARGV.shift)
if tarfile.nil?
+ $stderr.puts <<-EOF
+
+ Usage: ruby init.rb application.tar [application.rb [licence.txt]]
+ or
+ ruby init.rb application[/] [application.rb [licence.txt]]
+
+ If \"application.rb\" is not provided or equals to \"-\", it will
+ be derived from \"application.tar\" or \"application/\".
+
+ If a license is provided, it will be put at the beginning of
+ The Application.
+
+ For more information, see
+ http://www.erikveen.dds.nl/tar2rubyscript/index.html .
+ EOF
+
exit 1
end
tarfile.dup.gsub!(/[\/\\]$/, "")
-if not FileTest.exist?(tarfile)
+if not File.exist?(tarfile)
$stderr.puts "#{tarfile} doesn´t exist."
exit
end
-if not licensefile.nil? and not FileTest.file?(licensefile)
+if not licensefile.nil? and not licensefile.empty? and not File.file?(licensefile)
$stderr.puts "#{licensefile} doesn´t exist."
exit
end
-script = nil
-archive = nil
-
-File.open(scriptfile) {|f| script = f.read}
+script = File.open(scriptfile){|f| f.read}
-if FileTest.file?(tarfile)
- File.open(tarfile, "rb") {|f| archive = [f.read].pack("m").split("\n").collect{|s| "# " + s}.join("\n")}
+if File.file?(tarfile)
+ archive = File.open(tarfile, "rb"){|f| [f.read].pack("m").split("\n").collect{|s| "# " + s}.join("\n")}
end
-if FileTest.directory?(tarfile)
- orgdir = Dir.pwd
+if File.directory?(tarfile)
+ pdir = Dir.pwd
Dir.chdir(tarfile)
- if FileTest.file?("tar2rubyscript.bat")
+ if File.file?("tar2rubyscript.bat")
$stderr.puts "\".\\tar2rubyscript.bat\""
system(".\\tar2rubyscript.bat")
end
- if FileTest.file?("tar2rubyscript.sh")
+ if File.file?("tar2rubyscript.sh")
$stderr.puts "\". ./tar2rubyscript.sh\""
system("sh -c \". ./tar2rubyscript.sh\"")
end
@@ -49,17 +64,17 @@
begin
tar = "tar"
- IO.popen("#{tar} ch #{tarfile.sub(/.*[\/\\]/, "")}", "rb") {|f| archive = [f.read].pack("m").split("\n").collect{|s| "# " + s}.join("\n")}
+ archive = IO.popen("#{tar} ch #{tarfile.sub(/.*[\/\\]/, "")}", "rb"){|f| [f.read].pack("m").split("\n").collect{|s| "# " + s}.join("\n")}
rescue
tar = newlocation("tar.exe")
- IO.popen("#{tar} ch #{tarfile.sub(/.*[\/\\]/, "")}", "rb") {|f| archive = [f.read].pack("m").split("\n").collect{|s| "# " + s}.join("\n")}
+ archive = IO.popen("#{tar} ch #{tarfile.sub(/.*[\/\\]/, "")}", "rb"){|f| [f.read].pack("m").split("\n").collect{|s| "# " + s}.join("\n")}
end
- Dir.chdir(orgdir)
+ Dir.chdir(pdir)
end
-if not licensefile.nil?
- lic = nil ; File.open(licensefile) {|f| lic = f.readlines}
+if not licensefile.nil? and not licensefile.empty?
+ lic = File.open(licensefile){|f| f.readlines}
lic.collect! do |line|
line.gsub!(/[\r\n]/, "")
diff -ur tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/tarrubyscript.rb tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/tarrubyscript.rb
--- tar2rubyscript-0.3.8.tar.gz/tar2rubyscript/tarrubyscript.rb 2004-03-26 14:35:19.000000000 +0100
+++ tar2rubyscript-0.4.0.tar.gz/tar2rubyscript/tarrubyscript.rb 2004-12-03 22:53:43.000000000 +0100
@@ -16,6 +16,9 @@
# Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA.
+# Parts of this code are based on code from Thomas Hurst
+# <tom@hur.st>.
+
# Tar2RubyScript constants
JustExtract = ARGV.include?("--tar2rubyscript-justextract")
@@ -59,6 +62,24 @@
LF_FIFO = ´6´
LF_CONTIG = ´7´
+class Dir
+ def self.rm_rf(entry)
+ if File.ftype(entry) == "directory"
+ pdir = Dir.pwd
+
+ Dir.chdir(entry)
+ Dir.new(".").each do |e|
+ rm_rf(e) if not [".", ".."].include?(e)
+ end
+ Dir.chdir(pdir)
+
+ Dir.delete(entry)
+ else
+ File.delete(entry)
+ end
+ end
+end
+
class Reader
def initialize(filehandle)
@fp = filehandle
@@ -182,7 +203,7 @@
class TempSpace
def initialize
- @archive = File.new($0, "rb").read.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift
+ @archive = File.open(File.expand_path(__FILE__), "rb"){|f| f.read}.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift
@olddir = Dir.pwd
temp = ENV["TEMP"]
temp = "/tmp" if temp.nil?
@@ -195,7 +216,7 @@
end
def extract
- Dir.mkdir(@tempdir) if not FileTest.exists?(@tempdir)
+ Dir.mkdir(@tempdir) if not File.exists?(@tempdir)
newlocation do
@@ -212,7 +233,7 @@
if entries.length == 1
entry = entries.shift.dup
- if FileTest.directory?(entry)
+ if File.directory?(entry)
@newdir = "#{@tempdir}/#{entry}"
end
end
@@ -237,27 +258,17 @@
Dir.chdir(@olddir)
- recursivedelete(@tempfile)
- recursivedelete(@tempdir)
+ Dir.rm_rf(@tempfile)
+ Dir.rm_rf(@tempdir)
end
- end
- def recursivedelete(entry)
- if FileTest.file?(entry)
- File.delete(entry)
- end
-
- if FileTest.directory?(entry)
- pdir = Dir.pwd
+ self
+ end
- Dir.chdir(entry)
- Dir.new(".").each do |e|
- recursivedelete(e) if not [".", ".."].include?(e)
- end
- Dir.chdir(pdir)
+ def cleanup
+ @archive = nil
- Dir.rmdir(entry)
- end
+ self
end
def oldlocation(file="")
@@ -307,7 +318,7 @@
class Extract
def initialize
- @archive = File.new($0, "rb").read.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift
+ @archive = File.open(File.expand_path(__FILE__), "rb"){|f| f.read}.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift
temp = ENV["TEMP"]
temp = "/tmp" if temp.nil?
@tempfile = "#{temp}/tar2rubyscript.f.#{Process.pid}"
@@ -320,17 +331,33 @@
ensure
File.delete(@tempfile)
end
+
+ self
+ end
+
+ def cleanup
+ @archive = nil
+
+ self
end
end
class MakeTar
def initialize
- @archive = File.new($0, "rb").read.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift
- @tarfile = $0.gsub(/\.rbw?$/, "") + ".tar"
+ @archive = File.open(File.expand_path(__FILE__), "rb"){|f| f.read}.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift
+ @tarfile = File.expand_path(__FILE__).gsub(/\.rbw?$/, "") + ".tar"
end
def extract
File.open(@tarfile, "wb") {|f| f.write @archive}
+
+ self
+ end
+
+ def cleanup
+ @archive = nil
+
+ self
end
end
@@ -351,17 +378,29 @@
end
if JustExtract
- Extract.new.extract
+ Extract.new.extract.cleanup
else
if ToTar
- MakeTar.new.extract
+ MakeTar.new.extract.cleanup
else
- TempSpace.new.extract
+ TempSpace.new.extract.cleanup
- $0 = "./init.rb"
+ $: << newlocation
newlocation do
- load "init.rb"
+ if __FILE__ == $0
+ $0.replace("./init.rb")
+
+ if File.file?("./init.rb")
+ load "./init.rb"
+ else
+ $stderr.puts "%s doesn´t contain an init.rb ." % __FILE__
+ end
+ else
+ if File.file?("./init.rb")
+ load "./init.rb"
+ end
+ end
end
end
end