J
Joe Van Dyk
I wrote the below code in maybe 10 minutes. It seems to do the job,
but I'm sure it could be better. Any ideas?
# Examines a subversion directory.
# If a file has been added, add the file to the repository.
# If a file has been deleted, delete the file from the repository.
# And save all modified files.
# And then do a 'svn up'.
# Meant to do automated versioned backups of a directory for
# non-technically inclined users.
# Utility functions
class String
def get_filename
self.split[1]
end
end
def get_status line
line.split[0]
end
def new_file? line
get_status(line) =3D=3D "?"
end
def removed_file? line
get_status(line) =3D=3D "!"
end
def add_file file_name
puts "adding file: <#{file_name}>"
system "svn add '#{file_name}'"
end
def remove_file file_name
puts "removing file: <#{file_name}>"
system "svn del '#{file_name}'"
end
def hidden_filename line
line.get_filename[0,1] =3D=3D "." if line.size > 0
end
# Get svn stuff and process it.
svn_output =3D `svn status`
svn_output.split("\n").each do |line|
# a line should look something like "M some/dir/file_name"
unless hidden_filename(line)
add_file line.get_filename if new_file? line
remove_file line.get_filename if removed_file? line
end
end
system "svn commit -m 'autocommited!'"
system "svn up"
but I'm sure it could be better. Any ideas?
# Examines a subversion directory.
# If a file has been added, add the file to the repository.
# If a file has been deleted, delete the file from the repository.
# And save all modified files.
# And then do a 'svn up'.
# Meant to do automated versioned backups of a directory for
# non-technically inclined users.
# Utility functions
class String
def get_filename
self.split[1]
end
end
def get_status line
line.split[0]
end
def new_file? line
get_status(line) =3D=3D "?"
end
def removed_file? line
get_status(line) =3D=3D "!"
end
def add_file file_name
puts "adding file: <#{file_name}>"
system "svn add '#{file_name}'"
end
def remove_file file_name
puts "removing file: <#{file_name}>"
system "svn del '#{file_name}'"
end
def hidden_filename line
line.get_filename[0,1] =3D=3D "." if line.size > 0
end
# Get svn stuff and process it.
svn_output =3D `svn status`
svn_output.split("\n").each do |line|
# a line should look something like "M some/dir/file_name"
unless hidden_filename(line)
add_file line.get_filename if new_file? line
remove_file line.get_filename if removed_file? line
end
end
system "svn commit -m 'autocommited!'"
system "svn up"