[Box Backup-commit] COMMIT r2222 - in box/trunk: bin/bbackupquery bin/bbstoreaccounts lib/common
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Thu, 7 Aug 2008 14:48:00 +0100 (BST)
Author: chris
Date: 2008-08-07 14:47:59 +0100 (Thu, 07 Aug 2008)
New Revision: 2222
Modified:
box/trunk/bin/bbackupquery/BackupQueries.cpp
box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
box/trunk/lib/common/Utils.cpp
box/trunk/lib/common/Utils.h
Log:
Add machine-readable output mode (with -m option) to bbstoreaccounts info.
Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp 2008-08-06 18:28:10 UTC (rev 2221)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp 2008-08-07 13:47:59 UTC (rev 2222)
@@ -2190,8 +2190,8 @@
// --------------------------------------------------------------------------
void BackupQueries::CommandUsageDisplayEntry(const char *Name, int64_t Size, int64_t HardLimit, int32_t BlockSize)
{
- std::cout << FormatUsageLineStart(Name) <<
- FormatUsageBar(Size, Size * BlockSize, HardLimit * BlockSize) <<
+ std::cout << FormatUsageLineStart(Name, false) <<
+ FormatUsageBar(Size, Size * BlockSize, HardLimit * BlockSize, false) <<
std::endl;
}
Modified: box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
===================================================================
--- box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp 2008-08-06 18:28:10 UTC (rev 2221)
+++ box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp 2008-08-07 13:47:59 UTC (rev 2222)
@@ -39,6 +39,8 @@
// max size of soft limit as percent of hard limit
#define MAX_SOFT_LIMIT_SIZE 97
+bool sMachineReadableOutput = false;
+
void CheckSoftHardLimits(int64_t SoftLimit, int64_t HardLimit)
{
if(SoftLimit >= HardLimit)
@@ -71,7 +73,8 @@
std::string BlockSizeToString(int64_t Blocks, int64_t MaxBlocks, int DiscSet)
{
return FormatUsageBar(Blocks, Blocks * BlockSizeOfDiscSet(DiscSet),
- MaxBlocks * BlockSizeOfDiscSet(DiscSet));
+ MaxBlocks * BlockSizeOfDiscSet(DiscSet),
+ sMachineReadableOutput);
}
int64_t SizeStringToBlocks(const char *string, int DiscSet)
@@ -205,7 +208,9 @@
int AccountInfo(Configuration &rConfig, int32_t ID)
{
// Load in the account database
- std::auto_ptr<BackupStoreAccountDatabase> db(BackupStoreAccountDatabase::Read(rConfig.GetKeyValue("AccountDatabase").c_str()));
+ std::auto_ptr<BackupStoreAccountDatabase> db(
+ BackupStoreAccountDatabase::Read(
+ rConfig.GetKeyValue("AccountDatabase").c_str()));
// Exists?
if(!db->EntryExists(ID))
@@ -220,32 +225,33 @@
std::string rootDir;
int discSet;
acc.GetAccountRoot(ID, rootDir, discSet);
- std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID, rootDir, discSet, true /* ReadOnly */));
+ std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID,
+ rootDir, discSet, true /* ReadOnly */));
// Then print out lots of info
- std::cout << FormatUsageLineStart("Account ID") <<
+ std::cout << FormatUsageLineStart("Account ID", sMachineReadableOutput) <<
BOX_FORMAT_ACCOUNT(ID) << std::endl;
- std::cout << FormatUsageLineStart("Last object ID") <<
+ std::cout << FormatUsageLineStart("Last object ID", sMachineReadableOutput) <<
BOX_FORMAT_OBJECTID(info->GetLastObjectIDUsed()) << std::endl;
- std::cout << FormatUsageLineStart("Used") <<
+ std::cout << FormatUsageLineStart("Used", sMachineReadableOutput) <<
BlockSizeToString(info->GetBlocksUsed(),
info->GetBlocksHardLimit(), discSet) << std::endl;
- std::cout << FormatUsageLineStart("Old files") <<
+ std::cout << FormatUsageLineStart("Old files", sMachineReadableOutput) <<
BlockSizeToString(info->GetBlocksInOldFiles(),
info->GetBlocksHardLimit(), discSet) << std::endl;
- std::cout << FormatUsageLineStart("Deleted files") <<
+ std::cout << FormatUsageLineStart("Deleted files", sMachineReadableOutput) <<
BlockSizeToString(info->GetBlocksInDeletedFiles(),
info->GetBlocksHardLimit(), discSet) << std::endl;
- std::cout << FormatUsageLineStart("Directories") <<
+ std::cout << FormatUsageLineStart("Directories", sMachineReadableOutput) <<
BlockSizeToString(info->GetBlocksInDirectories(),
info->GetBlocksHardLimit(), discSet) << std::endl;
- std::cout << FormatUsageLineStart("Soft limit") <<
+ std::cout << FormatUsageLineStart("Soft limit", sMachineReadableOutput) <<
BlockSizeToString(info->GetBlocksSoftLimit(),
info->GetBlocksHardLimit(), discSet) << std::endl;
- std::cout << FormatUsageLineStart("Hard limit") <<
+ std::cout << FormatUsageLineStart("Hard limit", sMachineReadableOutput) <<
BlockSizeToString(info->GetBlocksHardLimit(),
info->GetBlocksHardLimit(), discSet) << std::endl;
- std::cout << FormatUsageLineStart("Client store marker") <<
+ std::cout << FormatUsageLineStart("Client store marker", sMachineReadableOutput) <<
info->GetLastObjectIDUsed() << std::endl;
return 0;
@@ -428,9 +434,9 @@
" specified raidfile disc set number (see raidfile.conf for valid\n"
" set numbers) with the specified soft and hard limits (in blocks\n"
" if suffixed with B, MB with M, GB with G)\n"
-" info <account>\n"
+" info [-m] <account>\n"
" Prints information about the specified account including number\n"
-" of blocks used.\n"
+" of blocks used. The -m option enable machine-readable output.\n"
" setlimit <accounts> <softlimit> <hardlimit>\n"
" Changes the limits of the account as specified. Numbers are\n"
" interpreted as for the 'create' command (suffixed with B, M or G)\n"
@@ -464,7 +470,7 @@
// See if there's another entry on the command line
int c;
- while((c = getopt(argc, (char * const *)argv, "c:")) != -1)
+ while((c = getopt(argc, (char * const *)argv, "c:m")) != -1)
{
switch(c)
{
@@ -473,6 +479,11 @@
configFilename = optarg;
break;
+ case 'm':
+ // enable machine readable output
+ sMachineReadableOutput = true;
+ break;
+
case '?':
default:
PrintUsageAndExit();
Modified: box/trunk/lib/common/Utils.cpp
===================================================================
--- box/trunk/lib/common/Utils.cpp 2008-08-06 18:28:10 UTC (rev 2221)
+++ box/trunk/lib/common/Utils.cpp 2008-08-07 13:47:59 UTC (rev 2222)
@@ -252,36 +252,56 @@
return result.str();
}
-std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max)
+std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max,
+ bool MachineReadable)
{
std::ostringstream result;
- // Bar graph
- char bar[17];
- unsigned int b = (int)((Bytes * (sizeof(bar)-1)) / Max);
- if(b > sizeof(bar)-1) {b = sizeof(bar)-1;}
- for(unsigned int l = 0; l < b; l++)
+
+ if (MachineReadable)
{
- bar[l] = '*';
+ result << (Bytes >> 10) << " kB, " <<
+ std::setprecision(0) << ((Bytes*100)/Max) << "%";
}
- for(unsigned int l = b; l < sizeof(bar) - 1; l++)
+ else
{
- bar[l] = ' ';
+ // Bar graph
+ char bar[17];
+ unsigned int b = (int)((Bytes * (sizeof(bar)-1)) / Max);
+ if(b > sizeof(bar)-1) {b = sizeof(bar)-1;}
+ for(unsigned int l = 0; l < b; l++)
+ {
+ bar[l] = '*';
+ }
+ for(unsigned int l = b; l < sizeof(bar) - 1; l++)
+ {
+ bar[l] = ' ';
+ }
+ bar[sizeof(bar)-1] = '\0';
+
+ result << std::fixed <<
+ std::setw(10) << Blocks << " blocks, " <<
+ std::setw(10) << HumanReadableSize(Bytes) << ", " <<
+ std::setw(3) << std::setprecision(0) <<
+ ((Bytes*100)/Max) << "% |" << bar << "|";
}
- bar[sizeof(bar)-1] = '\0';
- result << std::fixed <<
- std::setw(10) << Blocks << " blocks, " <<
- std::setw(10) << HumanReadableSize(Bytes) << ", " <<
- std::setw(3) << std::setprecision(0) <<
- ((Bytes*100)/Max) << "% |" << bar << "|";
-
return result.str();
}
-std::string FormatUsageLineStart(const std::string& rName)
+std::string FormatUsageLineStart(const std::string& rName,
+ bool MachineReadable)
{
- std::ostringstream result;
- result << std::setw(20) << std::right << rName << ": ";
+ std::ostringstream result;
+
+ if (MachineReadable)
+ {
+ result << rName << ": ";
+ }
+ else
+ {
+ result << std::setw(20) << std::right << rName << ": ";
+ }
+
return result.str();
}
Modified: box/trunk/lib/common/Utils.h
===================================================================
--- box/trunk/lib/common/Utils.h 2008-08-06 18:28:10 UTC (rev 2221)
+++ box/trunk/lib/common/Utils.h 2008-08-07 13:47:59 UTC (rev 2222)
@@ -31,8 +31,10 @@
};
int ObjectExists(const std::string& rFilename);
std::string HumanReadableSize(int64_t Bytes);
-std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max);
-std::string FormatUsageLineStart(const std::string& rName);
+std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max,
+ bool MachineReadable);
+std::string FormatUsageLineStart(const std::string& rName,
+ bool MachineReadable);
#include "MemLeakFindOff.h"