[Locomotive-users] [Req] : project snapshot (zip)

Adam Salter adam at rokslide.com
Sun Feb 4 05:27:11 GMT 2007


I just finished writing a shell script like this which uses Ruby! :)

Probably a bit complicated, but maybe not...
Requires "session" rubygem


archive.rb
--------------
#!/usr/bin/env ruby

#
# Make an archive of the directory from command line
#

require "FileUtils"
require 'rubygems'
require 'session'

begin

   if ( ARGV[1] )
     raise SystemCallError, "not a directory" if !File.directory? ARGV 
[1]
     dir = File.basename(ARGV[1])
     date = File.new(dir).mtime.strftime("_%d-%m-%Y")
     arch_file = '_archive/'+dir+date+'.zip'

     FileUtils.mkdir '_archive' if !File.directory? '_archive'
     FileUtils.rm arch_file if File.exists? arch_file

     sh = Session.new
     stdout, stderr = sh.execute "tar -czvf #{arch_file} #{dir}"
     raise SystemCallError, "#{stderr}" if sh.exitstatus != 0
     case ARGV[0]
     when 'cp'
     when 'mv'
         FileUtils.rm_r dir
     end
   else
     my_string = <<END_OF_STRING

USAGE: archive [ cp | mv ] dir

   cp - Copies the chosen directory into the '_archive' directory,  
renaming it by the modification date.
   mv - Moves the chosen directory into the '_archive' directory,  
renaming it by the modification date.

END_OF_STRING
     puts my_string
   end

rescue SystemCallError
   $stderr.print "Archive failed: " + $! + "\n"
end


-------------

On 04/02/2007, at 4:01 AM, Stephen Waits wrote:

>
> On Feb 2, 2007, at 5:21 AM, Alain Ravet wrote:
>
>> I've automated it through a script that I placed in
>> the dock, but I still need to create one script for each new project
>> so...
>
> Why not just write a shell (or perl, python, or ruby) script and  
> drop it in your ~/bin?  Then you'd have one script that could work  
> for everything.
>
> Though, of course you'd have to run it from the shell, in the base  
> directory of the project you'd want archived.  But, to me, that's  
> just about as easy as anything else you might need to do (or easier).
>
> --Steve
>
> P.S. - the script could look like this:
>
> archive.sh
> ==========
> #!/bin/sh
>
> # where to store the archive (note trailing)
> ARCHIVE_DIR="~/RailsProjectArchives"
>
> # figure out a name, based on current directory + datestamp
> CWD=`pwd`
> BASE_CWD=`basename $CWD`
> DATE=`date +"%F.%R"`
> ARCHIVE_NAME="$ARCHIVE_DIR/$BASE_CWD.$DATE.tar.gz"
>
> # create the archive
> tar zcvf $ARCHIVE_NAME .
>
> _______________________________________________
> Locomotive-users mailing list
> Locomotive-users at lists.raaum.org
> http://lists.raaum.org/mailman/listinfo/locomotive-users


More information about the Locomotive-users mailing list