java/ruby unzip

http://www.java2s.com/Tutorial/Java/0180__File/UnzipusingtheZipInputStream.htm

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class MainClass {

public static void main(String[] args) throws IOException {

for (int i = 0; i < args.length; i++) { FileInputStream fin = new FileInputStream(args[i]); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } zin.close(); } } } http://www.kodejava.org/examples/334.html package org.kodejava.example.util.zip; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; public class UnzipDemo { public static void main(String[] args) { String zipname = "data.zip"; try { FileInputStream fis = new FileInputStream(zipname); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; // // Read each entry from the ZipInputStream until no more entry found // indicated by a null return value of the getNextEntry() method. // while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); int size; byte[] buffer = new byte[2048]; FileOutputStream fos = new FileOutputStream(entry.getName()); BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } zis.close(); fis.close(); } catch (IOException e) { e.printStackTrace(); } } } http://www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-rubyzip/ require 'rubygems' require 'zip/zip' def unzip_file (file, destination) Zip::ZipFile.open(file) { |zip_file| zip_file.each { |f| f_path=File.join(destination, f.name) FileUtils.mkdir_p(File.dirname(f_path)) zip_file.extract(f, f_path) unless File.exist?(f_path) } } http://stackoverflow.com/questions/856891/unzip-zip-tar-tag-gz-files-with-ruby http://www.anyang-window.com.cn/tag/ava-zip/page/3/ http://www.iteye.com/topic/626705

Redmine 1.x升级到2.0.3

本来想按步骤再再写写Redmine的这个升级故事的1.x到2.0.3,还特别找了以下文章内容,以期参考:

Redmine v1.4.x 升級到 Redmine v2.0.x 的升級步驟

