[limb-svn] r6419 - in buildman/trunk: bin src/model tests

svn at limb-project.com svn at limb-project.com
Mon Oct 15 17:51:19 MSD 2007


Author: pachanga
Date: 2007-10-15 17:51:19 +0400 (Mon, 15 Oct 2007)
New Revision: 6419
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6419

Modified:
   buildman/trunk/bin/build.php
   buildman/trunk/src/model/Build.class.php
   buildman/trunk/tests/ProjectTest.class.php
Log:
-- build.php minor code beautifying
-- a bit better tests



Modified: buildman/trunk/bin/build.php
===================================================================
--- buildman/trunk/bin/build.php	2007-10-15 12:32:32 UTC (rev 6418)
+++ buildman/trunk/bin/build.php	2007-10-15 13:51:19 UTC (rev 6419)
@@ -10,15 +10,21 @@
   }
 }
 
-if (!isset($_SERVER['argv'][1])) {
+if(!isset($argv[1])) 
+{
   foreach(Project :: findAllProjects() as $project)
     $project->build(new CliListener());
-} else {
-  if ($project = Project :: findProject($_SERVER['argv'][1])) {
+} 
+else 
+{
+  if($project = Project :: findProject($argv[1])) 
+  {
     $project->build(new CliListener());
-  } else {
-    echo 'Error: project '.$_SERVER['argv'][1].' not found';
+  } 
+  else 
+  {
+    echo "Error: project '" . $argv[1] . "' not found\n";
+    exit(1);
   }
 }
 
-?>
\ No newline at end of file

Modified: buildman/trunk/src/model/Build.class.php
===================================================================
--- buildman/trunk/src/model/Build.class.php	2007-10-15 12:32:32 UTC (rev 6418)
+++ buildman/trunk/src/model/Build.class.php	2007-10-15 13:51:19 UTC (rev 6419)
@@ -1,210 +1,210 @@
-<?php
-lmb_require('limb/classkit/src/lmbObject.class.php');
-lmb_require('limb/util/src/system/lmbFs.class.php');
-
- at define('BUILDMAN_WEB_DIR', '/');
- at define('BUILDMAN_CP_BIN', 'cp');
- at define('BUILDMAN_CAT_BIN', 'cat');
- at define('BUILDMAN_ZIP_BIN', 'zip');
- at define('BUILDMAN_GZIP_BIN', 'gzip');
- at define('BUILDMAN_TAR_BIN', 'tar');
-
-class Build extends lmbObject
-{
-  const BUILD_NAME_REGEX = '~^r(\d+)-((\d+)_(\d+)_(\d+)-(\d+)_(\d+)_(\d+))-([-\w\._]+)$~';
-  const BUILD_TIME_FORMAT = 'Y_m_d-H_i_s';
-
-  const STATE_UNDEF    = 1;
-  const STATE_OK       = 2;
-  const STATE_ERROR    = 3;
-  const STATE_PROGRESS = 4;
-
-  protected $state;
-  protected $build_dir;
-  protected $build_name;
-  protected $project_name;
-  protected $build_revision;
-  protected $build_date;
-  protected $build_stamp;
-
-  function __construct($build_dir)
-  {
-    $this->build_dir = $build_dir;
-    $this->build_name = basename($build_dir);
-
-    //add exception handling later
-    preg_match(Build :: BUILD_NAME_REGEX, $this->build_name, $m);
-    $this->project_name = $m[9];
-    $this->build_revision = $m[1];
-    $this->build_date = $m[2];
-    $this->build_stamp = mktime($m[6], $m[7], $m[8], $m[4], $m[5], $m[3]);
-
-    if(file_exists($state_file = $this->getStateFile()))
-      $this->state = file_get_contents($state_file);
-    else
-      $this->state = self :: STATE_UNDEF;
-  }
-
-  function getBuildWebDir()
-  {
-    return BUILDMAN_WEB_DIR . 'builds/' . $this->project_name . '/' . $this->build_name;
-  }
-
-  function getChangelogWebPath()
-  {
-    return $this->getBuildWebDir() . '/CHANGE.LOG';
-  }
-
-  function getBuildlogWebPath()
-  {
-    return $this->getBuildWebDir() . '/BUILD.LOG';
-  }
-
-  function getBuildLog()
-  {
-    return file_get_contents($this->build_dir . '/BUILD.LOG');
-  }
-
-  function markOk()
-  {
-    $this->setState(self :: STATE_OK);
-  }
-
-  function markError()
-  {
-    $this->setState(self :: STATE_ERROR);
-  }
-
-  function markInProgress()
-  {
-    $this->setState(self :: STATE_PROGRESS);
-  }
-
-  function getIsError()
-  {
-    return $this->getState() == self :: STATE_ERROR;
-  }
-
-  function getIsOk()
-  {
-    return $this->getState() == self :: STATE_OK;
-  }
-
-  function getIsUndefined()
-  {
-    return $this->getState() == self :: STATE_UNDEF;
-  }
-
-  function getIsInProgress()
-  {
-    return $this->getState() == self :: STATE_PROGRESS;
-  }
-
-  function setState($state)
-  {
-    $this->state = $state;
-    file_put_contents($this->getStateFile(), $state);
-  }
-
-  function getStateFile()
-  {
-    return $this->build_dir . '/.state';
-  }
-
-  static function createBuild($builds_dir, $project, $rev, $time)
-  {
-    $name = self :: makeBuildDirName($project, $rev, $time);
-    lmbFs :: mkdir($dir = "$builds_dir/$name");
-    return new Build($dir);
-  }
-
-  static function makeBuildDirName($project, $rev, $time)
-  {
-    return 'r' . $rev . '-' . date(Build :: BUILD_TIME_FORMAT, $time) .  '-' . $project;
-  }
-
-  function copyFile($src, $dst=null)
-  {
-    if(!$dst)
-      $dst = basename($src);
-    $cmd = BUILDMAN_CP_BIN . " -rp $src {$this->build_dir}/$dst";
-    `$cmd`;
-  }
-
-  function createFile($name, $contents)
-  {
-    file_put_contents($this->build_dir . '/' . $name, $contents);
-  }
-
-  function createChangelog($contents)
-  {
-    $this->createFile('CHANGE.LOG', $contents);
-  }
-
-  function createBuildlog($contents)
-  {
-    $this->createFile('BUILD.LOG', $contents);
-  }
-
-  function removeFile($name)
-  {
-    lmbFs :: rm($this->build_dir . '/' . $name);
-  }
-
-  function zipFile($name, $archive_name)
-  {
-    $file = $this->build_dir . '/' . $name;
-    $archive = $this->build_dir . '/' . $archive_name;
-
-    $zip = BUILDMAN_ZIP_BIN;
-    $cat = BUILDMAN_CAT_BIN;
-
-    if(is_dir($file))
-    {
-      $old = getcwd();
-      $dir = dirname($file);
-      $name = basename($file);
-      chdir($dir);
-      `$zip -r -9 -q $archive $name`;
-      chdir($old);
-    }
-    else
-      `$cat $file | $zip -9 -q > $archive`;
-  }
-
-  function gzipFile($name, $archive_name)
-  {
-    $file = $this->build_dir . '/' . $name;
-    $archive = $this->build_dir . '/' . $archive_name;
-
-    $tar = BUILDMAN_TAR_BIN;
-    $gzip = BUILDMAN_GZIP_BIN;
-    $cat = BUILDMAN_CAT_BIN;
-
-    if(is_dir($file))
-    {
-      $old = getcwd();
-      $dir = dirname($file);
-      $name = basename($file);
-      chdir($dir);
-      `$tar cf - $name | $gzip -9 -c > $archive`;
-      chdir($old);
-    }
-    else
-      `$cat $file | $gzip -9 -c > $archive`;
-  }
-
-  function listFiles()
-  {
-    $files = array();
-    foreach(scandir($this->build_dir) as $file)
-    {
-      if($file == '.' || $file == '..')
-        continue;
-      $files[] = $this->build_dir . '/' . $file;
-    }
-    return $files;
-  }
-}
-
-?>
+<?php
+lmb_require('limb/classkit/src/lmbObject.class.php');
+lmb_require('limb/util/src/system/lmbFs.class.php');
+
+ at define('BUILDMAN_WEB_DIR', '/');
+ at define('BUILDMAN_CP_BIN', 'cp');
+ at define('BUILDMAN_CAT_BIN', 'cat');
+ at define('BUILDMAN_ZIP_BIN', 'zip');
+ at define('BUILDMAN_GZIP_BIN', 'gzip');
+ at define('BUILDMAN_TAR_BIN', 'tar');
+
+class Build extends lmbObject
+{
+  const BUILD_NAME_REGEX = '~^r(\d+)-((\d+)_(\d+)_(\d+)-(\d+)_(\d+)_(\d+))-([-\w\._]+)$~';
+  const BUILD_TIME_FORMAT = 'Y_m_d-H_i_s';
+
+  const STATE_UNDEF    = 1;
+  const STATE_OK       = 2;
+  const STATE_ERROR    = 3;
+  const STATE_PROGRESS = 4;
+
+  protected $state;
+  protected $build_dir;
+  protected $build_name;
+  protected $project_name;
+  protected $build_revision;
+  protected $build_date;
+  protected $build_stamp;
+
+  function __construct($build_dir)
+  {
+    $this->build_dir = $build_dir;
+    $this->build_name = basename($build_dir);
+
+    //add exception handling later
+    preg_match(Build :: BUILD_NAME_REGEX, $this->build_name, $m);
+    $this->project_name = $m[9];
+    $this->build_revision = $m[1];
+    $this->build_date = $m[2];
+    $this->build_stamp = mktime($m[6], $m[7], $m[8], $m[4], $m[5], $m[3]);
+
+    if(file_exists($state_file = $this->getStateFile()))
+      $this->state = file_get_contents($state_file);
+    else
+      $this->state = self :: STATE_UNDEF;
+  }
+
+  function getBuildWebDir()
+  {
+    return BUILDMAN_WEB_DIR . 'builds/' . $this->project_name . '/' . $this->build_name;
+  }
+
+  function getChangelogWebPath()
+  {
+    return $this->getBuildWebDir() . '/CHANGE.LOG';
+  }
+
+  function getBuildlogWebPath()
+  {
+    return $this->getBuildWebDir() . '/BUILD.LOG';
+  }
+
+  function getBuildLog()
+  {
+    return file_get_contents($this->build_dir . '/BUILD.LOG');
+  }
+
+  function markOk()
+  {
+    $this->setState(self :: STATE_OK);
+  }
+
+  function markError()
+  {
+    $this->setState(self :: STATE_ERROR);
+  }
+
+  function markInProgress()
+  {
+    $this->setState(self :: STATE_PROGRESS);
+  }
+
+  function getIsError()
+  {
+    return $this->getState() == self :: STATE_ERROR;
+  }
+
+  function getIsOk()
+  {
+    return $this->getState() == self :: STATE_OK;
+  }
+
+  function getIsUndefined()
+  {
+    return $this->getState() == self :: STATE_UNDEF;
+  }
+
+  function getIsInProgress()
+  {
+    return $this->getState() == self :: STATE_PROGRESS;
+  }
+
+  function setState($state)
+  {
+    $this->state = $state;
+    file_put_contents($this->getStateFile(), $state);
+  }
+
+  function getStateFile()
+  {
+    return $this->build_dir . '/.state';
+  }
+
+  static function createBuild($builds_dir, $project, $rev, $time)
+  {
+    $name = self :: makeBuildDirName($project, $rev, $time);
+    lmbFs :: mkdir($dir = "$builds_dir/$name");
+    return new Build($dir);
+  }
+
+  static function makeBuildDirName($project, $rev, $time)
+  {
+    return 'r' . $rev . '-' . date(Build :: BUILD_TIME_FORMAT, $time) .  '-' . $project;
+  }
+
+  function copyFile($src, $dst=null)
+  {
+    if(!$dst)
+      $dst = basename($src);
+    $cmd = BUILDMAN_CP_BIN . " -rp $src {$this->build_dir}/$dst";
+    `$cmd`;
+  }
+
+  function createFile($name, $contents)
+  {
+    file_put_contents($this->build_dir . '/' . $name, $contents);
+  }
+
+  function createChangelog($contents)
+  {
+    $this->createFile('CHANGE.LOG', $contents);
+  }
+
+  function createBuildlog($contents)
+  {
+    $this->createFile('BUILD.LOG', $contents);
+  }
+
+  function removeFile($name)
+  {
+    lmbFs :: rm($this->build_dir . '/' . $name);
+  }
+
+  function zipFile($name, $archive_name)
+  {
+    $file = $this->build_dir . '/' . $name;
+    $archive = $this->build_dir . '/' . $archive_name;
+
+    $zip = BUILDMAN_ZIP_BIN;
+    $cat = BUILDMAN_CAT_BIN;
+
+    if(is_dir($file))
+    {
+      $old = getcwd();
+      $dir = dirname($file);
+      $name = basename($file);
+      chdir($dir);
+      `$zip -r -9 -q $archive $name`;
+      chdir($old);
+    }
+    else
+      `$cat $file | $zip -9 -q > $archive`;
+  }
+
+  function gzipFile($name, $archive_name)
+  {
+    $file = $this->build_dir . '/' . $name;
+    $archive = $this->build_dir . '/' . $archive_name;
+
+    $tar = BUILDMAN_TAR_BIN;
+    $gzip = BUILDMAN_GZIP_BIN;
+    $cat = BUILDMAN_CAT_BIN;
+
+    if(is_dir($file))
+    {
+      $old = getcwd();
+      $dir = dirname($file);
+      $name = basename($file);
+      chdir($dir);
+      `$tar cf - $name | $gzip -9 -c > $archive`;
+      chdir($old);
+    }
+    else
+      `$cat $file | $gzip -9 -c > $archive`;
+  }
+
+  function listFiles()
+  {
+    $files = array();
+    foreach(scandir($this->build_dir) as $file)
+    {
+      if($file == '.' || $file == '..')
+        continue;
+      $files[] = $this->build_dir . '/' . $file;
+    }
+    return $files;
+  }
+}
+
+?>

Modified: buildman/trunk/tests/ProjectTest.class.php
===================================================================
--- buildman/trunk/tests/ProjectTest.class.php	2007-10-15 12:32:32 UTC (rev 6418)
+++ buildman/trunk/tests/ProjectTest.class.php	2007-10-15 13:51:19 UTC (rev 6419)
@@ -52,8 +52,8 @@
   {
     $project1 = new Project('foo');
 
-    $b1 = $project1->createBuild($rev1 = 21, $time1 = time());
-    $b2 = $project1->createBuild($rev2 = 34, $time2 = time() + 100);
+    $b1 = $project1->createBuild($rev1 = 999, $time1 = time());
+    $b2 = $project1->createBuild($rev2 = 1000, $time2 = time() + 100);
 
     $this->assertEqual($b1->getBuildStamp(), $time1);
     $this->assertEqual($b2->getBuildStamp(), $time2);
@@ -91,4 +91,4 @@
   }
 }
 
-?>
\ No newline at end of file
+?>



More information about the limb-svn mailing list