Ruby and ClearCase

OK so no one has used ruby to drive clearcase... might have to be a pet project to create a gem for this; gem's gem. heh

Now my problem is a very simple one and I don't seem to be typing the right things into google or looking up the right things in anvil to find it so I thought I could ask you guys for some ideas...

Problem:
I want to parse the STDIN generated when I do a clearcase update and for every line that contains:
  Loading "path_to_a_file.txt" (0 bytes)
What I want to get from this line is the filename (stuff in the quotes) so I can send it to a method to be zipped. Initially before I try to zip the file it would be nice to do some debugging by printing the filenames into a text file. This is what I have so far:

def updateView
    Dir.chdir("f:")
    Dir.chdir(getPathToView)
    system("cleartool update -rename #{getPathToView}") if viewCreated?
    parseOutput
    print "\nUpdated #{getPathToView}\n"
end

  def parseOutput
    $stdin.each { |line|
    if line =~ [^Loading]
      file = line.match(/".*"/)
      zipUp(file)
      puts "matched!"
    end
    }
  end

  def zipUp(file)
    Zip::ZipFile::open("updated.zip", true) { |zf|
    zf.add(file, file)
    }
  end

Ta in anticipation of the flood of help/abuse to ensue, ( ;

Gem

Regards

Gemma Cameron

···

-----Original Message-----
From: Cameron, Gemma (UK)
Sent: 22 August 2006 10:09
To: ruby-talk ML
Subject: Ruby and ClearCase...

               *** WARNING ***

This mail has originated outside your organization,
either from an external partner or the Global Internet.

     Keep this in mind if you answer this message.

Hi Guys,

Has anyone used Ruby (or Rake) to interface with cleartool or Rational ClearCase? I googled the problem and found the following project at rubyforge which looks promising... or at least would be if there were any released files (or am I missing reference to a gem somewhere?)

http://rubyforge.org/projects/basketcase/

What I'm wanting to do is to parse the output from cleartool after I've updated a snapshot in order to zip up the new files it's loaded (seeing as ClearCase insists on retaining the entire directory structure when you load folders - I'm used to svn...).

If not are there any suggestions as to how I could go about this or should I just use ruby as a means to sending commands to the shell (system "cleartool -mkview...") followed by somesort of STDIN/OUT? I'm on Windows NT4 and ClearCase 3.2 by the way...

Thanks in advance!

Gem

Regards

Gemma Cameron

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

OK so no one has used ruby to drive clearcase... might have to be a
pet project to create a gem for this; gem's gem. heh

This isn't all that surprising -- ClearCase is hella expensive and the
last time that I dealt with it was eight years ago. No other company
I've worked for uses it.

Now my problem is a very simple one and I don't seem to be typing the
right things into google or looking up the right things in anvil to
find it so I thought I could ask you guys for some ideas...

Problem:
  I want to parse the STDIN generated when I do a clearcase update and
  for every line that contains:
          Loading "path_to_a_file.txt" (0 bytes)
  What I want to get from this line is the filename (stuff in the
  quotes) so I can send it to a method to be zipped. Initially before
  I try to zip the file it would be nice to do some debugging by
  printing the filenames into a text file. This is what I have so far:

    def updateView
      Dir.chdir("f:")
      Dir.chdir(getPathToView)
      system("cleartool update -rename #{getPathToView}") if viewCreated?
      parseOutput
      print "\nUpdated #{getPathToView}\n"
    end

    def parseOutput
      $stdin.each { |line|
      if line =~ [^Loading]
        file = line.match(/".*"/)
        zipUp(file)
        puts "matched!"
      end
      }
    end

    def zipUp(file)
      Zip::ZipFile::open("updated.zip", true) { |zf|
      zf.add(file, file)
      }
    end

A couple of things. It is common Ruby parlance to use underscores in
method names instead of interCaps. So updateView would become
update_view. Second, in your updateView, where are you getting the
"getPathToView" value? Is it another method (like #viewCreated?)? Also,
you probably want to use a pipe -- I haven't done this on Windows -- so
look at popen if it'll work on Windows. Otherwise, do:

  def update_view(path_to_view, drive = nil)
    Dir.chdir("#{drive}#{path_to_view}") do |dir|
      if view_created?(path_to_view)
        output = `cleartool update -rename #{path_to_view}`
        parse_output output
        puts "\nUpdated #{path_to_view}"
      end
    end
  end

  def parse_output(input)
    input.split($/).each do |line|
      if line =~ %r{^Loading} # or /^Loading/
        file = line.split(//)[1]
        zip_up(file)
        puts "Matched #{file}"
      end
    end
  end

  def zip_up(file)
    Zip::ZipFile::open("updated.zip", true) { |zf|
      zf.add(file, file)
    }
  end

Not tested, obviously, since I don't have CC.

-austin

···

On 8/23/06, Cameron, Gemma (UK) <Gemma.Cameron@baesystems.com> wrote:
--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca