PDA

View Full Version : Little help with this simple script


vvmanoj
11-10-2010, 02:01 PM
I am in the process of writing this simple script to find out some directory sizes and do some cleaning. But I seem to have hit a brick wall. I am not sure what the issue is.

I have a simple UI and a proc assigned to a button. But for some reason the Query button will not work. (Only the query button has a proc assigned to it right now)

If I run the code from the script it works fine. Here is the code. Please note it works only under a Linux environment


// initialize variables
int $ma_cleanType = 0; // -- variable stores type of clean 1 = only incSave dir, 2 = both incSave and autoSave
string $ma_incSaveTok[]; // string stores tokenize result for inc save folder
string $ma_autoSaveTok[]; // string stores tokenize result for auto save folder
string $ma_incSaveDir;
string $ma_autoSaveDir;
string $ma_clwIncSizeFld; // text for displaying the size of inc save folder
string $ma_clwAutoSizeFld; // text for displaying the size of auto save folder

// Get the currently open scene work directory

$ma_workDir = `file -q -sn`;
$ma_workDir = `dirname $ma_workDir`;

$ma_incSaveDir = $ma_workDir + "/incrementalSave";
$ma_autoSaveDir = $ma_workDir + "/autosave";


// Build UI

if (`window -ex cleanup`)

{

deleteUI cleanup;

}

$ma_cleanupWin = `window -title "Cleanup v 1.0" cleanup`;

$ma_clwLayout1 = `columnLayout -height 300` ;

setParent $ma_clwLayout1;

separator -style "none" -height 5;

$ma_clwLayout2 = `columnLayout -columnAttach "left" 5 -rowSpacing 5 -columnWidth 390 -columnAlign "left" -height 240`;

text -font "boldLabelFont" "Scene location: ";

separator -style "none" -height 5;

textField -width 350 -editable 0 -text $ma_workDir;

separator -style "none" -height 5;

text -font "boldLabelFont" "Incremental Save Size: ";

separator -style "none" -height 2;

$ma_clwIncSizeFld = `text -width 100 -label ""`;

separator -style "none" -height 5;

text -font "boldLabelFont" "Auto Save Size: ";

separator -style "none" -height 2;

$ma_clwAutoSizeFld = `text -width 100 -label ""`;

separator -style "in" -height 10;

$ma_clwLayout3 = `rowLayout -numberOfColumns 2
-columnWidth2 150 150`;

setParent $ma_clwLayout3;

button -width 60 -label "Query" -command "clwQuery()";

button -width 60 -label "Cleanup!" -command "clwCleanup()";


showWindow $ma_cleanupWin;

window -e -width 400 -height 300 $ma_cleanupWin;


// the procedures


proc clwQuery()

{
int $ma_cleanType;
string $ma_incSaveTok[];
string $ma_autoSaveTok[];
string $ma_incSaveDir;
string $ma_autoSaveDir;
string $ma_clwIncSizeFld;
string $ma_clwAutoSizeFld;
string $ma_workDir;
string $ma_incSaveSize;
string $ma_autoSaveSize;

// Test for folders and find their sizes and update UI


if (`filetest -d $ma_incSaveDir` == 1)
{
$ma_cleanType = 1;
$ma_incSaveSize = system ("du -sh " + $ma_incSaveDir);
tokenize $ma_incSaveSize $ma_incSaveTok;
text -e -label $ma_incSaveTok[0] $ma_clwIncSizeFld;
}


if (`filetest -d $ma_autoSaveDir` == 1)
{
$ma_cleanType = 2;
$ma_autoSaveSize = system ("du -sh " + $ma_autoSaveDir);
tokenize $ma_autoSaveSize $ma_autoSaveTok;
text -e -label $ma_autoSaveTok[0] $ma_clwAutoSizeFld;
}

// throw error if both directories not found!

if ($ma_cleanType == 0)
{
warning "No Directories found! Nothing to clean!";
}

}



Could someone throw some light on it? Any help much appreciated! :)

Thanks!

CGTalk Moderation
11-10-2010, 02:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.