Sorauta-SVN-AutoCommit
view release on metacpan or search on metacpan
lib/Sorauta/SVN/AutoCommit.pm view on Meta::CPAN
#============================================
# SVNèªåã³ãããã¯ã©ã¹
#
# -------------------------------------------
# ã¢ã¯ã»ãµ
# svn_mode String SVNã®ã³ãããã¢ã¼ã
# commit ... èªåã³ãããã¢ã¼ã
# update ... ã¢ãããã¼ãå®è¡
# work_dir_path String 使¥ãã©ã«ãã¾ã§ã®ãã¹
# ex)c:\projects\hoge_svn_dir
# debug Integer ãããã°ã¢ã¼ã(ã³ããã鲿¢)
# 0 ... ã³ããããã(ããã©ã«ã)
# 1 ... ã¢ãããã¼ãããããã¡ã¤ã«ä¸è¦§ã®åæãªã©ã¯ããããAddãCommitèªä½ã¯ããªã
# thumbnail_width Integer ãµã ãã¤ã«æ¨ªå¹
# ããã©ã«ãã¯$THUMBNAI_WIDTHã®å¤
# thumbnail_height Integer ãµã ãã¤ã«ç¸¦å¹
# ããã©ã«ãã¯$THUMBNAI_HEIGHTã®å¤
#
# changes Integer ãã¼ã«ã«ã®SVNã«æ´æ°ããã£ãã
# 0 ... æ´æ°ãªã(ããã©ã«ã)
# 1 ... æ´æ°ãã
# commit_comment String ã³ãããæã®ã³ã¡ã³ã
# ããã©ã«ãã¯$COMMIT_COMMENTã®å¤
#
#============================================
package Sorauta::SVN::AutoCommit;
use base qw/Class::Accessor::Fast/;
use 5.012003;
use strict;
use warnings;
use utf8;
use CGI::Carp qw/fatalsToBrowser/;
use Data::Dumper;
use SVN::Agent;
use SVN::Agent::Dummy;
use Image::Magick;
use Sorauta::Utility;
our $VERSION = '0.02';
# ãµã ãã¤ã«ã®ç¸¦æ¨ª
our($THUMBNAIL_WIDTH, $THUMBNAIL_HEIGHT) = (160, 90);
# ã³ãããæã®ã³ã¡ã³ã
our $COMMIT_COMMENT = "auto commit from Sorauta::SVN::AutoCommit";
# ã³ããããããå¦ã
our $DEBUG = 0;
__PACKAGE__->mk_accessors(
qw/svn_mode work_dir_path debug thumbnail_width thumbnail_height changes commit_comment/);
#==========================================
# ã³ããããå®è¡
# req:
# res:
#==========================================
sub execute {
my $self = shift;
if (!$self->thumbnail_width) {
$self->thumbnail_width($THUMBNAIL_WIDTH);
}
if (!$self->thumbnail_height) {
$self->thumbnail_height($THUMBNAIL_HEIGHT);
}
if (!$self->commit_comment) {
$self->commit_comment($COMMIT_COMMENT);
}
# must be defined accessors
if (!$self->svn_mode || !$self->work_dir_path) {
die 'must be define accessor svn_mode(auto_commit|update), work_dir_path(/Users/user/Desktop/svn_work_folder)';
}
# set svn agent
my $sa;
if ($self->debug) {
$sa = SVN::Agent::Dummy->load({
path => $self->work_dir_path
});
}
else {
$sa = SVN::Agent->load({
path => $self->work_dir_path
});
}
#print Dumper($sa);
# execute command
if ($self->svn_mode eq 'auto_commit') {
$self->_auto_commit($sa);
}
elsif ($self->svn_mode eq 'update') {
$self->update($sa);
}
lib/Sorauta/SVN/AutoCommit.pm view on Meta::CPAN
else {
# add thumbnail image
if ($unknown_file =~ /^([\w\_\-]+)\\([0-9]+)\\([\w\_\.]+)/) {
my($type, $id_or_jan_code, $file_name) = ($1, $2, $3);
my $abs_dir_path = cat($$self->work_dir_path, 'thumbnail', $type, $id_or_jan_code);
$self->_create_thumbnail_image(
$sa,
cat($self->work_dir_path, $unknown_file),
cat($abs_dir_path, $file_name));
}
}
}
}
#==========================================
# SVNã«ç»é²æ¸ã¿ã ããã¼ã«ã«ã«åå¨ããªãå ´ååé¤ããããã«ã¹ã±ã¸ã¥ã¼ãªã³ã°
# req:
# sa: SVN::Agentã®ã¤ã³ã¹ã¿ã³ã¹
# res:
# result: null
#==========================================
sub _remove_missing_files {
my($self, $sa) = @_;
my @missing_files = @{$sa->missing};
foreach my $missing_file(@missing_files) {
next if is_hidden_file($missing_file);
# ãã¡ã¤ã«ãã¹ãã¨ã¹ã±ã¼ã
$missing_file = _escape($missing_file);
$sa->remove($missing_file);
# ãµã ãã¤ã«ç»åãåé¤
if ($missing_file =~ /^([\w\_\-]+)\\([0-9]+)\\([\w\_\.]+)/) {
my($type, $id_or_jan_code, $file_name) = ($1, $2, $3);
# ãã¡ã¤ã«ãã¹ãã¨ã¹ã±ã¼ã
$file_name = _escape($file_name);
my $dir_path = cat($$self->work_dir_path, 'thumbnail', $type, $id_or_jan_code);
if (-e cat($dir_path, $file_name)) {
$sa->remove(cat($dir_path, $file_name));
}
}
}
}
#==========================================
# ãµã ãã¤ã«ãçæãã
# req:
# sa: SVN::Agentã®ã¤ã³ã¹ã¿ã³ã¹
# original_file_path: å
ãã¡ã¤ã«ã®ãã¹
# thumbnail_file_path: ãµã ãã¤ã«ãã¡ã¤ã«ã®ãã¹
# res:
# result: null
#==========================================
sub _create_thumbnail_image {
my($self, $sa, $original_file_path, $thumbnail_file_path) = @_;
my $image = Image::Magick->new;
# å
ç»åãèªã¿è¾¼ã
print $image->Read(
$original_file_path
);
# ã¿ãã¨ã³æ¯çæå®
print $image->Resize(
geometry => $self->thumbnail_width.'x'.$self->thumbnail_height
);
# ãã¡ã¤ã«ä¿å
print $image->Write(
filename => $thumbnail_file_path,
compression => 'None'
);
# 追å ãã
print $sa->add($thumbnail_file_path);
}
#==========================================
# ãã¡ã¤ã«çãã¨ã¹ã±ã¼ã
# req:
# file_str: ãã¡ã¤ã«æåå
# res:
# file_str: ã¨ã¹ã±ã¼ãå¾ã®ãã¡ã¤ã«æåå
#==========================================
sub _escape {
return quotemeta(shift);
}
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
Sorauta::SVN::AutoCommit - auto recognize new file and deleted file, and commit those files
=head1 SYNOPSIS
use Sorauta::SVN::AutoCommit;
my $SVN_MODE = "auto_commit";
my $SVN_WORK_DIR = "/Users/user/Desktop/svn_dir";
my $DEBUG = 0;
my $ssa = Sorauta::SVN::AutoCommit->new({
svn_mode => $SVN_MODE,
work_dir_path => $SVN_WORK_DIR,
debug => $DEBUG,
});
#print $ssa;
$ssa->execute();
=head1 DESCRIPTION
( run in 2.555 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )