[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rake rules question

Its Me

3/16/2006 11:41:00 PM

I am using RMagick to do multi-stage processing of some images.

Can I have two different rules to process .PNG files in two different
directories?

rule stage_0/*.png => source/*.png do |t|
make_0 t.source, t.name
end

rule stage_1/*.png => stage_0/*.png do |t|
make_1 t.source, t.name
end


I can't seem to get this to work, and don't know if it is supposed to.

Thanks.




9 Answers

Jim Weirich

3/17/2006 3:18:00 AM

0

itsme213 wrote:
> I am using RMagick to do multi-stage processing of some images.
>
> Can I have two different rules to process .PNG files in two different
> directories?
>
> rule stage_0/*.png => source/*.png do |t|
> make_0 t.source, t.name
> end
>
> rule stage_1/*.png => stage_0/*.png do |t|
> make_1 t.source, t.name
> end
>
>
> I can't seem to get this to work, and don't know if it is supposed to.

It will work. The attached Rakefile will demonstrate the principle.
Basically, if you want your rules to trigger on something other than
simple file extenstions, you need to write them in this format:

rule(REGEX => LAMBDA_TRANSFORMER) do
ACTIONS
end

The REGEX should match the thing your are trying to build. The
LAMBDA_TRANSFORMER is just a lambda expression with a single input that
transforms the name of the target (i.e. whatever was matched by the
REGEX) into the target of the task (i.e. the thing the rule is to
produce).

For example, your regex might be %r{stage1/.*\.png$} to match a file
that should be in stage 1. Your lambda could be

lambda { |fn| fn.sub(/^stage1/, 'source') }

Make appropriate changes for the stage1 to stage2 work.

If you find rules confusing, an alternative is dynamically generate the
tasks in a list. For example:

SRC_FILES = FileList['source/*.png']

SRC_FILES.each do |fn|
stage1 = fn.sub(/^source/, 'stage1')
stage2 = fn.sub(/^source/, 'stage2')
task stage1 => stage2 do
do_stage_one_transform(fn, stage1)
end
task stage2 => stage1 do
do_stage_two_transform(stage2, stage1)
end
end

In many ways this is easier than rules and just as flexible.

Anyways, here is the example Rakefile using rules:

----------------------------------------------------------------
#!/usr/bin/env ruby

require 'rake/clean'

CLOBBER.include 'stage1', 'stage2'

task :default => %w(stage1 stage2 stage2/a.png)

directory 'stage1'
directory 'stage2'
----------------------------------------------------------------

rule(%r{^stage1/.*\.png$} => lambda { |fn| fn.sub(/^stage1/, 'source')
}) do |t|
File.open(t.source) do |ins|
File.open(t.name, "w") do |outs|
outs.write ins.read
outs.puts "Added to stage one"
end
end
end

rule(%r{^stage2/.*\.png$} => lambda { |fn| fn.sub(/^stage2/, 'stage1')
}) do |t|
File.open(t.source) do |ins|
File.open(t.name, "w") do |outs|
outs.write ins.read
outs.puts "Added to stage two"
end
end
end
----------------------------------------------------------------

# Other tasks --------------------------------------------------------

task :init => :clobber do
File.open("source/a.png", "w") do |outs|
outs.puts "A PNG FILE"
end
end

task :see do
puts "-- Contents of source/a.png -------------------------------"
puts File.read("source/a.png")
puts "-- Contents of stage2/a.png -------------------------------"
puts File.read("stage1/a.png")
puts "-- Contents of stage2/a.png -------------------------------"
puts File.read("stage2/a.png")
end
----------------------------------------------------------------

--
-- Jim Weirich

--
Posted via http://www.ruby-....


Jim Weirich

3/17/2006 3:23:00 AM

0

Jim Weirich wrote:
[... Rakefile example elided ...]

There are some extra lines of dashes in that Rakefile example. I swear
they weren't there when I pressed send. Oh well, hopefully that will
get you started.

--
-- Jim Weirich


--
Posted via http://www.ruby-....


Its Me

3/17/2006 6:03:00 PM

0

Thanks, Jim!

"Jim Weirich" <jim@weirichhouse.org> wrote

> Basically, if you want your rules to trigger on something other than
> simple file extenstions, you need to write them in this format:
>
> rule(REGEX => LAMBDA_TRANSFORMER) do
> ACTIONS
> end

Lovely. I will try this out.

> If you find rules confusing, an alternative is dynamically generate the
> tasks in a list. For example:
>
> SRC_FILES = FileList['source/*.png']
>
> SRC_FILES.each do |fn|
> stage1 = fn.sub(/^source/, 'stage1')
> stage2 = fn.sub(/^source/, 'stage2')
> task stage1 => stage2 do
> do_stage_one_transform(fn, stage1)
> end
> task stage2 => stage1 do
> do_stage_two_transform(stage2, stage1)
> end
> end
>
> In many ways this is easier than rules and just as flexible.
>
> Anyways, here is the example Rakefile using rules:
>
> ----------------------------------------------------------------
> #!/usr/bin/env ruby
>
> require 'rake/clean'
>
> CLOBBER.include 'stage1', 'stage2'
>
> task :default => %w(stage1 stage2 stage2/a.png)
>
> directory 'stage1'
> directory 'stage2'
> ----------------------------------------------------------------
>
> rule(%r{^stage1/.*\.png$} => lambda { |fn| fn.sub(/^stage1/, 'source')
> }) do |t|
> File.open(t.source) do |ins|
> File.open(t.name, "w") do |outs|
> outs.write ins.read
> outs.puts "Added to stage one"
> end
> end
> end
>
> rule(%r{^stage2/.*\.png$} => lambda { |fn| fn.sub(/^stage2/, 'stage1')
> }) do |t|
> File.open(t.source) do |ins|
> File.open(t.name, "w") do |outs|
> outs.write ins.read
> outs.puts "Added to stage two"
> end
> end
> end
> ----------------------------------------------------------------
>
> # Other tasks --------------------------------------------------------
>
> task :init => :clobber do
> File.open("source/a.png", "w") do |outs|
> outs.puts "A PNG FILE"
> end
> end
>
> task :see do
> puts "-- Contents of source/a.png -------------------------------"
> puts File.read("source/a.png")
> puts "-- Contents of stage2/a.png -------------------------------"
> puts File.read("stage1/a.png")
> puts "-- Contents of stage2/a.png -------------------------------"
> puts File.read("stage2/a.png")
> end
> ----------------------------------------------------------------
>
> --
> -- Jim Weirich
>
> --
> Posted via http://www.ruby-....
>
>


??? ???? ????? ?????? ????? ???????

10/11/2013 4:18:00 PM

0

On Friday, October 11, 2013 9:02:35 AM UTC-6, The Revd wrote:
> In article <4c2g59ltspv257pul7sr54uc3nilguv4t0@4ax.com>,
>
> The FAKE Revd <peeling@degenerate.Grik> wrote:
>
>
>
> > Life greeks you for your admiration of Griks and your
>
> > sucking of jew rectums. Now get this straight:
>
> >
>
> > ONLY I AM ALLOWED TO SUCK JEW RECTUMS.
>
> >
>
> > Capisce!?
>
>
>
> Suck away, sick fuck!

Some needs to bust a cap in that puss gut of yours.

The Revd

10/11/2013 4:47:00 PM

0

On Fri, 11 Oct 2013 09:18:15 -0700 (PDT), ????? ?????? ????? ???????
<Royalty3850@hotmail.com> wrote:

>Some needs to bust a cap in that puss gut of yours.

Some [sic] needs to get a rope and string you up, nigger asshole.

??? ???? ????? ?????? ????? ???????

10/11/2013 10:50:00 PM

0

On Friday, October 11, 2013 10:46:56 AM UTC-6, The Revd wrote:
> On Fri, 11 Oct 2013 09:18:15 -0700 (PDT), ????? ?????? ????? ???????
>
> <Royalty3850@hotmail.com> wrote:
>
>
>
> >Some needs to bust a cap in that puss gut of yours.
>
>
>
> Some [sic] needs to get a rope and string you up, nigger asshole.

You are still a genuine asshole and a deserving putz to die soon so the atmosphere will be less contaminated by your unclean and diseased person you goofy queer fuck.

Michael Ejercito

10/12/2013 2:14:00 AM

0



"?????????? ???????????? ?????????? ??????????????" wrote in message
news:c37ab7e2-f71c-4e06-b508-47375c4d134b@googlegroups.com...

>On Friday, October 11, 2013 10:46:56 AM UTC-6, The Revd wrote:
>> On Fri, 11 Oct 2013 09:18:15 -0700 (PDT), ????? ?????? ????? ???????
>>
>> <Royalty3850@hotmail.com> wrote:
>>
>>
>>
> >>Some needs to bust a cap in that puss gut of yours.
>>
>>
>>
>> Some [sic] needs to get a rope and string you up, nigger asshole.

>You are still a genuine asshole and a deserving putz to die soon so the
>atmosphere will be less contaminated by your unclean and >diseased person
>you goofy queer fuck.
He is a nithing and a mangina.


Michael

The Revd

10/12/2013 2:49:00 AM

0

On Fri, 11 Oct 2013 19:14:18 -0700, "Michael Ejercito"
<mejercit@hotmail.com> wrote:

>
>
>"????? ?????? ????? ???????" wrote in message
>news:c37ab7e2-f71c-4e06-b508-47375c4d134b@googlegroups.com...
>
>>On Friday, October 11, 2013 10:46:56 AM UTC-6, The Revd wrote:
>>> On Fri, 11 Oct 2013 09:18:15 -0700 (PDT), ????? ?????? ????? ???????
>>>
>>> <Royalty3850@hotmail.com> wrote:
>>>
>>>
>>>
>> >>Some needs to bust a cap in that puss gut of yours.
>>>
>>>
>>>
>>> Some [sic] needs to get a rope and string you up, nigger asshole.
>
>>You are still a genuine asshole and a deserving putz to die soon so the
>>atmosphere will be less contaminated by your unclean and >diseased person
>>you goofy queer fuck.
> He is a nithing and a mangina.

You are a craven gook and a jew anilinguist.

The Revd

10/12/2013 2:50:00 AM

0

On Fri, 11 Oct 2013 15:49:48 -0700 (PDT), ????? ?????? ????? ???????
<Royalty3850@hotmail.com> wrote:

>On Friday, October 11, 2013 10:46:56 AM UTC-6, The Revd wrote:
>> On Fri, 11 Oct 2013 09:18:15 -0700 (PDT), ????? ?????? ????? ???????
>>
>> <Royalty3850@hotmail.com> wrote:
>>
>>
>>
>> >Some needs to bust a cap in that puss gut of yours.
>>
>>
>>
>> Some [sic] needs to get a rope and string you up, nigger asshole.
>
>You are still a genuine asshole and a deserving putz to die soon so the atmosphere will be less contaminated by your unclean and diseased person you goofy queer fuck.

Who AKSED you to open your dirty fucking nigger mouth, boy? Go back
to pretending you're a jew, you demented little coon!