DCSIMG
October 2008 - Posts - IronShay

October 2008 - Posts

Why IronRuby is AWESOME!

Yesterday I had to detach a folder from the SVN supervision. In order to do that, one needs to delete the .svn folders within the folder and its subfolders.
I decided to take advantage of IronRuby for that matter.

The problem I ran into with this one was that the files on the .svn folder were read-only. This means that in order to delete the folder, I first have to loop over all the files and remove their read-only attribute. I searched the net for a way to do that without such a loop and found a solution that used a WMI request.

IronRuby lets me take the benefit of the great System.Management class and use it in a Ruby script that I can write in no time.

Here is the code that I've ended up with:

____________________________________________________________________________________
require 'mscorlib'
require 'System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

def RemoveSvnFromDir(path)
    # loop over the files in the given path
    Dir.foreach(path) do |filename|
        current_dir = path + "\\" + filename

        # Ignore dot and double-dot.
        next if filename == "." || filename == ".."

        # If the file is the svn folder, remove it using WMI (no need to reset the read-only attributes)
        if filename == ".svn"
            begin
                puts "Removing #{current_dir}"
                dir = System::Management::ManagementObject.new("win32_Directory.Name='#{current_dir}'")
                dir.Get();
                dir.InvokeMethod("Delete", nil,nil);                
            rescue Exception => e
                puts e.to_s
            end
            next
        end
       
        # If this is a folder, recourse into it and detach it from SVN as well
        if File.directory?(current_dir)
            RemoveSvnFromDir(current_dir)
        end
    end
end

# Get the path from the command line and execute
dir_name = ARGV[0]
puts "Detaching SVN from #{dir_name}"
RemoveSvnFromDir(dir_name)
____________________________________________________________________________________

In order to run it, all that is needed is to open cmd and write "ir SVNCleaner.rb c:\MyCodeDirectory" (assuming that the script file is named SVNCleaner.rb).

This is just a small example of the great power that uniting .Net and dynamic languages can unleash, get ready for more!

Happy Succoth!
Shay.

My article hits the MSDN Pulse October Edition

Hey folks,

Check out the latest MSDN Pulse edition. My article (in the Hebrew language) about dynamic languages and the .Net framework appears there. It's a short introduction to this new and exciting field so if it interests you, go ahead and read it!

A nice surprise on this edition for myself was being awarded as "Blogger of the Month"! That's almost like winning the Oscar award! (just without the glory, the money and some other tiny differences).

MSDN Pulse

Well, I hope you enjoy this and all other great editions of MSDN Pulse,
All the best,
Shay.

Posted by shayf | with no comments
תגים:

Traveling abroad is fun fun fun!

I wasn't around much during the last few weeks. The main reason for that was... I was traveling Ireland!!!
It was so much fun! words cannot describe the feeling!

My advice to all of you - take a vacation! and if you like lots of green, sheep, cows and breath-taking nature - visit Ireland.

To summarize the trip - a picture is worth a thousand words:

Ireland! Whoohoooooo!

One thing to remember - this is a vacation, the day will come when you have to return to reality. And it's gonna hurt! beware!

Well, I guess I have to get back to reality myself and start posting...
See you soon!

Posted by shayf | with no comments
תגים: