Changeset 2386


Ignore:
Timestamp:
11/26/2011 2:01:07 AM (3 years ago)
Author:
lowjoel
Message:

Factor the utility functions used by the Build slaves to a separate BuildUtil? file which is referenced by both the build server and build client scripts.

Location:
trunk/website/scripts
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/BuildPublish.php

    r1995 r2386  
    1717require_once('Database.php'); 
    1818require_once('Build.php'); 
    19  
    20 /** 
    21  * Uploads the contents of a stream to a particular URL. 
    22  * 
    23  * @param string $url      The URL of the destination of the upload. 
    24  * @param string $stream   The source stream for upload. 
    25  * @param string $username The username of the user, if required. 
    26  * @param string $password The password of the user, if required. 
    27  */ 
    28 function Upload($url, $stream, $username = '', $password = '') 
    29 { 
    30     printf('Uploading file to %s... ', $url); 
    31  
    32     $curl = curl_init($url); 
    33     curl_setopt($curl, CURLOPT_USERPWD, sprintf('%s:%s', $username, $password)); 
    34     curl_setopt($curl, CURLOPT_UPLOAD, true); 
    35     curl_setopt($curl, CURLOPT_INFILE, $stream); 
    36  
    37     if (curl_exec($curl) === false) 
    38         throw new Exception('cURL Error: ' . curl_error($curl)); 
    39     curl_close($curl); 
    40  
    41     printf("File uploaded.\n"); 
    42 } 
    43  
    44 function Delete($url, $username = '', $password = '') 
    45 { 
    46     printf('Deleting %s... ', $url); 
    47  
    48     $curl = curl_init($url); 
    49     curl_setopt($curl, CURLOPT_USERPWD, sprintf('%s:%s', $username, $password)); 
    50  
    51     //Create a temp stream to upload to the old path (to zero the length) 
    52     $stream = fopen('php://temp', 'r'); 
    53     curl_setopt($curl, CURLOPT_UPLOAD, true); 
    54     curl_setopt($curl, CURLOPT_INFILE, $stream); 
    55  
    56     //Parse the URL to get the path to delete 
    57     $path = parse_url($url, PHP_URL_PATH); 
    58     curl_setopt($curl, CURLOPT_POSTQUOTE, array( 
    59         sprintf('rm "%s"', $path) 
    60     )); 
    61  
    62     if (curl_exec($curl) === false) 
    63         throw new Exception('cURL Error: ' . curl_error($curl)); 
    64     fclose($stream); 
    65     curl_close($curl); 
    66  
    67     printf("File deleted.\n"); 
    68 } 
    6919 
    7020$file = fopen($argv[3], 'rb'); 
  • trunk/website/scripts/BuildServer.php

    r2385 r2386  
    11<?php 
    2  
    32//HTTP Digest authentication code, modified from http://php.net/manual/en/features.http-auth.php 
    43define('HTTP_DIGEST_REALM', 'Build Server'); 
     
    5655    http_digest_challenge(); 
    5756 
     57require('Build.php'); 
     58require('BuildUtil.php'); 
     59require('Credentials.php'); 
     60require('Database.php'); 
    5861 
     62try 
     63{ 
     64    //Check that we have all the necessary information 
     65    $branches = BuildBranch::Get(); 
     66    if (!array_key_exists($_GET['branch'], $branches)) 
     67        throw new Exception('The branch ' . $_GET['branch'] . ' does not exist.'); 
     68    if (!is_numeric($_GET['revision']) || !is_numeric($_GET['filesize']) || empty($_GET['url'])) 
     69        throw new Exception('Invalid build information provided.'); 
     70 
     71    //Get the branch the notification is for 
     72    define('HTTP_WEB_ROOT', 'http://eraser.sourceforge.net'); 
     73    $branch = $branches[$_GET['branch']]; 
     74 
     75    //Insert the build to the database. 
     76    printf('Inserting build into database... '); 
     77    Build::CreateBuild($branch->ID, intval($_GET['revision']), intval($_GET['filesize']), $_GET['url']); 
     78    printf("Inserted.\n"); 
     79 
     80    //Remove old builds 
     81    printf('Removing old builds from database...' . "\n"); 
     82 
     83    $pdo = new Database(); 
     84    $statement = $pdo->prepare('UPDATE downloads SET Superseded=1 WHERE DownloadID=?'); 
     85 
     86    $builds = Build::GetActive($branch->ID); 
     87    for ($i = 0, $j = count($builds) - 3; $i < $j; ++$i) 
     88    { 
     89        printf("\n\t" . 'Removing build %s' . "\n\t\t", $builds[$i]->Name); 
     90 
     91        //Delete the copy on the SourceForge web server. 
     92        Delete(SHELL_WEB_ROOT . parse_url($builds[$i]->Link, PHP_URL_PATH), $sftp_username, 
     93            $sftp_password); 
     94 
     95        //Remove from the database 
     96        $statement->execute(array($builds[$i]->ID)); 
     97    } 
     98} 
     99catch (Exception $e) 
     100{ 
     101    echo $e->getMessage(); 
     102    exit(1); 
     103} 
    59104?> 
Note: See TracChangeset for help on using the changeset viewer.