Beispiel #1
0
/**
 * Téléporter et déballer un composant SVN
 * 
 * Déployer un repository SVN depuis une source et une révision données
 *
 * @param string $methode
 *     Méthode de téléportation : http|git|svn|...
 * @param string $source
 *     URL de la source SVN
 * @param string $dest
 *     Chemin du répertoire de destination
 * @param array $options
 *     Tableau d'options. Index possibles :
 *     - revision => 'nnn'
 *     - literal => --ignore-externals
 * @return bool
 *     True si l'opération réussie, false sinon.
 */
function teleporter_svn_dist($methode, $source, $dest, $options = array())
{
    if (is_dir($dest)) {
        $infos = teleporter_svn_read($dest);
        if (!$infos) {
            spip_log("Suppression de {$dest} qui n'est pas au format SVN", "teleport");
            $old = teleporter_nettoyer_vieille_version($dest);
        } elseif ($infos['source'] !== $source) {
            spip_log("Suppression de {$dest} qui n'est pas sur le bon repository SVN", "teleport");
            $old = teleporter_nettoyer_vieille_version($dest);
        } elseif (!isset($options['revision']) or $options['revision'] != $infos['revision']) {
            $command = "svn up ";
            if (isset($options['revision'])) {
                $command .= escapeshellarg("-r" . $options['revision']) . " ";
            }
            if (isset($options['ignore-externals'])) {
                $command .= "--ignore-externals ";
            }
            $command .= escapeshellarg($dest);
            spip_log($command, "teleport");
            exec($command);
        } else {
            // Rien a faire !
            spip_log("{$dest} deja a jour (Revision " . $options['revision'] . " SVN de {$source})", "teleport");
        }
    }
    if (!is_dir($dest)) {
        $command = "svn co ";
        if (isset($options['revision'])) {
            $command .= escapeshellarg("-r" . $options['revision']) . " ";
        }
        if (isset($options['ignore-externals'])) {
            $command .= "--ignore-externals ";
        }
        $command .= escapeshellarg($source) . " " . escapeshellarg($dest);
        spip_log($command, "teleport");
        exec($command);
    }
    // verifier que tout a bien marche
    $infos = teleporter_svn_read($dest);
    if (!$infos) {
        return false;
    }
    return true;
}
Beispiel #2
0
/**
 * Téléporter et déballer un composant GIT
 * 
 * Déployer un repository GIT depuis une source et une révision données
 *
 * @param string $methode
 *     Méthode de téléportation : http|git|svn|...
 * @param string $source
 *     URL de la source GIT
 * @param string $dest
 *     Chemin du répertoire de destination
 * @param array $options
 *     Tableau d'options. Index possibles :
 *     - revision => 'ae89'
 *     - branche => 'xxx'
 * @return bool
 *     True si l'opération réussie, false sinon.
 */
function teleporter_git_dist($methode, $source, $dest, $options = array())
{
    $branche = isset($options['branche']) ? $options['branche'] : 'master';
    if (is_dir($dest)) {
        $infos = teleporter_git_read($dest, array('format' => 'assoc'));
        if (!$infos) {
            spip_log("Suppression de {$dest} qui n'est pas au format GIT", "teleport");
            $old = teleporter_nettoyer_vieille_version($dest);
        } elseif ($infos['source'] !== $source) {
            spip_log("Suppression de {$dest} qui n'est pas sur le bon repository GIT", "teleport");
            $old = teleporter_nettoyer_vieille_version($dest);
        } elseif (!isset($options['revision']) or $options['revision'] != $infos['revision']) {
            $command = "git checkout " . escapeshellarg($branche);
            teleporter_git_exec($dest, $command);
            $command = "git pull --all";
            teleporter_git_exec($dest, $command);
            if (isset($options['revision'])) {
                $command = "git checkout " . escapeshellarg($options['revision']);
                teleporter_git_exec($dest, $command);
            } else {
                $command = "git checkout " . escapeshellarg($branche);
                teleporter_git_exec($dest, $command);
            }
        } else {
            spip_log("{$dest} deja sur GIT {$source} Revision " . $options['revision'], "teleport");
        }
    }
    if (!is_dir($dest)) {
        $command = "git clone ";
        $command .= escapeshellarg($source) . " " . escapeshellarg($dest);
        teleporter_git_exec($dest, $command);
        if (isset($options['revision'])) {
            $command = "git checkout " . escapeshellarg($options['revision']);
            teleporter_git_exec($dest, $command);
        }
    }
    // verifier que tout a bien marche
    $infos = teleporter_git_read($dest);
    if (!$infos) {
        return false;
    }
    return true;
}
Beispiel #3
0
/**
 * Téléporter et déballer un composant HTTP
 *
 * @uses  teleporter_http_recuperer_source()
 * @uses  teleporter_nettoyer_vieille_version()
 *
 * @param string $methode
 *   Méthode de téléportation : http|git|svn|...
 * @param string $source
 *     URL de la source HTTP
 * @param string $dest
 *     Chemin du répertoire de destination
 * @param array $options
 *     Tableau d'options.
 *     Doit au moins avoir l'index :
 *     - dir_tmp : Indique un répertoire temporaire pour stocker
 *       les fichiers. Par exemple défini avec : sous_repertoire(_DIR_CACHE, 'chargeur');
 * @return bool|string
 *     Texte d'erreur si erreur,
 *     True si l'opération réussie.
 */
function teleporter_http_dist($methode, $source, $dest, $options = array())
{
    $tmp = $options['dir_tmp'];
    # on ne se contente pas du basename qui peut etre un simple v1
    # exemple de l'url http://nodeload.github.com/kbjr/Git.php/zipball/v0.1.1-rc
    $fichier = $tmp . (basename($dest) . "-" . substr(md5($source), 0, 8) . "-" . basename($source));
    $res = teleporter_http_recuperer_source($source, $fichier);
    if (!is_array($res)) {
        return $res;
    }
    list($fichier, $extension) = $res;
    if (!($deballe = charger_fonction("http_deballe_" . preg_replace(",\\W,", "_", $extension), "teleporter", true))) {
        return _T('svp:erreur_teleporter_format_archive_non_supporte', array('extension' => $extension));
    }
    $old = teleporter_nettoyer_vieille_version($dest);
    if (!($target = $deballe($fichier, $dest, $tmp))) {
        // retablir l'ancien sinon
        if ($old) {
            rename($old, $dest);
        }
        return _T('svp:erreur_teleporter_echec_deballage_archive', array('fichier' => $fichier));
    }
    return true;
}