[Box Backup] machinereadble output bbackupquery - help needed

Torsten boxbackup@boxbackup.org
Thu, 16 Oct 2008 18:35:32 +0200


--Boundary-00=_W129Iy+G8GCKTr1
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I tried to change box backup to have an machine reabable option 
for 'bbackupqery usage quit'.

It is well  prepared because FormatUsageLineStart() and FormatUsageBar() have 
already an option for this.

The problem is the command line option for bbackupquery. I do not know how to 
exactly handle this. The attached patch does not really work, it only shows 
where i changed the source.

Is it possible to add such a function into the trunk? Can anybody help with 
this?

thanks
  Torsten

--Boundary-00=_W129Iy+G8GCKTr1
Content-Type: text/x-diff;
  charset="iso 8859-15";
  name="bbackupquery_machinereadable_output_svn2352.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="bbackupquery_machinereadable_output_svn2352.diff"

Index: bin/bbackupquery/BackupQueries.cpp
===================================================================
--- bin/bbackupquery/BackupQueries.cpp	(Revision 2352)
+++ bin/bbackupquery/BackupQueries.cpp	(Arbeitskopie)
@@ -63,6 +63,8 @@
 #define COMPARE_RETURN_ERROR		3
 #define COMMAND_RETURN_ERROR		4
 
+bool mMachineReadableOutput = false; 
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -72,7 +74,7 @@
 //
 // --------------------------------------------------------------------------
 BackupQueries::BackupQueries(BackupProtocolClient &rConnection,
-	const Configuration &rConfiguration, bool readWrite)
+	const Configuration &rConfiguration, bool readWrite, bool mMachineReadableOutput)
 	: mReadWrite(readWrite),
 	  mrConnection(rConnection),
 	  mrConfiguration(rConfiguration),
@@ -86,6 +88,7 @@
 	#else
 	mRunningAsRoot = (::geteuid() == 0);
 	#endif
+	::mMachineReadableOutput = mMachineReadableOutput;
 }
 
 // --------------------------------------------------------------------------
@@ -1203,6 +1206,7 @@
 	: mQuickCompare(false),
 	  mIgnoreExcludes(false),
 	  mIgnoreAttributes(false),
+	  mMachineReadableOutput(false),
 	  mDifferences(0),
 	  mDifferencesExplainedByModTime(0),
 	  mUncheckedFiles(0),
@@ -1268,6 +1272,7 @@
 	params.mQuietCompare = opts['Q'];
 	params.mIgnoreExcludes = opts['E'];
 	params.mIgnoreAttributes = opts['A'];
+	params.mMachineReadableOutput = opts['m'];
 	
 	// Try and work out the time before which all files should be on the server
 	{
@@ -2275,8 +2280,8 @@
 // --------------------------------------------------------------------------
 void BackupQueries::CommandUsageDisplayEntry(const char *Name, int64_t Size, int64_t HardLimit, int32_t BlockSize)
 {
-	std::cout << FormatUsageLineStart(Name, false) <<
-		FormatUsageBar(Size, Size * BlockSize, HardLimit * BlockSize, false) <<
+	std::cout << FormatUsageLineStart(Name, mMachineReadableOutput) <<
+		FormatUsageBar(Size, Size * BlockSize, HardLimit * BlockSize, mMachineReadableOutput) <<
 		std::endl;
 }
 
Index: bin/bbackupquery/BackupQueries.h
===================================================================
--- bin/bbackupquery/BackupQueries.h	(Revision 2352)
+++ bin/bbackupquery/BackupQueries.h	(Arbeitskopie)
@@ -32,7 +32,8 @@
 public:
 	BackupQueries(BackupProtocolClient &rConnection,
 		const Configuration &rConfiguration,
-		bool readWrite);
+		bool readWrite,
+		bool mMachineReadbleOutput);
 	~BackupQueries();
 private:
 	BackupQueries(const BackupQueries &);
@@ -78,6 +79,7 @@
 		bool mQuietCompare;
 		bool mIgnoreExcludes;
 		bool mIgnoreAttributes;
+		bool mMachineReadableOutput;
 		int mDifferences;
 		int mDifferencesExplainedByModTime;
 		int mUncheckedFiles;
Index: bin/bbackupquery/bbackupquery.cpp
===================================================================
--- bin/bbackupquery/bbackupquery.cpp	(Revision 2352)
+++ bin/bbackupquery/bbackupquery.cpp	(Arbeitskopie)
@@ -108,6 +108,7 @@
 	
 	// Flags
 	bool readWrite = false;
+	bool mMachineReadableOutput = false;
 
 	Logging::SetProgramName("bbackupquery");
 
@@ -118,10 +119,10 @@
 	#endif
 
 #ifdef WIN32
-	const char* validOpts = "qvwuc:l:W:";
+	const char* validOpts = "qvwucm:l:W:";
 	bool unicodeConsole = false;
 #else
-	const char* validOpts = "qvwc:l:W:";
+	const char* validOpts = "qvwcm:l:W:";
 #endif
 
 	// See if there's another entry on the command line
@@ -187,6 +188,11 @@
 			}
 			break;
 
+		case 'm':
+			// machine readable output
+			mMachineReadableOutput = true;
+			break;
+
 #ifdef WIN32
 		case 'u':
 			unicodeConsole = true;
@@ -308,7 +314,7 @@
 	if(!quiet) printf("Login complete.\n\nType \"help\" for a list of commands.\n\n");
 	
 	// Set up a context for our work
-	BackupQueries context(connection, conf, readWrite);
+	BackupQueries context(connection, conf, readWrite, mMachineReadableOutput);
 	
 	// Start running commands... first from the command line
 	{

--Boundary-00=_W129Iy+G8GCKTr1--