Checkout of Instiki Trunk 1/21/2007.
This commit is contained in:
commit
69b62b6f33
1138 changed files with 139586 additions and 0 deletions
69
vendor/plugins/rubyzip-0.9.1/samples/example.rb
vendored
Executable file
69
vendor/plugins/rubyzip-0.9.1/samples/example.rb
vendored
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
system("zip example.zip example.rb gtkRubyzip.rb")
|
||||
|
||||
require 'zip/zip'
|
||||
|
||||
####### Using ZipInputStream alone: #######
|
||||
|
||||
Zip::ZipInputStream.open("example.zip") {
|
||||
|zis|
|
||||
entry = zis.get_next_entry
|
||||
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
||||
puts "'#{zis.gets.chomp}'"
|
||||
entry = zis.get_next_entry
|
||||
print "First line of '#{entry.name} (#{entry.size} bytes): "
|
||||
puts "'#{zis.gets.chomp}'"
|
||||
}
|
||||
|
||||
|
||||
####### Using ZipFile to read the directory of a zip file: #######
|
||||
|
||||
zf = Zip::ZipFile.new("example.zip")
|
||||
zf.each_with_index {
|
||||
|entry, index|
|
||||
|
||||
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
|
||||
# use zf.get_input_stream(entry) to get a ZipInputStream for the entry
|
||||
# entry can be the ZipEntry object or any object which has a to_s method that
|
||||
# returns the name of the entry.
|
||||
}
|
||||
|
||||
|
||||
####### Using ZipOutputStream to write a zip file: #######
|
||||
|
||||
Zip::ZipOutputStream.open("exampleout.zip") {
|
||||
|zos|
|
||||
zos.put_next_entry("the first little entry")
|
||||
zos.puts "Hello hello hello hello hello hello hello hello hello"
|
||||
|
||||
zos.put_next_entry("the second little entry")
|
||||
zos.puts "Hello again"
|
||||
|
||||
# Use rubyzip or your zip client of choice to verify
|
||||
# the contents of exampleout.zip
|
||||
}
|
||||
|
||||
####### Using ZipFile to change a zip file: #######
|
||||
|
||||
Zip::ZipFile.open("exampleout.zip") {
|
||||
|zf|
|
||||
zf.add("thisFile.rb", "example.rb")
|
||||
zf.rename("thisFile.rb", "ILikeThisName.rb")
|
||||
zf.add("Again", "example.rb")
|
||||
}
|
||||
|
||||
# Lets check
|
||||
Zip::ZipFile.open("exampleout.zip") {
|
||||
|zf|
|
||||
puts "Changed zip file contains: #{zf.entries.join(', ')}"
|
||||
zf.remove("Again")
|
||||
puts "Without 'Again': #{zf.entries.join(', ')}"
|
||||
}
|
||||
|
||||
# For other examples, look at zip.rb and ziptest.rb
|
||||
|
||||
# Copyright (C) 2002 Thomas Sondergaard
|
||||
# rubyzip is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the ruby license.
|
34
vendor/plugins/rubyzip-0.9.1/samples/example_filesystem.rb
vendored
Executable file
34
vendor/plugins/rubyzip-0.9.1/samples/example_filesystem.rb
vendored
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'zip/zipfilesystem'
|
||||
require 'ftools'
|
||||
|
||||
EXAMPLE_ZIP = "filesystem.zip"
|
||||
|
||||
File.delete(EXAMPLE_ZIP) if File.exists?(EXAMPLE_ZIP)
|
||||
|
||||
Zip::ZipFile.open(EXAMPLE_ZIP, Zip::ZipFile::CREATE) {
|
||||
|zf|
|
||||
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
||||
zf.dir.mkdir("dir1")
|
||||
zf.dir.chdir("dir1")
|
||||
zf.file.open("file1.txt", "w") { |os| os.write "second file1.txt" }
|
||||
puts zf.file.read("file1.txt")
|
||||
puts zf.file.read("../file1.txt")
|
||||
zf.dir.chdir("..")
|
||||
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
||||
puts "Entries: #{zf.entries.join(', ')}"
|
||||
}
|
||||
|
||||
Zip::ZipFile.open(EXAMPLE_ZIP) {
|
||||
|zf|
|
||||
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
||||
}
|
||||
|
||||
# For other examples, look at zip.rb and ziptest.rb
|
||||
|
||||
# Copyright (C) 2003 Thomas Sondergaard
|
||||
# rubyzip is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the ruby license.
|
86
vendor/plugins/rubyzip-0.9.1/samples/gtkRubyzip.rb
vendored
Executable file
86
vendor/plugins/rubyzip-0.9.1/samples/gtkRubyzip.rb
vendored
Executable file
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
$VERBOSE = true
|
||||
|
||||
require 'gtk'
|
||||
require 'zip/zip'
|
||||
|
||||
class MainApp < Gtk::Window
|
||||
def initialize
|
||||
super()
|
||||
set_usize(400, 256)
|
||||
set_title("rubyzip")
|
||||
signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
|
||||
|
||||
box = Gtk::VBox.new(false, 0)
|
||||
add(box)
|
||||
|
||||
@zipfile = nil
|
||||
@buttonPanel = ButtonPanel.new
|
||||
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
show_file_selector
|
||||
}
|
||||
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
puts "Not implemented!"
|
||||
}
|
||||
box.pack_start(@buttonPanel, false, false, 0)
|
||||
|
||||
sw = Gtk::ScrolledWindow.new
|
||||
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
|
||||
box.pack_start(sw, true, true, 0)
|
||||
|
||||
@clist = Gtk::CList.new(["Name", "Size", "Compression"])
|
||||
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
||||
@clist.set_column_width(0, 120)
|
||||
@clist.set_column_width(1, 120)
|
||||
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
|
||||
|w, row, column, event|
|
||||
@selected_row = row
|
||||
}
|
||||
sw.add(@clist)
|
||||
end
|
||||
|
||||
class ButtonPanel < Gtk::HButtonBox
|
||||
attr_reader :openButton, :extractButton
|
||||
def initialize
|
||||
super
|
||||
set_layout(Gtk::BUTTONBOX_START)
|
||||
set_spacing(0)
|
||||
@openButton = Gtk::Button.new("Open archive")
|
||||
@extractButton = Gtk::Button.new("Extract entry")
|
||||
pack_start(@openButton)
|
||||
pack_start(@extractButton)
|
||||
end
|
||||
end
|
||||
|
||||
def show_file_selector
|
||||
@fileSelector = Gtk::FileSelection.new("Open zip file")
|
||||
@fileSelector.show
|
||||
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
open_zip(@fileSelector.filename)
|
||||
@fileSelector.destroy
|
||||
}
|
||||
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
@fileSelector.destroy
|
||||
}
|
||||
end
|
||||
|
||||
def open_zip(filename)
|
||||
@zipfile = Zip::ZipFile.open(filename)
|
||||
@clist.clear
|
||||
@zipfile.each {
|
||||
|entry|
|
||||
@clist.append([ entry.name,
|
||||
entry.size.to_s,
|
||||
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
mainApp = MainApp.new()
|
||||
|
||||
mainApp.show_all
|
||||
|
||||
Gtk.main
|
101
vendor/plugins/rubyzip-0.9.1/samples/qtzip.rb
vendored
Executable file
101
vendor/plugins/rubyzip-0.9.1/samples/qtzip.rb
vendored
Executable file
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$VERBOSE=true
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'Qt'
|
||||
system('rbuic -o zipdialogui.rb zipdialogui.ui')
|
||||
require 'zipdialogui.rb'
|
||||
require 'zip/zip'
|
||||
|
||||
|
||||
|
||||
a = Qt::Application.new(ARGV)
|
||||
|
||||
class ZipDialog < ZipDialogUI
|
||||
|
||||
|
||||
def initialize()
|
||||
super()
|
||||
connect(child('add_button'), SIGNAL('clicked()'),
|
||||
self, SLOT('add_files()'))
|
||||
connect(child('extract_button'), SIGNAL('clicked()'),
|
||||
self, SLOT('extract_files()'))
|
||||
end
|
||||
|
||||
def zipfile(&proc)
|
||||
Zip::ZipFile.open(@zip_filename, &proc)
|
||||
end
|
||||
|
||||
def each(&proc)
|
||||
Zip::ZipFile.foreach(@zip_filename, &proc)
|
||||
end
|
||||
|
||||
def refresh()
|
||||
lv = child("entry_list_view")
|
||||
lv.clear
|
||||
each {
|
||||
|e|
|
||||
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def load(zipfile)
|
||||
@zip_filename = zipfile
|
||||
refresh
|
||||
end
|
||||
|
||||
def add_files
|
||||
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
|
||||
zipfile {
|
||||
|zf|
|
||||
l.each {
|
||||
|path|
|
||||
zf.add(File.basename(path), path)
|
||||
}
|
||||
}
|
||||
refresh
|
||||
end
|
||||
|
||||
def extract_files
|
||||
selected_items = []
|
||||
unselected_items = []
|
||||
lv_item = entry_list_view.first_child
|
||||
while (lv_item)
|
||||
if entry_list_view.is_selected(lv_item)
|
||||
selected_items << lv_item.text(0)
|
||||
else
|
||||
unselected_items << lv_item.text(0)
|
||||
end
|
||||
lv_item = lv_item.next_sibling
|
||||
end
|
||||
puts "selected_items.size = #{selected_items.size}"
|
||||
puts "unselected_items.size = #{unselected_items.size}"
|
||||
items = selected_items.size > 0 ? selected_items : unselected_items
|
||||
puts "items.size = #{items.size}"
|
||||
|
||||
d = Qt::FileDialog.get_existing_directory(nil, self)
|
||||
if (!d)
|
||||
puts "No directory chosen"
|
||||
else
|
||||
zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
slots 'add_files()', 'extract_files()'
|
||||
end
|
||||
|
||||
if !ARGV[0]
|
||||
puts "usage: #{$0} zipname"
|
||||
exit
|
||||
end
|
||||
|
||||
zd = ZipDialog.new
|
||||
zd.load(ARGV[0])
|
||||
|
||||
a.mainWidget = zd
|
||||
zd.show()
|
||||
a.exec()
|
13
vendor/plugins/rubyzip-0.9.1/samples/write_simple.rb
vendored
Executable file
13
vendor/plugins/rubyzip-0.9.1/samples/write_simple.rb
vendored
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'zip/zip'
|
||||
|
||||
include Zip
|
||||
|
||||
ZipOutputStream.open('simple.zip') {
|
||||
|zos|
|
||||
ze = zos.put_next_entry 'entry.txt'
|
||||
zos.puts "Hello world"
|
||||
}
|
74
vendor/plugins/rubyzip-0.9.1/samples/zipfind.rb
vendored
Executable file
74
vendor/plugins/rubyzip-0.9.1/samples/zipfind.rb
vendored
Executable file
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$VERBOSE = true
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'zip/zip'
|
||||
require 'find'
|
||||
|
||||
module Zip
|
||||
module ZipFind
|
||||
def self.find(path, zipFilePattern = /\.zip$/i)
|
||||
Find.find(path) {
|
||||
|fileName|
|
||||
yield(fileName)
|
||||
if zipFilePattern.match(fileName) && File.file?(fileName)
|
||||
begin
|
||||
Zip::ZipFile.foreach(fileName) {
|
||||
|zipEntry|
|
||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
||||
}
|
||||
rescue Errno::EACCES => ex
|
||||
puts ex
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
||||
self.find(path, zipFilePattern) {
|
||||
|fileName|
|
||||
yield(fileName) if fileNamePattern.match(fileName)
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
module ZipFindConsoleRunner
|
||||
|
||||
PATH_ARG_INDEX = 0;
|
||||
FILENAME_PATTERN_ARG_INDEX = 1;
|
||||
ZIPFILE_PATTERN_ARG_INDEX = 2;
|
||||
|
||||
def self.run(args)
|
||||
check_args(args)
|
||||
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
||||
args[FILENAME_PATTERN_ARG_INDEX],
|
||||
args[ZIPFILE_PATTERN_ARG_INDEX]) {
|
||||
|fileName|
|
||||
report_entry_found fileName
|
||||
}
|
||||
end
|
||||
|
||||
def self.check_args(args)
|
||||
if (args.size != 3)
|
||||
usage
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
def self.usage
|
||||
puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
|
||||
end
|
||||
|
||||
def self.report_entry_found(fileName)
|
||||
puts fileName
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ZipFindConsoleRunner.run(ARGV)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue