view treepkg/publish.py @ 429:9cfa9f64387a treepkg-status

only rsync specified architectures from cachedir to publishdir
author Bjoern Ricks <bricks@intevation.de>
date Wed, 28 Jul 2010 11:38:00 +0000
parents 25ef11a79d7f
children 8e0c81870e5e
line wrap: on
line source
#! /usr/bin/python
# Copyright (C) 2007 - 2010 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh@intevation.de>
# Bjoern Ricks    <bjoern.ricks@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

import os.path

import util
from treepkg.run import call, capture_output
from treepkg.cmdexpand import cmdexpand

def remove_trailing_slashes(s):
    return s.rstrip("/")

def expand_filename(filename):
    """
    Applies os.path.expanduser and os.path.expandvars to filename
    """
    return os.path.expandvars(os.path.expanduser(filename))

def prefix_for_remote_command(user, host):
    """Returns the ssh call needed to run a command on a remote host.
    If host is empty, the function assumes the command is to be run on
    the local host as the same user that exectutes this function, so
    that no ssh or other call is needed.
    """
    prefix = []
    if host:
        prefix.extend(["ssh", "%s@%s" % (user, host)])
    return prefix

def copy_arch_to_publishdir(variables, dist, section, arch=None, quiet=False,
                            create=True):
    if not arch:
        cachedir = variables["cachedir"]
    else:
        cachedir = os.path.join(variables["cachedir"], arch)

    # if cachedir does not exist rsync will fail therefore
    # it must be created or skipped. if it is created remote
    # content will be deleted
    if not os.path.exists(cachedir):
        if create:
            util.ensure_directory(cachedir)
        else:
            return

    destdir = os.path.join(variables["publish_dir"], dist, section)
    remote_destdir = destdir
    if variables["publish_host"]:
        remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables)
                          + remote_destdir)
    runremote = prefix_for_remote_command(variables["publish_user"],
                                          variables["publish_host"])

    call(cmdexpand("@runremote mkdir --parents $destdir",
                   runremote=runremote, destdir=destdir, **variables))
    rsync_flags = []
    if variables["publish_remove_old_packages"]:
        rsync_flags.append("--delete")
    if quiet:
        rsync_flags.append("--quiet")
    cmd = cmdexpand("rsync @rsync_flags -r --perms --times --omit-dir-times"  
                   " $cachedir $remote_destdir/",
                   rsync_flags=rsync_flags, remote_destdir=remote_destdir,
                   cachedir=cachedir)
    #print "rsync cmd: %s" % cmd
    call(cmd)



def copy_to_publishdir(variables, dist, section, arch=None, quiet=False):
    if not arch:
        destdir = os.path.join(variables["publish_dir"], dist, section)
    else:
        destdir = os.path.join(variables["publish_dir"], dist, section, arch)
    remote_destdir = destdir
    if variables["publish_host"]:
        remote_destdir = (("%(publish_user)s@%(publish_host)s:" % variables)
                          + remote_destdir)
    runremote = prefix_for_remote_command(variables["publish_user"],
                                          variables["publish_host"])

    call(cmdexpand("@runremote mkdir --parents $destdir",
                   runremote=runremote, destdir=destdir, **variables))
    rsync_flags = []
    if variables["publish_remove_old_packages"]:
        rsync_flags.append("--delete")
    if quiet:
        rsync_flags.append("--quiet")
    call(cmdexpand("rsync @rsync_flags -r --perms --times --omit-dir-times"  
                   " $cachedir/ $remote_destdir/",
                   rsync_flags=rsync_flags, remote_destdir=remote_destdir,
                   **variables))

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)