Merge files.rb

From radmind

Jump to: navigation, search

This is a very rough starter script. You will need to edit this script, think of it as a template which may save you some time when using lmerge with various transcripts.

There are a variety other ways (depending on what you want to do they may also be faster and less complex) to accomplish what this script will do. The key with this script is the flexibility you gain by being able to do pattern matching / list manipulation within ruby. Hopefully even those who are very new to ruby will find this script will save time in certain circumstances. The hope is that people will add further examples of how to manipulate the list of transcripts and then add these into the script.

Essentially this script will look in a directory and generate a list of transcripts using the 'Dir[]' directive towards the start of the script. Next it will reverse these and finally, you may then start pruning / adding into this list of transcripts for other areas.

To use:

  1. Download merge_files.rb
  2. Make merge_files.rb executable
  3. Edit the 'transcripts_dir' line and edit the other parts as required for your particular purpose.
  4. Run merge_files.rb and then use the output as required with lmerge.
 Notes : This script is geared towards getting data ready for lmerge. 
               It is more of a template than a ready to use script. Hopefully, it saves someone a few moments.
#!/usr/bin/env ruby

# (C)2008 Henri Shustak
# Licenced under the GNU GPL

# Notes
# cd into the directory where the lmerge binday is located : typcially /usr/local/bin
# then using the output from this script you should be able to use lmerge
# to generate the new transcript.

#./lmerge -n [-vIV] [ -D path ] [ -u umask ] transcript1 transcript2 dest    ( This is the basic options example )
#./lmerge transcript_highest.T .... transcript_lowest.T new_transcript_dest.T     (This is the one you probably want to follow)
#./lcksum -c sha1 new_transcript_dest.T

# Version 0.1

require 'fileutils'

# To find all transcripts such as "somepattern-v0001.T", "somepattern-v0002.T" ...
transcripts_dir = Dir["/var/radmind/transcript/somepattern-v*.T"]
transcripts_dir = transcripts_dir.reverse

# Weed out the onese we do not want in the new transcript array - (currently disabled - commented out)
# If you feel like explaining this further or adding other examples, then go a head.
# This is simply a verbose example of what you may do to remove some items from the list.

x = 0
transcripts_dir.each do |f|
	#	if (( f.strip != "/var/radmind/transcript/somepattern-notinuse-v00048.T" ) && ( f.strip != "/var/radmind/transcript/somepattern-notinuse-v00077.T" ))
		#new_transcripts[x] = File.basename(f)
	    new_transcripts[x] = f
		x = x + 1	
	#	end

input_transcripts = ""
new_transcripts.each do |f|
	input_transcripts = input_transcripts + " " + f

# lists them on the output - you could do something more complicated if you wanted one example would be updating checksums?
puts input_transcripts

Personal tools