#!/usr/bin/python
#
#  Copyright (c) 2010 Red Hat, Inc.  <bowe@redhat.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
"""
"""
__author__  = 'Bowe Strickland <bowe@redhat.com>'

import os
import sys
from time import sleep
from subprocess import check_call, CalledProcessError

#os.chdir("/home/bowe/a/svn/linux/rhce-config/rhce-config/var/ftp/pub/gls")
#base = "127.0.0"

os.chdir("/var/ftp/pub/gls")
base = "192.168.0"

cmd1 = "rsync --progress -av ulbin/ root@%s:/usr/local/bin"
cmd2 = "rsync --progress -av ullib/ root@%s:/usr/local/lib"
cmd3 = "rsync --progress -av ulsbin/ root@%s:/usr/local/sbin"


stations = []
for i in range(1,21):
    stations.append("%s.%d" % (base, i))
    stations.append("%s.%d" % (base, (100+i)))
    stations.append("%s.%d" % (base, (200+i)))

null = open("/dev/null", "w")
for s in stations:
    sleep(1)
    if not os.fork():
        try:
            check_call(cmd1%s, shell=True, stdout=null, stderr=null)
            print "%-15s rsync ulbin succeeded" % s
            check_call(cmd2%s, shell=True, stdout=null, stderr=null)
            print "%-15s rsync ullib succeeded" % s
            check_call(cmd3%s, shell=True, stdout=null, stderr=null)
            print "%-15s rsync ulsbin succeeded" % s
        except CalledProcessError, e:
            print "%-15s rsync failed: %s" % (s, str(e))
        sys.exit(0)

# vi: ts=4 expandtab


