one signup works on all my projects

thefrugalprogrammer

Other blog posts:

Mar 22,10

  Probable Burndown

Mar 10,10

  Open Source From the Inside Out

Mar 09,10

  Unit Testing in ploof

Mar 08,10

  A Few Minor Issues

Mar 04,10

  Real Agile QA

Framework auto-updates

Aug 07, 2009

One of the more annoying things about web frameworks I've used is that if you started a project and you suddenly need a feature and need to update or slide back a version, it's a pain in the posterior.

In ploof I'm trying to solve this problem with diffs and patches for the core files.

The ploof command, available on the command line, provides this functionality. Even though ploof doesn't have any releases (proper), you can tell your ploof export to update to a particular revision:

./ploof update trunk

or

./ploof update 1.0

(note that as of this writing there is no 1.0 version, so trunk is all you get)

The essential strategy is to export another version in the resource subdirectory, run a diff against what you currently have installed, and patch it automatically.

Here's the code:

function setup_patch_directory($version= "trunk")
{
    if (opendir("resource/updates"))
        exec("rm -rf resource/updates");
    
    // export a copy of the code off the server:
    exec("mkdir resource/updates");
    if ($version != "trunk")
        $version= "branches/".$version;
    
    exec("svn export http://ploof.googlecode.com/svn/$version ./resource/updates/svn");
}

$patch_list= array(
        "./core"=>"./resource/updates/svn/core",
        "./config/config.default.php"=>"./resource/updates/svn/config/config.default.php",
        "./ploof"=>"./resource/updates/svn/ploof",
        "./public/index.php"=>"./resource/updates/svn/public/index.php",
        "./resource/schemas/init.sql"=>"./resource/updates/svn/resource/schemas/init.sql",
        "./README"=>"./resource/updates/svn/README",
        "./resource/bin"
    );
            
function generate_patch($version= "trunk")
{   
    global $patch_list; 
    setup_patch_directory($version);
    
    // build patch files:
    foreach($patch_list as $k=>$v)
    {
        $patch_filename= preg_replace("/[./]*/", "_",$k);
        exec("diff -rupN -x .svn $k $v > ./resource/updates/$patch_filename.patch");
    }
}

function patch()
{
    global $patch_list;
    foreach($patch_list as $k=>$v)
    {
        $patch_filename= preg_replace("/[./]*/", "_",$k);
        exec("patch -p1 < ./resource/updates/$patch_filename.patch");
    }
}

function update($version= "trunk")
{
    generate_patch($version);
    patch();
}

This isn't perfect (it needs to address core CSS/HSS/JS merging, and needs to play nicely other VCS's), but it's a start toward better framework integration into our normal development workflow.

Comments:
No comments on this post yet.
powered by ploof. built and © andrew ettinger, 2009.