# Re: Ruby and ClearCase

**URL:** <https://www.ruby-forum.com/t/re-ruby-and-clearcase/66105>\
**Category:** Ruby\
**Created:** [August 23, 2006, 12:09pm UTC](https://www.ruby-forum.com/t/re-ruby-and-clearcase/66105 "2006-08-23T12:09:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CameronS\_Gemma\_SUK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/45deac/32.png) [@CameronS\_Gemma\_SUK](https://www.ruby-forum.com/u/CameronS_Gemma_SUK)\
**Post date:** [August 23, 2006, 12:09pm UTC](https://www.ruby-forum.com/t/re-ruby-and-clearcase/66105/1 "2006-08-23T12:09:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CameronS\_Gemma\_SUK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/45deac/32.png) [@CameronS\_Gemma\_SUK](https://www.ruby-forum.com/u/CameronS_Gemma_SUK)\
**Post date:** [August 23, 2006, 2:31pm UTC](https://www.ruby-forum.com/t/re-ruby-and-clearcase/66105/2 "2006-08-23T14:31:18Z")

</div>

On 8/23/06, Cameron, Gemma (UK) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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…

> ```
> Dir.chdir("f:")
> 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
