0
votes

Here is the problem definition; I have some local changes in my working copy. I can list them by svn st command. Example output;

M       admin/controller/common/forgotten.php
M       admin/controller/sale/contact.php
A  +    admin/model/tool/mail.php
D       catalog/view/theme/default/template/mail/order.tpl
D       catalog/view/theme/default/template/mail/recommend.tpl
A  +    mail_template

I have a remote server and i want to push these changes to remote server by ftp for testing. If it's ok then i will commit them to trunk.

Now i'm doing this by finding and uploading those files one by one selecting them in an ftp client. But sometimes it's very time consuming especially when changed files are much more.

So i want this action to be done automatically by a script or tool. Any suggestion? Or should i write a small application for this problem?

1

1 Answers

0
votes

Here's something written in that could work. If you don't like perl it may at least give you an idea of what to do in your own script. I tried to write it readable.

Start the script with this call svn status | perl scriptname.pl.

The script reads the output of svn status line by line. It checks if the lines describe an added, modified/replaced or deleted element and adds the path of the element to the corresponding list. Then it tries to connect to the FTP server and changes the elements there.

The FTP part is completely untested.

I haven't tested what SVN does when you add a folder with subelements in it. Maybe you have to add all the subelements to @filesAdded by yourself.

    #!/usr/bin/perl

    use Net::FTP;

    use strict;
    use warnings;

    my $username = "username";
    my $password = "password";
    my $host = "example.com";
    my $port = 20;
    my $path = "/some/path/";

    my @filesAdded;
    my @filesModified;
    my @filesDeleted;

    while(<STDIN>) {
        chomp;
        if (/[A]...... (.+)/) {
            push @filesAdded, $1;
        } elsif(/[MR]...... (.+)/) {
            push @filesModified, $1;
        } elsif (/[D]...... (.+)/) {
            push @filesDeleted, $1;
        }
    }

    print "========================[ CHANGES ]========================\n";
    print "filesAdded[".(scalar @filesModified)."]=".(join ", ", @filesModified)."\n";
    print "filesModified[".(scalar @filesModified)."]=".(join ", ", @filesModified)."\n";
    print "filesDeleted[".(scalar @filesDeleted)."]=".(join ", ", @filesDeleted)."\n";
    print "==========================[ FTP ]==========================\n";

    {
        my $ftp = Net::FTP->new(Host => $host, Port => $port) or die "Cannot connect to $host: $@";
        $ftp->login($username, $password) or die "Cannot login ", $ftp->message;
        $ftp->cwd($path) or die "Cannot change working directory ", $ftp->message;

        for my $fileAdded (@filesAdded) {
            if(-f $fileAdded) {
                $ftp->put($fileAdded);
            } elsif(-d $fileAdded) {
                $ftp->mkdir($fileAdded, 1);
            }
        }

        for my $fileModified (@filesModified) {
            $ftp->put($fileModified, $fileModified);
        }

        for my $fileDeleted (@filesDeleted) {
            if(-f $fileDeleted) {
                $ftp->delete($fileDeleted);
            } elsif(-d $fileDeleted) {
                $ftp->rmdir($fileDeleted, 1);
            }
        }
        $ftp->quit;
    }

    print "========================[ SUCCESS ]========================\n";