Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up on #109

commit 0b2a8c0a546bd562bf4037757b652356a4e0a7f8 1 parent cb60205
@nestal nestal authored
View
7 README
@@ -50,8 +50,13 @@ Enjoy!
Version History:
-Grive v0.3: Bug fix release
+Grive v0.3: Bug fix & minor feature release
Fixed bugs:
#93: missing reference count increment in one of the Json constructors
#82: retry for HTTP error 500 & 503
#77: Fixed a bug where grive crashed on the first run.
+
+New features:
+ #87: support for revisions
+ #86: partial sync (contributed by justin at tierramedia.com)
+
View
124 grive/src/main.cc
@@ -51,6 +51,7 @@ const std::string defaultConfigFileName = ".grive";
const char *configFileEnvironmentVariable = "GR_CONFIG";
using namespace gr ;
+namespace po = boost::program_options;
// libgcrypt insist this to be done in application, not library
void InitGCrypt()
@@ -65,18 +66,46 @@ void InitGCrypt()
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
}
-int Main( int argc, char **argv )
+void InitLog( const po::variables_map& vm )
{
- InitGCrypt() ;
-
- std::string rootFolder = defaultRootFolder;
-
std::auto_ptr<log::CompositeLog> comp_log(new log::CompositeLog) ;
LogBase* console_log = comp_log->Add( std::auto_ptr<LogBase>( new log::DefaultLog ) ) ;
+
+ if ( vm.count( "log" ) )
+ {
+ std::auto_ptr<LogBase> file_log(new log::DefaultLog( vm["log"].as<std::string>() )) ;
+ file_log->Enable( log::debug ) ;
+ file_log->Enable( log::verbose ) ;
+ file_log->Enable( log::info ) ;
+ file_log->Enable( log::warning ) ;
+ file_log->Enable( log::error ) ;
+ file_log->Enable( log::critical ) ;
+
+ // log grive version to log file
+ file_log->Log( log::Fmt("grive version " VERSION " " __DATE__ " " __TIME__), log::verbose ) ;
+ file_log->Log( log::Fmt("current time: %1%") % DateTime::Now(), log::verbose ) ;
+
+ comp_log->Add( file_log ) ;
+ }
- Json options ;
+ if ( vm.count( "verbose" ) )
+ {
+ console_log->Enable( log::verbose ) ;
+ }
- namespace po = boost::program_options;
+ if ( vm.count( "debug" ) )
+ {
+ console_log->Enable( log::verbose ) ;
+ console_log->Enable( log::debug ) ;
+ }
+ LogBase::Inst( std::auto_ptr<LogBase>(comp_log.release()) ) ;
+}
+
+int Main( int argc, char **argv )
+{
+ InitGCrypt() ;
+
+ std::string rootFolder = defaultRootFolder;
// construct the program options
po::options_description desc( "Grive options" );
@@ -105,56 +134,41 @@ int Main( int argc, char **argv )
std::cout << desc << std::endl ;
return 0 ;
}
-
- boost::shared_ptr<Config> config ;
-
- if ( vm.count( "log" ) )
- {
- std::auto_ptr<LogBase> file_log(new log::DefaultLog( vm["log"].as<std::string>() )) ;
- file_log->Enable( log::debug ) ;
- file_log->Enable( log::verbose ) ;
- file_log->Enable( log::info ) ;
- file_log->Enable( log::warning ) ;
- file_log->Enable( log::error ) ;
- file_log->Enable( log::critical ) ;
-
- // log grive version to log file
- file_log->Log( log::Fmt("grive version " VERSION " " __DATE__ " " __TIME__), log::verbose ) ;
- file_log->Log( log::Fmt("current time: %1%") % DateTime::Now(), log::verbose ) ;
-
- comp_log->Add( file_log ) ;
- }
- if ( vm.count( "verbose" ) )
+ else if ( vm.count( "version" ) )
{
- console_log->Enable( log::verbose ) ;
+ std::cout
+ << "grive version " << VERSION << ' ' << __DATE__ << ' ' << __TIME__ << std::endl ;
+ return 0 ;
}
+
+ // initialize logging
+ InitLog(vm) ;
- options.Add( "log-xml", Json(vm.count("log-xml") > 0) ) ;
- options.Add( "new-rev", Json(vm.count("new-rev") > 0) ) ;
+ boost::shared_ptr<Config> config ;
- if ( vm.count( "debug" ) )
- {
- console_log->Enable( log::verbose ) ;
- console_log->Enable( log::debug ) ;
- }
-
- // config file will be (in order of preference)
- // value specified in environment string
- // value specified in defaultConfigFileName in path from commandline --path
- // value specified in defaultConfigFileName in current directory
+ // config file will be (in order of preference)
+ // value specified in environment string
+ // value specified in defaultConfigFileName in path from commandline --path
+ // value specified in defaultConfigFileName in current directory
const char *envConfigFileName = ::getenv( configFileEnvironmentVariable ) ;
- if (envConfigFileName) {
- config.reset(new Config(envConfigFileName));
+ if (envConfigFileName) {
+ config.reset(new Config(envConfigFileName));
- } else if ( vm.count( "path" ) ) {
- rootFolder = vm["path"].as<std::string>();
- config.reset(new Config( fs::path(rootFolder) / fs::path(defaultConfigFileName) ));
+ } else if ( vm.count( "path" ) ) {
+ rootFolder = vm["path"].as<std::string>();
+ config.reset(new Config( fs::path(rootFolder) / fs::path(defaultConfigFileName) ));
- } else {
- config.reset(new Config( defaultConfigFileName) );
- }
+ } else {
+ config.reset(new Config( defaultConfigFileName) );
+ }
- Log( "config file name %1%", config->ConfigFile().string(), log::verbose );
+ // misc options
+ Json options ;
+ options.Add( "log-xml", Json(vm.count("log-xml") > 0) ) ;
+ options.Add( "new-rev", Json(vm.count("new-rev") > 0) ) ;
+ options.Add( "force", Json(vm.count("force") > 0 ) ) ;
+
+ Log( "config file name %1%", config->ConfigFile().string(), log::verbose );
if ( vm.count( "auth" ) )
{
@@ -177,18 +191,6 @@ int Main( int argc, char **argv )
config->Get().Add( "refresh_token", Json( token.RefreshToken() ) ) ;
config->Save() ;
}
- if ( vm.count( "version" ) )
- {
- std::cout
- << "grive version " << VERSION << ' ' << __DATE__ << ' ' << __TIME__ << std::endl ;
- return 0 ;
- }
- if ( vm.count( "force" ) )
- {
- options.Add( "force", Json(true) ) ;
- }
-
- LogBase::Inst( std::auto_ptr<LogBase>(comp_log.release()) ) ;
std::string refresh_token ;
try
View
3  libgrive/CMakeLists.txt
@@ -6,7 +6,7 @@ find_package(LibGcrypt REQUIRED)
find_package(JSONC REQUIRED)
find_package(CURL REQUIRED)
find_package(EXPAT REQUIRED)
-find_package(Boost 1.40.0 COMPONENTS filesystem system REQUIRED)
+find_package(Boost 1.40.0 COMPONENTS program_options filesystem system REQUIRED)
find_package(BFD)
find_package(CppUnit)
find_package(Iberty)
@@ -126,6 +126,7 @@ IF ( CPPUNIT_FOUND )
target_link_libraries( unittest
grive
${CPPUNIT_LIBRARY}
+ ${Boost_LIBRARIES}
)
ENDIF ( CPPUNIT_FOUND )
View
18 libgrive/src/util/Config.cc
@@ -21,18 +21,21 @@
#include "util/StdioFile.hh"
+#include <boost/program_options.hpp>
+
#include <iostream>
#include <iterator>
-using namespace gr;
+namespace gr {
-Config::Config(const fs::path& configFile)
- : m_configFile(configFile)
- , m_cfg( Read() )
+Config::Config(const fs::path& configFile) :
+ m_configFile(configFile),
+ m_cfg( Read() )
{
- if (configFile.empty()) {
- throw Error() << expt::ErrMsg("Config cannot be initalised with an empty string.");
- }
+ if (configFile.empty())
+ {
+ throw Error() << expt::ErrMsg("Config cannot be initalised with an empty string.");
+ }
}
const fs::path& Config::ConfigFile() const
@@ -63,3 +66,4 @@ Json Config::Read()
}
}
+} // end of namespace
View
6 libgrive/src/util/Config.hh
@@ -35,14 +35,14 @@ public :
Json& Get() ;
void Save() ;
- const fs::path &ConfigFile() const;
+ const fs::path &ConfigFile() const;
private :
Json Read() ;
private :
- const fs::path m_configFile;
- Json m_cfg ;
+ const fs::path m_configFile;
+ Json m_cfg ;
} ;
} // end of namespace
Please sign in to comment.
Something went wrong with that request. Please try again.