基本更新步驟:
切換到安裝目錄:
cd /home/apps
備份舊有的資料:
mv redmine redmine_bak
取得最新的程式:
/usr/local/bin/svn co http://redmine.rubyforge.org/svn/branches/2.0-stable redmine
複製資料庫設定、上傳檔案、Theme:
cp /home/apps/redmine_bak/config/database.yml /home/apps/redmine/config/
cp -ai /home/apps/redmine_bak/files/* /home/apps/redmine/files/
cp -ai /home/apps/redmine_bak/public/themes/* /home/apps/redmine/public/themes/
Plugins:先不要安裝與更新,等下面步驟完成後再來處理。
切換到 redmine 根目錄中:
cd redmine
更新 RubyGem:
gem update –system
檢查並更新 gems:
bundle install –without development test postgresql
Generate a session store secret:
rake generate_secret_token
更新 Database Schema:
rake db:migrate RAILS_ENV=production
更新 Plugins 的 Database Schema:
rake redmine:plugins:migrate RAILS_ENV=production
清除 cache:
rake tmp:cache:clear
rake tmp:sessions:clear
啟動 WEBrick web server 來進行測試:
ruby script/rails server webrick -e production
更新 Plugins:¶
Redmine V2.0.x 的 Plugins 目錄從 Redmine V1.x 的 /vendor/plugins 移到 /plugins。
建議的更新方式是一個一個慢慢來,更新完成再進行下一個。
更新流程:(安裝一個 plugin 後,執行 3-5 步驟,確認沒有錯誤後,再安裝下一個 plugin)
切換到 redmine 根目錄中:
cd redmine
檢查並更新 gems (非必要,除非有提醒再執行):
bundle install –without development test postgresql
安裝一個 Plugin:
更新 Database Schema:
rake db:migrate RAILS_ENV=production
更新 Plugins 的 Database Schema:
rake redmine:plugins:migrate RAILS_ENV=production
啟動 WEBrick web server 來進行測試:
ruby script/rails server webrick -e production

如何将Turnkey Redmine 虚拟机从Redmine 1.0.5 升级到1.2

#0
/etc/init.d/apache2 stop
#1
cd /var/www
#2
mv railsapp railsappOLD
#3
svn co http://redmine.rubyforge.org/svn/branches/1.2-stable railsapp
#4
cp ./railsappOLD/config/database.yml ./railsapp/config/database.yml
#5
cp ./railsappOLD/config/email.yml ./railsapp/config/email.yml
#6
cp -r ./railsappOLD/files ./railsapp/filesrak
#7
sudo chown -R root:www-data /var/www/railsapp
#8
cd /var/www/railsapp
#9 (inside the /var/www/railsapp folder)
sudo chown -R www-data:www-data files log tmp
#10 (this command takes a little time – be patient)
gem install rails -v=2.3.11
#11
gem install rack
#12
gem install rack -v=1.1.1
#13 (inside the /var/www/railsapp folder)
rake generate_session_store
#14 (inside the /var/www/railsapp folder)
rake db:migrate RAILS_ENV=production
#15 (inside the /var/www/railsapp folder)
sudo chown -R www-data:www-data files log tmp public/plugin_assets
#16 (inside the /var/www/railsapp folder)
rake db:migrate:upgrade_plugin_migrations RAILS_ENV=production
#17 (inside the /var/www/railsapp folder)
rake db:migrate_plugins RAILS_ENV=production
#18
sudo chmod -R 755 files log/ tmp/ public/plugin_assets
#19 (inside the /var/www/railsapp folder)
rake tmp:cache:clear
#20 (inside the /var/www/railsapp folder)
rake tmp:sessions:clear
#21
/etc/init.d/apache2 start

后来发现如果按说明基本没有什么问题。以下一些内容算是一些参照索引吧:

1. 需要bundler:gem install bundler

2. 安装 Redmine 1.4 ,用Ubuntu Server 11.10
3. How to Install Redmine 2.0.1 on Ubuntu 12.04

# tasksel install lamp-server

# apt-get install ruby-full libmysqlclient-dev libmagickwand-dev libapache2-mod-passenger

# wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz
# tar xzvf rubygems-1.8.24.tgz
# cd rubygems-1.8.24
# ruby stup.rb

# ln -s /usr/bin/gem1.8 /usr/bin/gem

# gem install bundler

# wget http://files.rubyforge.vm.bytemark.co.uk/redmine/redmine-2.0.1.tar.gz
# tar xzvf redmine-2.0.1.tar.gz
# mv redmine-2.0.1.tar.gz redmine
# mv redmine /var/www/redmine
# cd /var/www/redmine

# bundle install –without development test postgresql sqlite

# mysql -u root -p
create database redmine character set utf8;
create user ‘redmine’@’localhost’ identified by ‘my_password’;
grant all privileges on redmine.* to ‘redmine’@’localhost’;

# vi config/database.yml
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: password

# rake generate_secret_token

# RAILS_ENV=production rake db:migrate

# RAILS_ENV=production rake redmine:load_default_data

# vi /etc/apache2/mods-available/passenger.conf
PassengerDefaultUser www-data

# vi /etc/apache2/sites-available/default
DocumentRoot /var/www/redmine/public

RailsBaseURI /redmine

# a2enmod passenger

# mkdir redmine/public/plugin_assets
# chown -R www-data:www-data redmine/
# chmod -R 755 redmine/
# chmod -R 777 redmine/public/plugin_assets
# chmod -R 777 redmine/files

# service apache2 restart

4. 其实还需要安装安装以下包:

libmysqlclient-dev

libmagickcore-dev

libmagickwand-dev

postgresql-server-dev-8.4

libsqlite3-dev

5. 运行时需要:

mkdir -p ./tmp/pids
touch log/produciton.log
chmod 0666 log/production.log
mkdir -p public/plugin_assets

6. 重要的参考:Upgrading

generate_secret_token

http://www.redmine.org/boards/2/topics/30624
Solved 🙂 problem is passenger module .

1) gem install passenger
2) passenger-install-apache2-module
3).1 vi /etc/apache2/mods_enabled/passenger.load
#change module path to :
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
.2 vi /etc/apache2/mods_enabled/passenger.conf
#change conf to

PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.12
PassengerRuby /usr/bin/ruby1.8
configuration options provided by passenger-install-command. module path may change by time becouse of version

>>>>
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.15/ext/apache2/mod_passenger.so << 这行是要加在passenger.load里的,否则只会列出当前目录文件的列表

PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.15
PassengerRuby /usr/bin/ruby1.8

7. 其它参考:

http://antontw.blogspot.com/2008/11/linux-svn-http-mysql-auth.html
http://www.debuntu.org/2006/05/20/54-how-to-subversion-svn-with-apache2-and-dav
http://www.linuxidc.com/Linux/2012-07/66234.htm

http://code.google.com/p/mod-auth-external/wiki/Installation

8. 原来创建的视图有些小问题了,主要是现在这样的内容需要自己生成或者自己去个性dav_svn配置。

CREATE VIEW users_auth_external AS SELECT u.login AS username, u.hashed_password AS passwd, GROUP_CONCAT(CONCAT(CONCAT(p.identifier, '_'), r.name)) AS groups FROM `members` m INNER JOIN users u ON m.user_id = u.id INNER JOIN projects p ON m.project_id = p.id INNER JOIN member_roles mr ON mr.member_id = m.id INNER JOIN roles r ON mr.role_id = r.id WHERE u.status = 1 GROUP BY username;

9. 还是参考:

http://www.redmine.org/projects/redmine/wiki/Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl 注:新的验证方法用这个配置还是方便,改mysql_auth的源码也是一个方案

http://serverfault.com/questions/355503/svn-authentication-over-apache-dav-and-redmine-not-work

http://www.redmine.org/boards/2/topics/3597?r=3827

http://www.redmine.org/projects/redmine/wiki/Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl?version=24#Testing-the-configuration

http://www.redmine.org/boards/2/topics/24386?r=25722#message-25722
http://www.redmine.org/boards/2/topics/24386?r=24411#message-24411
http://www.redmine.org/issues/7410
http://redmine.rubyforge.org/svn/trunk/extra/svn/Redmine.pm
http://code.google.com/p/redminerepositorycontrol/
http://www.redmine.org/issues/5236
http://www.webdotdev.com/nvd/content/view/209/
http://dev.mysql.com/doc//refman/5.5/en/encryption-functions.html
http://www.redmine.org/boards/2/topics/6387
http://www.linuxquestions.org/questions/linux-server-73/apache-2-2-authtype-digest-pam-module-mysql-configuration-and-guidance-needed-789958/

10. 重要的插件:
https://github.com/ciaranj/redmine_burndown
http://www.redminebacklogs.net/en/installation.html#
https://github.com/backlogs/redmine_backlogs

11. 还有几个库会在安装插件的时候用到,因为时间原因,以上资料用来升级Redmine是足够了,插件因为时间关系暂时是没好。

libxslt

cucumber-rails, gherkin

12.

Redmine 显示“Updated by {{author}} {{age}} ago”的问题

升级了一下的服务器,终于不再用PC代替了。Redmine也升了个级,目前的版本是1.0.5。不过出现了点小问题,原来好用的最近的新闻里出现的是
Updated by {{author}} {{age}} ago

History list shows “Updated by {{author}} {{age}} ago”,提示i18n只支持到0.4.2,而系统里是0.6.0,把高版本删除了就好了。

ShowOff安装测试

ShowOff是什么?showoff是一个用Sinatra开发的基于配置的简报系统。类似于Keynote。详细内容看它的主站吧:https://github.com/schacon/showoff

1.

sudo apt-get install libxml2-dev libxslt-dev

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libxslt1-dev' instead of 'libxslt-dev'
The following NEW packages will be installed:
  libxml2-dev libxslt1-dev
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 1,412 kB of archives.
After this operation, 5,583 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu/ natty-updates/main libxml2-dev amd64 2.7.8.dfsg-2ubuntu0.1 [835 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ natty/main libxslt1-dev amd64 1.1.26-6build1 [577 kB]
Fetched 1,412 kB in 4s (299 kB/s)     
Selecting previously deselected package libxml2-dev.
(Reading database ... 249315 files and directories currently installed.)
Unpacking libxml2-dev (from .../libxml2-dev_2.7.8.dfsg-2ubuntu0.1_amd64.deb) ...
Selecting previously deselected package libxslt1-dev.
Unpacking libxslt1-dev (from .../libxslt1-dev_1.1.26-6build1_amd64.deb) ...
Processing triggers for man-db ...
Processing triggers for doc-base ...
Processing 1 added doc-base file(s)...
Registering documents with scrollkeeper...
Setting up libxml2-dev (2.7.8.dfsg-2ubuntu0.1) ...
Setting up libxslt1-dev (1.1.26-6build1) ...

2.

sudo gem install showoff

Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed rack-1.3.2
Successfully installed tilt-1.3.2
Successfully installed sinatra-1.2.6
Successfully installed bluecloth-2.1.0
Successfully installed nokogiri-1.5.0
Successfully installed json-1.5.3
Successfully installed gli-1.3.2
Successfully installed showoff-0.4.2
8 gems installed
Installing ri documentation for rack-1.3.2...
Installing ri documentation for tilt-1.3.2...
Installing ri documentation for sinatra-1.2.6...
Installing ri documentation for bluecloth-2.1.0...
Installing ri documentation for nokogiri-1.5.0...

No definition for get_options

No definition for set_options

No definition for parse_memory

No definition for parse_file

No definition for parse_with
Installing ri documentation for json-1.5.3...
Installing ri documentation for gli-1.3.2...
Installing ri documentation for showoff-0.4.2...
Installing RDoc documentation for rack-1.3.2...
Installing RDoc documentation for tilt-1.3.2...
Installing RDoc documentation for sinatra-1.2.6...
Installing RDoc documentation for bluecloth-2.1.0...
Installing RDoc documentation for nokogiri-1.5.0...

No definition for get_options

No definition for set_options

No definition for parse_memory

No definition for parse_file

No definition for parse_with
Installing RDoc documentation for json-1.5.3...
Installing RDoc documentation for gli-1.3.2...
Installing RDoc documentation for showoff-0.4.2...

3. 安装后缺省目录/var/lib/gems/1.8/bin

4. 创建(信赖RMagick,需安装libmagickwand-dev,再sudo gem install rmagick pdfkit)

/var/lib/gems/1.8/bin/showoff create presentname

5. 创建后进入presentname目录

/var/lib/gems/1.8/bin/showoff serve

image sizing disabled - install rmagick
pdf generation disabled - install pdfkit
== Sinatra/1.2.6 has taken the stage on 9090 for development with backup from WEBrick
[2011-08-17 04:39:17] INFO  WEBrick 1.3.1
[2011-08-17 04:39:17] INFO  ruby 1.8.7 (2010-08-16) [x86_64-linux]
[2011-08-17 04:39:24] INFO  WEBrick::HTTPServer#start: pid=13746 port=9090

参考文章:
1. Subjects covered include Ruby, ERROR, Libxml, Nokogiri, and Iconv.

2.How to install rmagick on Ubuntu 10.04?

Code Review for Redmine

相关文件要复制到指定目录

/usr/share/redmine/vendor/plugins/redmine_code_review$ sudo cp -R assets/ /var/www/pm/plugin_assets/redmine_code_review/

在系统管理里设置角色和权限中相关角色的权限。

翻译的内容需要放到
/usr/share/redmine/config/locales/zh.yml 文件中。在研究是否可以放到独立文件中。

http://www.r-labs.org/projects/r-labs/wiki/Code_Review

胡子手册:mustache — Mustache processor

这是部关于“胡子”的手册。传说中应用于PHP, Java, Ruby, Python, JavaScript, erLang等牛掰事物上的模板。至于这么介于牛A和牛C之间的事务为什么叫做胡子,据某不大健康的思路大致如下:
1. 可能如果以男人为模板,胡子大概是比较重要的部分,虽然现代人的社会大部分男人的胡子都脱不了被刮除的风险。
2. 如果有了胡子,则可以更为男人一点。如果使用了mustache模板,则上通五湖,下达四海,各类前端工程师可以游刃于纯美之间,无需考虑各种开发的小小刀片之差异。
3. 大棵一点的是有了胡子,至少么还象个男人,谁还在于您阳货之不具耶?
4. 更恶的一点:胡子么,既名之曰mustache,这痛么必然是有一点点的,反正痛过了就没事了:D。
5. 胡子挡住了你的嘴,所以你说的内容胡子上是看不出来的,这样用户真不会关注你后端的实现办法了。:)
以上胡扯,如有愿意对号入座者,自行分辨,或者可以自行摸一下,是不是硬硬的还在:D。若是觉得一个mustache就可以解决您公司复杂的python/Java/RoR/PHP之类混乱开发方式引起的使用了django/grails/rhtml/smarty之类模板的混乱,窃以为切切不可。
下面开始翻译mustache模板手册:

MUSTACHE(1) MUSTACHE MANUAL

NAME/名称
mustache — Mustache processor

SYNOPSIS/摘要
mustache
mustache –compile
mustache –tokens
DESCRIPTION/描述
Mustache is a logic-less templating system for HTML, config files, anything.
Mustache是一个用于HTML/配置文件或任何一种文档的无逻辑模板系统。
The mustache command processes a Mustache template preceded by YAML frontmatter from standard input and prints one or more documents to standard output.
mustache命令会使用由标准输入预提供的YAML数据,然后打印一个或者多个文档到标准输出。
YAML frontmatter beings with — on a single line, followed by YAML, ending with another — on a single line, e.g./该YAML的输入格式由一行—开始,跟着是YAML内容,再由另一行—结束。例如

---
names: [ {name: chris}, {name: mark}, {name: scott} ]
---

If you are unfamiliar with YAML, it is a superset of JSON. Valid JSON should work fine.如果你对YAML不熟悉,它是JSON的超集。合法的JSON也可以工作得很好。

After the frontmatter should come any valid Mustache template. See mustache(5) for an overview of Mustache templates./在数据之后跟着合法的Mustache模板。参见mustache(5)来获得Mustache模板的概况。

For example/例如:

{{#names}}
Hi {{name}}!
{{/names}}

Now let’s combine them/现在让我们来整合它们.

$ cat data.yml


names: [ {name: chris}, {name: mark}, {name: scott} ]

$ cat template.mustache

{{#names}}
Hi {{name}}!
{{/names}}

$ cat data.yml template.mustache | mustache

Hi chris!
Hi mark!
Hi scott!

If you provide multiple YAML documents (as delimited by —), your template will be rendered multiple times. Like a mail merge./如果你提供多个YAML文档(用—来分隔),模板会渲染多次。就象邮件合并。

For example/例如:

$ cat data.yml


name: chris

name: mark

name: scott

$ cat template.mustache

Hi {{name}}!

$ cat data.yml template.mustache | mustache

Hi chris!
Hi mark!
Hi scott!
OPTIONS/选项
By default mustache will try to render a Mustache template using the YAML frontmatter you provide. It can do a few other things, however.缺省地mustache命令会试图用你提供的YAML格式数据来渲染一个Mustache模板。当然,它还可以做一些其它的事情。

-c, –compile
Print the compiled Ruby version of a given template. This is the code that is actually used when rendering a template into a string. Useful for debugging but only if you are familiar with Mustache’s internals.
打印给定模板的编译后Ruby版本代码。这个代码是将模板渲染成字符串时真实使用的代码。这个代码对于高度来说是非常有用的,但是仅适用于你对Mustache内部非常熟悉的情况。

-t, –tokens
Print the tokenized form of a given Mustache template. This can be used to understand how Mustache parses a template. The tokens are handed to a generator which compiles them into a Ruby string. Syntax errors and confused tags, therefor, can probably be identified by examining the tokens produced.
打印指定Mustache模板标记后样式。这个可以用来理解Mustache是如何解析一个模板的。这些标记由一个产生器来处理,这个产生器将它们编译到一个Ruby字符串中。语法错误和令人糊涂的标签,就可能通过检测标识的产生来被认知。

INSTALLATION/安装
If you have RubyGems installed/如果你已经安装了RubyGems:

gem install mustache

EXAMPLES/例子

$ mustache data.yml template.mustache
$ cat data.yml | mustache - template.mustache
$ mustache -c template.mustache
$ cat < ---
name: Bob
age: 30
---
data

COPYRIGHT/版权
Mustache is Copyright (C) 2009 Chris Wanstrath

Original CTemplate by Google(源自Google CTemplate)

SEE ALSO/参见
mustache(5), mustache(7), gem(1), http://mustache.github.com/

http://mustache.github.com/mustache.1.html

注:
在Ubuntu下,如果没有安装ruby,请安装。如:

$ sudo apt-get install ruby rubygems
$ sudo gem install mustache

之后,它是安装到了/var/lib/gems/1.8/bin/。调用/var/lib/gems/1.8/bin/mastache或者加入路径吧。

本文的内容感谢@shellexy的帮助。