Changeset 2222
- Timestamp:
- 07/08/2008 14:47:59 (5 months ago)
- Location:
- box/trunk
- Files:
-
- 4 modified
-
bin/bbackupquery/BackupQueries.cpp (modified) (1 diff)
-
bin/bbstoreaccounts/bbstoreaccounts.cpp (modified) (7 diffs)
-
lib/common/Utils.cpp (modified) (1 diff)
-
lib/common/Utils.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbackupquery/BackupQueries.cpp
r2182 r2222 2191 2191 void BackupQueries::CommandUsageDisplayEntry(const char *Name, int64_t Size, int64_t HardLimit, int32_t BlockSize) 2192 2192 { 2193 std::cout << FormatUsageLineStart(Name ) <<2194 FormatUsageBar(Size, Size * BlockSize, HardLimit * BlockSize ) <<2193 std::cout << FormatUsageLineStart(Name, false) << 2194 FormatUsageBar(Size, Size * BlockSize, HardLimit * BlockSize, false) << 2195 2195 std::endl; 2196 2196 } -
box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
r2149 r2222 40 40 #define MAX_SOFT_LIMIT_SIZE 97 41 41 42 bool sMachineReadableOutput = false; 43 42 44 void CheckSoftHardLimits(int64_t SoftLimit, int64_t HardLimit) 43 45 { … … 72 74 { 73 75 return FormatUsageBar(Blocks, Blocks * BlockSizeOfDiscSet(DiscSet), 74 MaxBlocks * BlockSizeOfDiscSet(DiscSet)); 76 MaxBlocks * BlockSizeOfDiscSet(DiscSet), 77 sMachineReadableOutput); 75 78 } 76 79 … … 206 209 { 207 210 // Load in the account database 208 std::auto_ptr<BackupStoreAccountDatabase> db(BackupStoreAccountDatabase::Read(rConfig.GetKeyValue("AccountDatabase").c_str())); 211 std::auto_ptr<BackupStoreAccountDatabase> db( 212 BackupStoreAccountDatabase::Read( 213 rConfig.GetKeyValue("AccountDatabase").c_str())); 209 214 210 215 // Exists? … … 221 226 int discSet; 222 227 acc.GetAccountRoot(ID, rootDir, discSet); 223 std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID, rootDir, discSet, true /* ReadOnly */)); 228 std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID, 229 rootDir, discSet, true /* ReadOnly */)); 224 230 225 231 // Then print out lots of info 226 std::cout << FormatUsageLineStart("Account ID" ) <<232 std::cout << FormatUsageLineStart("Account ID", sMachineReadableOutput) << 227 233 BOX_FORMAT_ACCOUNT(ID) << std::endl; 228 std::cout << FormatUsageLineStart("Last object ID" ) <<234 std::cout << FormatUsageLineStart("Last object ID", sMachineReadableOutput) << 229 235 BOX_FORMAT_OBJECTID(info->GetLastObjectIDUsed()) << std::endl; 230 std::cout << FormatUsageLineStart("Used" ) <<236 std::cout << FormatUsageLineStart("Used", sMachineReadableOutput) << 231 237 BlockSizeToString(info->GetBlocksUsed(), 232 238 info->GetBlocksHardLimit(), discSet) << std::endl; 233 std::cout << FormatUsageLineStart("Old files" ) <<239 std::cout << FormatUsageLineStart("Old files", sMachineReadableOutput) << 234 240 BlockSizeToString(info->GetBlocksInOldFiles(), 235 241 info->GetBlocksHardLimit(), discSet) << std::endl; 236 std::cout << FormatUsageLineStart("Deleted files" ) <<242 std::cout << FormatUsageLineStart("Deleted files", sMachineReadableOutput) << 237 243 BlockSizeToString(info->GetBlocksInDeletedFiles(), 238 244 info->GetBlocksHardLimit(), discSet) << std::endl; 239 std::cout << FormatUsageLineStart("Directories" ) <<245 std::cout << FormatUsageLineStart("Directories", sMachineReadableOutput) << 240 246 BlockSizeToString(info->GetBlocksInDirectories(), 241 247 info->GetBlocksHardLimit(), discSet) << std::endl; 242 std::cout << FormatUsageLineStart("Soft limit" ) <<248 std::cout << FormatUsageLineStart("Soft limit", sMachineReadableOutput) << 243 249 BlockSizeToString(info->GetBlocksSoftLimit(), 244 250 info->GetBlocksHardLimit(), discSet) << std::endl; 245 std::cout << FormatUsageLineStart("Hard limit" ) <<251 std::cout << FormatUsageLineStart("Hard limit", sMachineReadableOutput) << 246 252 BlockSizeToString(info->GetBlocksHardLimit(), 247 253 info->GetBlocksHardLimit(), discSet) << std::endl; 248 std::cout << FormatUsageLineStart("Client store marker" ) <<254 std::cout << FormatUsageLineStart("Client store marker", sMachineReadableOutput) << 249 255 info->GetLastObjectIDUsed() << std::endl; 250 256 … … 429 435 " set numbers) with the specified soft and hard limits (in blocks\n" 430 436 " if suffixed with B, MB with M, GB with G)\n" 431 " info <account>\n"437 " info [-m] <account>\n" 432 438 " Prints information about the specified account including number\n" 433 " of blocks used. \n"439 " of blocks used. The -m option enable machine-readable output.\n" 434 440 " setlimit <accounts> <softlimit> <hardlimit>\n" 435 441 " Changes the limits of the account as specified. Numbers are\n" … … 465 471 // See if there's another entry on the command line 466 472 int c; 467 while((c = getopt(argc, (char * const *)argv, "c: ")) != -1)473 while((c = getopt(argc, (char * const *)argv, "c:m")) != -1) 468 474 { 469 475 switch(c) … … 474 480 break; 475 481 482 case 'm': 483 // enable machine readable output 484 sMachineReadableOutput = true; 485 break; 486 476 487 case '?': 477 488 default: -
box/trunk/lib/common/Utils.cpp
r2221 r2222 253 253 } 254 254 255 std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max) 255 std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max, 256 bool MachineReadable) 256 257 { 257 258 std::ostringstream result; 258 259 259 // Bar graph 260 char bar[17]; 261 unsigned int b = (int)((Bytes * (sizeof(bar)-1)) / Max); 262 if(b > sizeof(bar)-1) {b = sizeof(bar)-1;} 263 for(unsigned int l = 0; l < b; l++) 264 { 265 bar[l] = '*'; 266 } 267 for(unsigned int l = b; l < sizeof(bar) - 1; l++) 268 { 269 bar[l] = ' '; 270 } 271 bar[sizeof(bar)-1] = '\0'; 272 273 result << std::fixed << 274 std::setw(10) << Blocks << " blocks, " << 275 std::setw(10) << HumanReadableSize(Bytes) << ", " << 276 std::setw(3) << std::setprecision(0) << 277 ((Bytes*100)/Max) << "% |" << bar << "|"; 260 261 if (MachineReadable) 262 { 263 result << (Bytes >> 10) << " kB, " << 264 std::setprecision(0) << ((Bytes*100)/Max) << "%"; 265 } 266 else 267 { 268 // Bar graph 269 char bar[17]; 270 unsigned int b = (int)((Bytes * (sizeof(bar)-1)) / Max); 271 if(b > sizeof(bar)-1) {b = sizeof(bar)-1;} 272 for(unsigned int l = 0; l < b; l++) 273 { 274 bar[l] = '*'; 275 } 276 for(unsigned int l = b; l < sizeof(bar) - 1; l++) 277 { 278 bar[l] = ' '; 279 } 280 bar[sizeof(bar)-1] = '\0'; 281 282 result << std::fixed << 283 std::setw(10) << Blocks << " blocks, " << 284 std::setw(10) << HumanReadableSize(Bytes) << ", " << 285 std::setw(3) << std::setprecision(0) << 286 ((Bytes*100)/Max) << "% |" << bar << "|"; 287 } 278 288 279 289 return result.str(); 280 290 } 281 291 282 std::string FormatUsageLineStart(const std::string& rName) 283 { 284 std::ostringstream result; 285 result << std::setw(20) << std::right << rName << ": "; 292 std::string FormatUsageLineStart(const std::string& rName, 293 bool MachineReadable) 294 { 295 std::ostringstream result; 296 297 if (MachineReadable) 298 { 299 result << rName << ": "; 300 } 301 else 302 { 303 result << std::setw(20) << std::right << rName << ": "; 304 } 305 286 306 return result.str(); 287 307 } -
box/trunk/lib/common/Utils.h
r2127 r2222 32 32 int ObjectExists(const std::string& rFilename); 33 33 std::string HumanReadableSize(int64_t Bytes); 34 std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max); 35 std::string FormatUsageLineStart(const std::string& rName); 34 std::string FormatUsageBar(int64_t Blocks, int64_t Bytes, int64_t Max, 35 bool MachineReadable); 36 std::string FormatUsageLineStart(const std::string& rName, 37 bool MachineReadable); 36 38 37 39 #include "MemLeakFindOff.h"
