コード例 #1
0
/*!

 */
bool
Strategy::init( CmdLineParser & cmd_parser )
{
    ParamMap param_map( "HELIOS_base options" );

    // std::string fconf;
    //param_map.add()
    //    ( "fconf", "", &fconf, "another formation file." );

    //
    //
    //

    if ( cmd_parser.count( "help" ) > 0 )
    {
        param_map.printHelp( std::cout );
        return false;
    }

    //
    //
    //

    cmd_parser.parse( param_map );

    return true;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: nadezhdin-ivan/shdt
// Parses options specified in the first line of the file with 'filename'.
// Returns: success?
// On success, public member variables shall contain interpreted program
// parameters.
bool Options::ParseConfigFile(string filename, bool validate /* = true */) {
	// avoid endless recursion!
	//printf("Parsing: '%s'...\n", filename.c_str());
	if (parsedConfigFiles.find(filename) != parsedConfigFiles.end()) {
		fprintf(stderr, "Cyclic list of configuration files is not allowed!\nStopping at file named: '%s'.\n", filename.c_str());
		return true;
	}

	const int MAX_LINE_LEN = 1024;
	char line[MAX_LINE_LEN+1] = {0};

	FILE* in = fopen(filename.c_str(), "r+t");
	if (!in) {
		fprintf(stderr, "Failed to open config file named: '%s'.\n", filename.c_str());
		return false;
	}
	fgets(line, MAX_LINE_LEN, in);
	fclose(in);

	// add this file to read config files set
	parsedConfigFiles.insert(filename);

	CmdLineParser cmdline = cmdline_prototype;
	if (!cmdline.Parse(line, true)) {
		fprintf(stderr, "Syntax error in config file: '%s'. \n", filename.c_str());
		return false;
	}
	Store(cmdline);

	return validate ? Validate() : true;
}
コード例 #3
0
/*!

 */
bool
SampleTrainer::initImpl( CmdLineParser & cmd_parser )
{
    bool result = TrainerAgent::initImpl( cmd_parser );

#if 0
    ParamMap my_params;

    std::string formation_conf;
    my_map.add()
        ( &conf_path, "fconf" )
        ;

    cmd_parser.parse( my_params );
#endif

    if ( cmd_parser.failed() )
    {
        std::cerr << "coach: ***WARNING*** detected unsupported options: ";
        cmd_parser.print( std::cerr );
        std::cerr << std::endl;
    }

    if ( ! result )
    {
        return false;
    }

    //////////////////////////////////////////////////////////////////
    // Add your code here.
    //////////////////////////////////////////////////////////////////

    return true;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: vkevroletin/Moroz
int main(int argc, char* argv[]) {
  CmdLineParser cmdp;
  if (false == cmdp.parse_cmd_line(argc, argv)) {
    cerr << "    error: " << cmdp.last_error << "\n";
    cmdp.print_help();
  } else {
    BaseCompressor* zip = cmdp.compression == CmdLineParser:: COMPR_HAFFMAN ?
      (BaseCompressor*) new Haffman() : (BaseCompressor*) new LZW();
    try {
      switch (cmdp.action) {
      case (CmdLineParser::ACT_COMPRESSION): {
        zip->compress(cmdp.files);
      } break;
      case (CmdLineParser::ACT_DECOMPRESSION): {
        zip->decompress(cmdp.files[0]);
      } break;
      case (CmdLineParser::ACT_PRINT_HELP):{
        cmdp.print_help();
      }
      }
    }
    catch (Error& e) {
      std::cerr << e.message();
    }
  }

  return 0;
}
コード例 #5
0
ファイル: start_slave.cpp プロジェクト: norouzi4d/sector
int main(int argc, char** argv)
{
   cout << SectorVersionString << endl;

   SlaveConf global_conf;

   CmdLineParser clp;
   clp.parse(argc, argv);

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "mh")
         global_conf.m_strMasterHost = i->second;
      else if (i->first == "mp")
         global_conf.m_iMasterPort = atoi(i->second.c_str());
      else if (i->first == "h")
      {
         global_conf.m_strHomeDir = i->second;
      }
      else if (i->first == "ds")
         global_conf.m_llMaxDataSize = atoll(i->second.c_str()) * 1024 * 1024;
      else if (i->first == "log")
         global_conf.m_iLogLevel = atoi(i->second.c_str());
      else
      {
         cout << "warning: unrecognized flag " << i->first << endl;
         help();
      }
   }

   string base = "";
   if (clp.m_vParams.size() == 1)
      base = clp.m_vParams.front();
   else if (clp.m_vParams.size() > 1)
      cout << "warning: wrong parameters ignored.\n";

   Slave s;

   if (s.init(&base, &global_conf) < 0)
   {
      cout << "error: failed to initialize the slave. check slave configurations.\n";
      return-1;
   }

   if (s.connect() < 0)
   {
      cout << "error: failed to connect to the master, or the connection request is rejected.\n";
      return -1;
   }

   s.run();

   s.close();

   return 0;
}
コード例 #6
0
 /**
  * Creates a command line parser initialized with default values.
  * @return a command line parser initialized with default values.
  */
 CmdLineParser get_cmd_line_parser() {
   CmdLineParser parser;
   parser.add_legal("-h --help -L --list -v --verbose -V --version -a --all -f --conformity --conformity-format --max-time");
   const int argc = 3;
   const char *defaults[argc] = {
     "--conformity-format=*Test|test_*|*",
     "-f=%p::%n - %m (%ts)%N(Registered at %f:%l)",
     "--max-time=1e+10",
   };
   parser.parse(argc, defaults);
   CPUNIT_ITRACE("EntryPoint - Default arguments:"<<parser.to_string());
   return parser;
 }
コード例 #7
0
bool parseCommandLine(int argc, char **argv, CmdLineParser &clp, ConfigInput &config)
{
  if(!clp.parseCmdLine(argc, argv))
  {
    clp.printUsage();
    return false;
  }

  config.listenPort = ((CmdLineOptionInt*)  clp.getCmdLineOption(ARG_LISTEN_PORT))->getValue();
  config.isVerbose =  ((CmdLineOptionFlag*) clp.getCmdLineOption(ARG_VERBOSE))->getValue();

  return true;
}
コード例 #8
0
  /**
   * If you have extra command line parameters, you may use this method to start CPUnit
   * after you have done your own. You should use {@link #get_cmd_line_parser()} to obtain
   * a parser which is already set up to accept the CPUnit specific command line parameters,
   * and then use CmdLineParser.add_legal to specify the arguments you expect in addition.
   * 
   * @param parser A parser contaiing the command line arguments, excluding the program name.
   *               I.e. from main(int& argc,char** args), the parser would be called as
   *               {@link CmdLineParser#parse(const int, const char**) parser.parse(arcg-1,args+1)}.
   * @return 0 if all tests succeed, and >0 elsewise.
  */
  int main(const CmdLineParser &parser) {

    AutoDisposer ad;
    try {
      CPUNIT_ITRACE("EntryPoint - Actual arguments:"<<parser.to_string());

      std::vector<std::string> patterns = parser.program_input();
      if (patterns.size() == 0) { 
	patterns.push_back("*");
      }
      
      if(parser.has_one_of("-h --help")) {
	usage();
	return 0;
      }
      if(parser.has_one_of("-L --list")) {
	list_tests(patterns);
	return 0;
      }
      if(parser.has_one_of("-V --version")) {
	print_version_info();
	return 0;
      }
      
      const bool verbose    = parser.has("-v") || parser.has("--verbose");
      const bool robust     = parser.has("-a") || parser.has("--all");
      const bool conformity = parser.has("--conformity");
      
      CPUNIT_ITRACE("EntryPoint - verbose="<<verbose<<" robust="<<robust<<" conformity="<<conformity);
      
      bool conform = true;
      if (conformity) {
	std::vector<std::string> conf_patterns = get_conformity_format(parser);
	const int num_conformity_breaches = conformity_report(patterns, conf_patterns[0], conf_patterns[1], conf_patterns[2], verbose, std::cout);
	std::cout<<"There where "<<num_conformity_breaches<<" conformity breaches."<<std::endl;
	conform = num_conformity_breaches == 0;
      }

      const std::string report_format = parser.value_of<std::string>(error_format_token);
      const double max_time = parser.value_of<double>(max_time_token);
      const std::vector<cpunit::ExecutionReport> result = cpunit::TestExecutionFacade().execute(patterns, max_time, verbose, robust);
      bool all_well = report_result(result, report_format, std::cout);
      
      int exit_value = 0;
      if (!all_well) {
	exit_value |= 0x1;
      }
      if(!conform) {
	exit_value |= 0x2;
      }
      return exit_value;
    } catch (AssertionException &e) {
      std::cout<<"Terminated due to AssertionException: "<<std::endl<<e.what()<<std::endl;
      return 1;
    }
  }
コード例 #9
0
ファイル: sample_player.cpp プロジェクト: 4SkyNet/HFO
/*!

 */
bool
SamplePlayer::initImpl( CmdLineParser & cmd_parser )
{
    bool result = PlayerAgent::initImpl( cmd_parser );

    // read additional options
    result &= Strategy::instance().init( cmd_parser );

    rcsc::ParamMap my_params( "Additional options" );
#if 0
    std::string param_file_path = "params";
    param_map.add()
    ( "param-file", "", &param_file_path, "specified parameter file" );
#endif

    cmd_parser.parse( my_params );

    if ( cmd_parser.count( "help" ) > 0 )
    {
        my_params.printHelp( std::cout );
        return false;
    }

    if ( cmd_parser.failed() )
    {
        std::cerr << "player: ***WARNING*** detected unsuppprted options: ";
        cmd_parser.print( std::cerr );
        std::cerr << std::endl;
    }

    if ( ! result )
    {
        return false;
    }

    if ( ! Strategy::instance().read( config().configDir() ) )
    {
        std::cerr << "***ERROR*** Failed to read team strategy." << std::endl;
        return false;
    }

    if ( KickTable::instance().read( config().configDir() + "/kick-table" ) )
    {
        std::cerr << "Loaded the kick table: ["
                  << config().configDir() << "/kick-table]"
                  << std::endl;
    }

    return true;
}
コード例 #10
0
ファイル: sysinfo.cpp プロジェクト: norouzi4d/sector
int main(int argc, char** argv)
{
   cout << SectorVersionString << endl;

   Sector client;
   if (Utility::login(client) < 0)
      return -1;

   bool address = false;

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help();
      return -1;
   }

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "a")
         address = true;
      else
      {
         help();
         return -1;
      }
   }

   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if (*i == "a")
         address = true;
      else
      {
         help();
         return -1;
      }
   }

   SysStat sys;
   int result = client.sysinfo(sys);
   if (result >= 0)
      print(sys, address);
   else
      Utility::print_error(result);

   Utility::logout(client);

   return result;
}
コード例 #11
0
void loadCmdLine(CmdLineParser &clp)
{
  clp.setMainHelpText("A simple Echo Server");

  // All options are optional
     // Number of Threads
  clp.addCmdLineOption(new CmdLineOptionInt(ARG_LISTEN_PORT,
                                            string("TCP port to listen on"),
                                            3868));
     // Verbosity
  clp.addCmdLineOption(new CmdLineOptionFlag(ARG_VERBOSE,
                                             string("Turn on verbosity"),
                                             false));
}
コード例 #12
0
ファイル: stop_all.cpp プロジェクト: norouzi4d/sector
int main(int argc, char** argv)
{
   string sector_home;
   if (ConfLocation::locate(sector_home) < 0)
   {
      cerr << "no Sector information located; nothing to stop.\n";
      return -1;
   }

   string slaves_list = sector_home + "/conf/slaves.list";
   bool force = false;

   CmdLineParser clp;
   clp.parse(argc, argv);
   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "s")
         slaves_list = i->second;
      else
      {
         help();
         return 0;
      }
   }
   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if ((*i == "f") || (*i == "force"))
         force = true;
      else
      {
         help();
         return 0;
      }
   }

   cout << "This will stop this master and all slave nodes by brutal forces. If you need a graceful shutdown, use ./tools/sector_shutdown.\n";

   if (!force)
   {
      cout << "Do you want to continue? Y/N:";
      char answer;
      cin >> answer;
      if ((answer != 'Y') && (answer != 'y'))
      {
         cout << "aborted.\n";
         return -1;
      }
   }
コード例 #13
0
ファイル: main.cpp プロジェクト: GraphicsEmpire/tetcutter
void cutFinished() {

    if(!g_parser.value_to_int("disjoint"))
		return;


	vector<CuttableMesh*> vMeshes;
	g_lpTissue->convertDisjointPartsToMeshes(vMeshes);

	if(vMeshes.size() == 0)
		return;

	U32 ctMaxCells = 0;
	U32 idxMaxCell = 0;
	for(U32 i=0; i < vMeshes.size(); i++) {
		vMeshes[i]->computeAABB();
		vMeshes[i]->setElemToShow(0);
        TheEngine::Instance().add(vMeshes[i]);

		if(vMeshes[i]->countCells() > ctMaxCells) {
			ctMaxCells = vMeshes[i]->countCells();
			idxMaxCell = i;
		}
	}

	g_lpTissue = vMeshes[idxMaxCell];

	g_lpTissue->setElemToShow();
	if(g_lpAvatar)
		g_lpAvatar->setTissue(g_lpTissue);
}
コード例 #14
0
ファイル: main.cpp プロジェクト: Drakey83/steamlink-sdk
bool synchronizeDocs(QHelpEngineCore &collection,
                     QHelpEngineCore &cachedCollection,
                     CmdLineParser &cmd)
{
    TRACE_OBJ
    const QDateTime &lastCollectionRegisterTime =
        CollectionConfiguration::lastRegisterTime(collection);
    if (!lastCollectionRegisterTime.isValid() || lastCollectionRegisterTime
        < CollectionConfiguration::lastRegisterTime(cachedCollection))
        return true;

    const QStringList &docs = collection.registeredDocumentations();
    const QStringList &cachedDocs = cachedCollection.registeredDocumentations();

    /*
     * Ensure that the cached collection contains all docs that
     * the collection contains.
     */
    foreach (const QString &doc, docs) {
        if (!cachedDocs.contains(doc)) {
            const QString &docFile = collection.documentationFileName(doc);
            if (!cachedCollection.registerDocumentation(docFile)) {
                cmd.showMessage(QCoreApplication::translate("Assistant",
                                    "Error registering documentation file '%1': %2").
                                arg(docFile).arg(cachedCollection.error()), true);
                return false;
            }
        }
    }

    CollectionConfiguration::updateLastRegisterTime(cachedCollection);

    return true;
}
コード例 #15
0
int main(int argc, char** argv)
{
   CmdLineParser clp;
   if (clp.parse(argc, argv) <= 0)
   {
      help();
      return -1;
   }

   int32_t id = 0;
   string addr;
   int32_t code = 0;
   for (map<string, string>::iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "i")
         id = atoi(i->second.c_str());
      else if (i->first == "d")
         addr = i->second;
      else if (i->first == "c")
         code = atoi(i->second.c_str());
      else
      {
         help();
         return -1;
      }
   }

   if (((id == 0) && (addr.c_str()[0] == 0))|| (code == 0))
   {
      help();
      return -1;
   }

   Session s;
   s.loadInfo("../conf/client.conf");

   Client c;
   if (c.init(s.m_ClientConf.m_strMasterIP, s.m_ClientConf.m_iMasterPort) < 0)
      return -1;

   string passwd = s.m_ClientConf.m_strPassword;
   if (s.m_ClientConf.m_strUserName != "root")
   {
      cout << "please input root password:";
      cin >> passwd;
   }
コード例 #16
0
ファイル: sample_coach.cpp プロジェクト: UNiQ10/HFO
/*!

 */
bool
SampleCoach::initImpl( CmdLineParser & cmd_parser )
{
    bool result =CoachAgent::initImpl( cmd_parser );

#if 0
    ParamMap my_params;
    if ( cmd_parser.count( "help" ) )
    {
       my_params.printHelp( std::cout );
       return false;
    }
    cmd_parser.parse( my_params );
#endif

    if ( cmd_parser.failed() )
    {
        std::cerr << "coach: ***WARNING*** detected unsupported options: ";
        cmd_parser.print( std::cerr );
        std::cerr << std::endl;
    }

    if ( ! result )
    {
        return false;
    }

    //////////////////////////////////////////////////////////////////
    // Add your code here.
    //////////////////////////////////////////////////////////////////

    if ( config().useTeamGraphic() )
    {
        if ( config().teamGraphicFile().empty() )
        {
            M_team_graphic.createXpmTiles( team_logo_xpm );
        }
        else
        {
            M_team_graphic.readXpmFile( config().teamGraphicFile().c_str() );
        }
    }

    return true;
}
コード例 #17
0
int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);
 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;


  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }
  
  Parser parser;
  bool ok;

  QFile file (filename);
  QVariant data = parser.parse (&file, &ok);
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "json object successfully converted to:";
    qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serialization output";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    QByteArray b = serializer.serialize(data);
    qDebug() << b;
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
コード例 #18
0
void loadCmdLine(CmdLineParser &clp)
{
    clp.setMainHelpText("A simple Echo Server");

    // All options are optional
    // IP Address
    clp.addCmdLineOption(new CmdLineOptionStr(ARG_IP_ADDRESS,
                         string("IP Address to listen on"),
                         string("127.0.0.1")));

    // TCP port
    clp.addCmdLineOption(new CmdLineOptionInt(ARG_LISTEN_PORT,
                         string("TCP port to listen on"),
                         3868));
    // Verbosity
    clp.addCmdLineOption(new CmdLineOptionFlag(ARG_VERBOSE,
                         string("Turn on verbosity"),
                         false));
}
コード例 #19
0
ファイル: cmdline_tester.cpp プロジェクト: LosYear/Ferriage
int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);
  QTime time;
  int   duration;

 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;

  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }
  
  Parser parser;
  bool ok;

  QFile file (filename);
  time.start();
  QVariant data = parser.parse (&file, &ok);
  duration = time.elapsed();
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "Parsing of" << filename << "took" << duration << "ms";
    if (!cmd.quiet())
      qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serializing... ";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    time.start();
    QByteArray b = serializer.serialize(data);
    duration = time.elapsed();
    qDebug() << "Serialization took:" << duration << "ms";
    if (!cmd.quiet())
     qDebug() << b;
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
コード例 #20
0
ファイル: main.cpp プロジェクト: nadezhdin-ivan/shdt
// Parses the command line given in a form the main() function received it.
// Returns: success?
// On success, public member variables shall contain interpreted 
// (validated) program parameters.
bool Options::ParseCmdLine(int argc, char* argv[]) {
	// zeroth, ensure fallback to the defaults..
	Reset();

	// first, try to read options from the default configuration file..
	FILE* in = fopen(INPUT, "r");
	if (in) {
		fclose(in);
		ParseConfigFile(INPUT, false);
	}

	// than, update those options with options from command-line..
	// ..and user-specified config files..
	CmdLineParser cmdline = cmdline_prototype;
	if (!cmdline.Parse(argc, argv)) {
		fprintf(stderr, "Command line syntax error!\n");
		fprintf(stderr, "Type '%s --help' for more information. \n", argv[0]);
		return false;
	}
	Store(cmdline);

	// at last, validate all stored options..
	return Validate();
}
コード例 #21
0
ファイル: main.cpp プロジェクト: Drakey83/steamlink-sdk
bool rebuildSearchIndex(QCoreApplication *app, const QString &collectionFile,
                        CmdLineParser &cmd)
{
    TRACE_OBJ
    QHelpEngine engine(collectionFile);
    if (!engine.setupData()) {
        cmd.showMessage(QCoreApplication::translate("Assistant", "Error: %1")
                        .arg(engine.error()), true);
        return false;
    }

    QHelpSearchEngine * const searchEngine = engine.searchEngine();
    QObject::connect(searchEngine, SIGNAL(indexingFinished()), app,
                     SLOT(quit()));
    searchEngine->reindexDocumentation();
    return app->exec() == 0;
}
コード例 #22
0
ファイル: main.cpp プロジェクト: nadezhdin-ivan/shdt
// Interprets the parsed command line and copies options that were defined into
// object member variables. After parsing all user option-definition streams, 
// these options must be validated with "Validate(..)".
// "Store(..)" acts in cumulative manner, i.e. preserves options already defined,
// if 'cmdline' doesn't redefine those options.
// Returns: success?
void Options::Store(CmdLineParser& cmdline) {
	// store options from additional configuration file (if any)
	vector<string> args;
	if (cmdline.NonOptionArgs(args)) {
		// take first non-option argument as a config filename
		ParseConfigFile(args[0], false);
	}

	help |= cmdline.IsSpecified("help");

	cmdline.IsSpecified("user") && cmdline.Read("user", username);
	cmdline.IsSpecified("pass") && cmdline.Read("pass", password);
	cmdline.IsSpecified("host") && cmdline.Read("host", hostname);
	cmdline.IsSpecified("port") && cmdline.Read("port", port);

	if (cmdline.IsSpecified("type")) {
		bool redefinition = true;

		string t;
		cmdline.Read("type", t);
		if (t == "d" || t == "double" || t == "float64")
			type = tFLOAT64, typeSize = sizeof(double);
		else if (t == "f" || t == "float" || t == "float32")
			type = tFLOAT32, typeSize = sizeof(float);
		else if (t == "l" || t == "longlong" || t == "int64")
			type = tINT64, typeSize = sizeof(int64);
		else if (t == "i" || t == "int" || t == "int32")
			type = tINT32, typeSize = sizeof(int32);
		else if (t == "s" || t == "shortint" || t == "int16")
			type = tINT16, typeSize = sizeof(int16);
		else if (t == "b" || t == "byte" || t == "int8")
			type = tINT8, typeSize = sizeof(int8);
		else {
			// do nothing! leave current type
			redefinition = false;
		}

		if (redefinition) {
			dataFormat = type == tFLOAT64 ? FMT_DOUBLE : ( type == tFLOAT32 ? FMT_FLOAT : (type == tINT64 ? FMT_LONGLONG : FMT_INT) );
		}
	}

	(cmdline.IsSpecified("count") || cmdline.IsSpecified("N")) && (cmdline.Read("count", count) || cmdline.Read("N", count));

	cmdline.IsSpecified("binary") && (outputMode = modeBinary);
	cmdline.IsSpecified("text") && (outputMode = modeText);
	cmdline.IsSpecified("separator") && cmdline.Read("separator", columnSeparator);	
	cmdline.IsSpecified("format") && cmdline.Read("format", dataFormat);

	cmdline.IsSpecified("out") && cmdline.Read("out", outputFilename);

}
コード例 #23
0
ファイル: pipe.cpp プロジェクト: norouzi4d/sector
int main(int argc, char** argv)
{
   CmdLineParser clp;
   if ((clp.parse(argc, argv) < 0) || (clp.m_mDFlags.size() != 1))
   {
      cerr << "usage #1: <your_application> | sector_pipe -d dst_file" << endl;
      cerr << "usage #2: sector_pipe -s src_file | <your_application>" << endl;
      return 0;
   }

   string option = clp.m_mDFlags.begin()->first;

   Sector client;
   if (Utility::login(client) < 0)
      return -1;

   timeval t1, t2;
   gettimeofday(&t1, 0);
   int64_t total_size = 0;

   SectorFile* f = client.createSectorFile();

   if (option == "d")
   {
      if (f->open(argv[2], SF_MODE::WRITE | SF_MODE::APPEND) < 0)
      {
         cerr << "ERROR: unable to open destination file." << endl;
         return -1;
      }

      int size = 1000000;
      char* buf = new char[size];
      int read_size = size;

      // read data from sdtin and write to Sector
      while(true)
      {
         read_size = read(0, buf, size);
         if (read_size <= 0)
            break;
         f->write(buf, read_size);
         total_size += read_size;
      }

      delete [] buf;
   }
   else if (option == "s")
   {
      if (f->open(argv[2], SF_MODE::READ) < 0)
      {
         cerr << "ERROR: unable to open source file." << endl;
         return -1;
      }

      int size = 1000000;
      char* buf = new char[size];
      int read_size = size;

      // read data from Sector and write to stdout
      while(!f->eof())
      {
         read_size = f->read(buf, size);
         if (read_size <= 0)
            break;
         total_size += read_size;
         write(1, buf, read_size);
      }

      delete [] buf;
   }

   f->close();
   client.releaseSectorFile(f);

   gettimeofday(&t2, 0);
   double throughput = total_size * 8.0 / 1000000.0 / ((t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1000000.0);

   cerr << "Pipeline accomplished! " << "AVG speed " << throughput << " Mb/s." << endl << endl ;

   Utility::logout(client);

   return 0;
}
コード例 #24
0
ファイル: download.cpp プロジェクト: deniskin82/sector-sphere
int main(int argc, char** argv)
{
   logger::config( "/tmp", "sector-download" );

   for( int arg = 0; arg < argc; ++arg )
      log().debug << argv[ arg ] << ' ';
   log().debug << std::endl;

   if (argc < 3)
   {
      help(argv[0]);
      log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
      return -1;
   }

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help(argv[0]);
      log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
      return -1;
   }

   if (clp.m_vParams.size() < 2)
   {
      help(argv[0]);
      log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
      return -1;
   }

   bool encryption = false;
   bool resume = false;

   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if (*i == "e")
         encryption = true;
      else if( *i == "smart" )
         resume = true;
      else
      {
         help(argv[0]);
         log().error << "Invalid command-line syntax, exiting with rc = -1" << std::endl;
         return -1;
      }
   }

   string newdir = *clp.m_vParams.rbegin();
   clp.m_vParams.erase(clp.m_vParams.begin() + clp.m_vParams.size() - 1);

   // check destination directory, which must exist
   SNode s;
   int r = LocalFS::stat(newdir, s);
   if ((r < 0) || !s.m_bIsDir)
   {
      cerr << "ERROR: destination directory does not exist.\n";
      log().error << "stat failed on destination directory, err = " << r << ", exiting with rc = -1" << std::endl;
      return -1;
   }

   // login to SectorFS
   Sector client;
   int rc = Utility::login(client);
   if (rc < 0)
   {
      cerr << "ERROR: failed to log in to sector\n";
      log().error << "Client login to master failed with err = " << rc << ", exiting with rc = -1" << std::endl;
      return -1;
   }

   // start downloading all files
   for (vector<string>::iterator i = clp.m_vParams.begin(); i != clp.m_vParams.end(); ++ i)
   {
      vector<string> fl;
      bool wc = WildCard::isWildCard(*i);
      if (!wc)
      {
         SNode attr;
         if ((rc = client.stat(*i, attr)) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            log().error << "Failed to stat sector file " << *i << ", err = " << rc << std::endl;
            return -1;
         }
         getFileList(*i, fl, client);
      }
      else
      {
         string path = *i;
         string orig = path;
         size_t p = path.rfind('/');
         if (p == string::npos)
            path = "/";
         else
         {
            path = path.substr(0, p);
            orig = orig.substr(p + 1, orig.length() - p);
         }

         vector<SNode> filelist;
         int r = client.list(path, filelist);
         if (r < 0)
            cerr << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;

         for (vector<SNode>::iterator i = filelist.begin(); i != filelist.end(); ++ i)
         {
            if (WildCard::match(orig, i->m_strName))
               getFileList(path + "/" + i->m_strName, fl, client);
         }
      }

      string olddir;
      for (int j = i->length() - 1; j >= 0; -- j)
      {
         if (i->c_str()[j] != '/')
         {
            olddir = i->substr(0, j);
            break;
         }
      }
      size_t p = olddir.rfind('/');
      if (p == string::npos)
         olddir = "";
      else
         olddir = olddir.substr(0, p);

      for (vector<string>::iterator i = fl.begin(); i != fl.end(); ++ i)
      {
         string dst = *i;
         if (olddir.length() > 0)
            dst.replace(0, olddir.length(), newdir);
         else
            dst = newdir + "/" + dst;

         string localdir = dst.substr(0, dst.rfind('/'));

         // if localdir does not exist, create it
         if (LocalFS::stat(localdir, s) < 0)
         {
            for (unsigned int p = 1; p < localdir.length(); ++ p)
            {
               if (localdir.c_str()[p] == '/')
               {
                  string substr = localdir.substr(0, p);

                  if ((-1 == ::mkdir(substr.c_str(), S_IRWXU)) && (errno != EEXIST))
                  {
                     int errno_save = errno;
                     cerr << "ERROR: unable to create local directory " << substr << endl;
                     log().error << "Failed to create local directory " << substr << ", errno = " << errno_save << std::endl;
                     return -1;
                  }
               }
            }

            if ((-1 == ::mkdir(localdir.c_str(), S_IRWXU)) && (errno != EEXIST))
            {
               int errno_save = errno;
               cerr << "ERROR: unable to create local directory " << localdir << endl;
               log().error << "Failed to create local directory " << localdir << ", errno = " << errno_save << std::endl;
               break;
            }
         }

         if (!resume )
         {
            string fileName = *i;
            if( fileName.rfind( '/' ) != fileName.npos )
                fileName = fileName.substr( fileName.rfind( '/' ) + 1 );
            string destFile = localdir + '/' + fileName;
            if( LocalFS::stat( destFile, s ) >= 0 )
            {
                cout << "Destination directory already contains file '" << fileName << "', removing." << endl;
                log().debug << "Destination directory already contains file " << fileName << " and smart not specified, removing file" << std::endl;
                if( LocalFS::erase( destFile ) < 0 )
                {
                   int save_errno = errno;
                   cerr << "ERROR: could not remove destination file: " << strerror( save_errno ) << endl
                       << "NOT downloading file!" << endl;
                   log().error << "Failed to remove destination file " << fileName << ", aborting this file" << std::endl;
                   return -1;
                }
            }
         } 
         else
         {
            string fileName = *i;
            if( fileName.rfind( '/' ) != fileName.npos )
                fileName = fileName.substr( fileName.rfind( '/' ) + 1 );
            string destFile = localdir + '/' + fileName;
            if( LocalFS::stat( destFile, s ) >= 0 )
            {
                cout << "Destination directory already contains file '" << fileName << "', resuming partial download." << endl;
		log().debug << "Destination file already exists with size " << s.m_llSize << ", resuming partial download" << std::endl;
            }
         }

         if (download(i->c_str(), localdir.c_str(), client, encryption) < 0)
         {
            // calculate total available disk size
            int64_t availdisk = 0;
            LocalFS::get_dir_space(localdir, availdisk);
            if (availdisk <= 0)
            {
               // if no disk space svailable, no need to try any more
               cerr << "insufficient local disk space. quit.\n";
               log().error << "Insufficient disk space" << std::endl;
               Utility::logout(client);
            }
            return -1;
         }
      }
   }

   Utility::logout(client);
   log().debug << "Download completed successfully" << std::endl;
   return 0;
}
コード例 #25
0
ファイル: main.cpp プロジェクト: fungos/seed1_tools
int main(int argc, const char **argv)
{
	char xmlfile[1024];
	char configfile[1024];
	char platform[128];
	bool rebuild = false;
	bool packages = false;
	bool compression = false;
	bool resources = false;
	bool unified = false;
	bool dirs = false;
	u8	 alignment = ALIGN_32;

	memset(configfile, '\0', 1024);
	memcpy(configfile, "config.xml", strlen("config.xml"));

	CmdLineParser *parser = new CmdLineParser(12);
	parser->Add("i", "input", false, false, true, SetXmlFile, xmlfile);
	parser->Add("p", "platform", false, false, true, SetPlatformString, platform);
	parser->Add("r", "rebuild", true, false, false, Rebuild, &rebuild);
	parser->Add("k", "packages", true, false, false, EnablePackages, &packages);
	parser->Add("a", "alignment", true, false, true, SetAlignment, &alignment);
	parser->Add("c", "compress", true, false, false, EnableCompression, &compression);
	parser->Add("d", "add_resources", true, false, false, EnablePackageResources, &resources);
	parser->Add("t", "tree", true, false, true, RebuildDirectoryTree, &dirs);
	parser->Add("v", "verbose", true, false, false, EnableVerboseMode, &gVerbose);
	parser->Add("q", "quiet", true, false, false, EnableQuietMode, &gQuiet);
	parser->Add("f", "config", true, false, true, SetConfigFile, &configfile);
	parser->Add("u", "unify", true, false, false, EnablePackageUnified, &unified);

	fprintf(stdout, "Seed Exporter (c) Danny Angelo Carminati Grein 2008\n");
	if (!parser->Parse(argc, argv, true))
	{
		fprintf(stdout, "\nusage: %s -i [input xml] -p [platform] [params]\n\n", argv[0]);
		fprintf(stdout, "PARAMS\n");
		fprintf(stdout, "\t\t-f, --config\tUse this config file as config.xml\n");
		fprintf(stdout, "\t\t-r, --rebuild\tRebuild all files.\n");
		fprintf(stdout, "\t\t-k, --packages\tCreate group packages.\n");
		fprintf(stdout, "\t\t-d, --add_resources\tAdd resources to the package files.\n");
		fprintf(stdout, "\t\t-u, --unify\tUnify packages in one output only.\n");
		fprintf(stdout, "\t\t-a [value], --alignment [value]\tOutput data alignment.\n");
		fprintf(stdout, "\t\t-c, --compress\tEnable output data compression.\n");
		fprintf(stdout, "\t\t-t, --tree\tBuild directory structure only (not implemented!)\n");
		fprintf(stdout, "\t\t-v, --verbose\tVerbose mode.\n");
		fprintf(stdout, "\t\t-q, --quiet\tQuiet mode.\n");
		fprintf(stdout, "\n");

		return EXIT_FAILURE;
	}

	e->bfsExeName = bfs::path(argv[0]);
	e->Process(configfile, xmlfile, platform, rebuild, packages, alignment, compression, resources, unified);

	return EXIT_SUCCESS;
}
コード例 #26
0
CmdLineParser * SeekerCmdLineParser::createCmdLineParser()
{
   CmdLineParser * parser = new CmdLineParser();
      
   parser->addIntOption(dxPortArg, SseUtil::strToInt(DEFAULT_DX_PORT),
                        "port for dx connections");

   parser->addIntOption(zxPortArg, SseUtil::strToInt(DEFAULT_ZX_PORT),
                        "port for zx connections");

   parser->addIntOption(ifcPortArg, SseUtil::strToInt(DEFAULT_IFC_PORT),
                        "port for ifc connections");

   parser->addIntOption(tsigPortArg, SseUtil::strToInt(DEFAULT_TSIG_PORT),
                        "port for tsig connections");

   parser->addIntOption(tscopePortArg, SseUtil::strToInt(DEFAULT_TSCOPE_PORT),
                        "port for tscope connections");

   parser->addIntOption(channelizerPortArg, 
                        SseUtil::strToInt(DEFAULT_CHANNELIZER_PORT),
                        "port for channelizer connections");

   parser->addIntOption(dxArchiverPortArg,
                        SseUtil::strToInt(DEFAULT_DX_ARCHIVER_TO_SSE_PORT),
                        "port for dx archiver connections");

   parser->addStringOption(dxArchiver1HostnameArg,
                           DEFAULT_DX_ARCHIVER1_HOSTNAME,
                           "dx archiver1 hostname");

   parser->addIntOption(dxToArchiver1PortArg,
                        SseUtil::strToInt(DEFAULT_DX_TO_DX_ARCHIVER1_PORT),
                        "port for dx connections to archiver1");

   parser->addStringOption(dxArchiver2HostnameArg, DEFAULT_DX_ARCHIVER2_HOSTNAME,
                           "dx archiver2 hostname");

   parser->addIntOption(dxToArchiver2PortArg,
                        SseUtil::strToInt(DEFAULT_DX_TO_DX_ARCHIVER2_PORT),
                        "port for dx connections to archiver2");

   parser->addStringOption(dxArchiver3HostnameArg, DEFAULT_DX_ARCHIVER3_HOSTNAME,
                           "dx archiver3 hostname");

   parser->addIntOption(dxToArchiver3PortArg,
                        SseUtil::strToInt(DEFAULT_DX_TO_DX_ARCHIVER3_PORT),
                        "port for dx connections to archiver3");

   parser->addStringOption(expectedComponentsFilenameArg,
                           DEFAULT_EXPECTED_COMPONENTS_FILENAME,
                           "expected NSS components configuration filename");

   parser->addIntOption(componentControlPortArg,
                        SseUtil::strToInt(DEFAULT_COMPONENT_CONTROL_PORT),
                        "port for component control connections");

   parser->addFlagOption(noUiArg,"disable user interface (server mode)");

   return parser;
}
コード例 #27
0
int main(int argc, char** argv)
{
   if (argc < 2)
   {
      help();
      return -1;
   }

   unsigned int thresh = 65536;
   int timeout = 3600 * 24; // default wait for one day

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help();
      return -1;
   }

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "w")
         thresh = atoi(i->second.c_str());
      else if (i->first == "t")
      {
         timeout = atoi(i->second.c_str());
         if (timeout < 0)
            timeout = INT_MAX;
      }
      else
      {
         help();
         return -1;
      }
   }

   Sector client;
   if (Utility::login(client) < 0)
      return -1;   

   list<string> filelist;

   for (vector<string>::iterator i = clp.m_vParams.begin(); i < clp.m_vParams.end(); ++ i)
   {
      vector<string> fl;
      fl.clear();

      bool wc = WildCard::isWildCard(*i);
      if (!wc)
      {
         SNode attr;
         if (client.stat(*i, attr) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            return -1;
         }
         getFileList(*i, fl, client, thresh);
      }
      else
      {
         string path = *i;
         string orig = path;
         size_t p = path.rfind('/');
         if (p == string::npos)
            path = "/";
         else
         {
            path = path.substr(0, p);
            orig = orig.substr(p + 1, orig.length() - p);
         }

         vector<SNode> filelist;
         int r = client.list(path, filelist);
         if (r < 0)
            cerr << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;

         for (vector<SNode>::iterator i = filelist.begin(); i != filelist.end(); ++ i)
         {
            if (WildCard::match(orig, i->m_strName))
               getFileList(path + "/" + i->m_strName, fl, client, thresh);
         }
      }

      filelist.insert(filelist.end(), fl.begin(), fl.end());
   }

   int result = -1;

   timeval t;
   gettimeofday(&t, NULL);
   int exp_time = t.tv_sec + timeout;

   int interval = 1;
   int total = -1;
   int new_total = 0;

   while (!filelist.empty())
   {
      new_total = 0;

      for (list<string>::iterator i = filelist.begin(); i != filelist.end();)
      {
         SNode sn;
         if (client.stat(*i, sn) < 0)
         {
            cout << "file " << sn.m_strName << " is lost.\n";
            break;
         }

         int diff = (sn.m_iReplicaNum > int(thresh)) ? (thresh - sn.m_sLocation.size()) : (sn.m_iReplicaNum - int(sn.m_sLocation.size()));

         if (diff <= 0)
         {
            list<string>::iterator j = i;
            ++ i;
            filelist.erase(j);
         }
         else
         {
            if ((result = client.copy(*i, *i)) < 0)
            {
               Utility::print_error(result);

               list<string>::iterator j = i;
               ++ i;
               filelist.erase(j);

               break;
            }

            ++ i;
            new_total += diff;
         }
      }

      timeval curr_time;
      gettimeofday(&curr_time, NULL);
      if (curr_time.tv_sec > exp_time)
      {
         cout << "timeout.\n";
         break;
      }

      //TODO: sleep diff for the last time
      if (interval < exp_time - curr_time.tv_sec)
         sleep(interval);
      else
         sleep(exp_time - curr_time.tv_sec);

      // wait longer if no progress, otherwise continue to wait for 1 sec
      if ((total > 0) && (new_total < total))
      {
         total = new_total;
         interval = 1;
      }
      else if (interval < 16)
      {
         interval <<= 1;
      }
   }

   if (filelist.empty())
   {
      cout << "all files have enough replicas.\n";
      result = 0;
   }

   Utility::logout(client);

   return result;
}
コード例 #28
0
ファイル: main.cpp プロジェクト: sashatref/DuplicateFinder
int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "Russian");

    CmdLineParser parser;
    parser << CmdLineItem("path", true, false, false, "Каталог для поиска дубликатов файлов");

    int result = parser.parse(argc, argv);
    switch(result)
    {
    case CmdLineParser::Error:
        qDebug() << (parser.getLastError() + "\n\n" + parser.getHelpString()).toStdString().c_str();
        return 0;
        break;
    case CmdLineParser::Help:
        qDebug() << parser.getHelpString().toStdString().c_str();
        return 0;
        break;
    }

    QElapsedTimer timer;
    timer.start();


    QString path = parser.at("path")->getValue().at(0);
    qDebug() << "Указанный каталог: " << path;

    QStringList files = Files::countDir(path, QStringList());
    qDebug() << "Найдено файлов: " << files.size();
    qDebug() << "Timer:" << timer.elapsed();

    QVector<MyFileInfo> fileInfoList;

    for(int i = 0 ; i < files.size(); i++)
    {
        fileInfoList.append(MyFileInfo(files[i]));
        fileInfoList.last().calcSize();
    }

    qDebug() << "Посчитаны размеры всех файлов";
    qDebug() << "Timer:" << timer.elapsed();

    qSort(fileInfoList.begin(), fileInfoList.end(), [](const MyFileInfo &_item1, const MyFileInfo &_item2)
    {
        return _item1.getFileSize() < _item2.getFileSize();
    });

    qDebug() << "Массив отсортирован по размеру";
    qDebug() << "Timer:" << timer.elapsed();

    for(int i = 1 ; i < fileInfoList.size(); i++)
    {
        if(fileInfoList[i].getFileSize() == fileInfoList[i - 1].getFileSize())
        {
            if(!fileInfoList[i].isHashPresent()) fileInfoList[i].calcHash();
            if(!fileInfoList[i - 1].isHashPresent()) fileInfoList[i - 1].calcHash();
            if(fileInfoList[i].getHash() == fileInfoList[i - 1].getHash())
            {
                if(fileInfoList[i].compareFiles(fileInfoList[i - 1]))
                {
                    qDebug() << fileInfoList[i].toString();
                    qDebug() << fileInfoList[i - 1].toString();
                    qDebug() << "------------------------\n";
                }
            }
        }
    }

    qDebug() << "Timer:" << timer.elapsed();
    qDebug() << "Завершено";

    return 0;
}
コード例 #29
0
ファイル: upload.cpp プロジェクト: deniskin82/sector-sphere
int main(int argc, char** argv)
{
   if (argc < 3)
   {
      help();
      return -1;
   }

   CmdLineParser clp;
   if (clp.parse(argc, argv) < 0)
   {
      help();
      return -1;
   }

   if (clp.m_vParams.size() < 2)
   {
      help();
      return -1;
   }

   int replica_num = 1;
   string ip = "";
   string cluster = "";
   int parallel = 1;  // concurrent uploading multiple files

   bool encryption = false;
   bool smart = false;

   for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
   {
      if (i->first == "n")
         replica_num = atoi(i->second.c_str());
      else if (i->first == "a")
         ip = i->second;
      else if (i->first == "c")
         cluster = i->second;
      else if (i->first == "p")
         parallel = atoi(i->second.c_str());
      else
      {
         help();
         return -1;
      }
   }

   for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
   {
      if (*i == "e")
         encryption = true;
      else if (*i == "smart" )
         smart = true;
      else
      {
         help();
         return -1;
      }
   }

   Sector client;
   if (Utility::login(client) < 0)
      return -1;

   string dstdir = *clp.m_vParams.rbegin();
   clp.m_vParams.pop_back();
   
   SNode attr;
   int r = client.stat(dstdir, attr);
   if ((r < 0) || (!attr.m_bIsDir))
   {
      cerr << "destination directory on Sector does not exist.\n";
      Utility::logout(client);
      return -1;
   }

   bool success = true;

   // upload multiple files/dirs
   for (vector<string>::const_iterator param = clp.m_vParams.begin(); param != clp.m_vParams.end(); ++ param)
   {
      string prefix = "";

      vector<string> fl;
      bool wc = WildCard::isWildCard(*param);
      if (!wc)
      {
         SNode s;
         if (LocalFS::stat(*param, s) < 0)
         {
            cerr << "ERROR: source file does not exist.\n";
            return -1;
         }

         if (s.m_bIsDir)
            prefix = *param;
         else
         {
            size_t pos = param->rfind('/');
            if (pos != string::npos)
               prefix = param->substr(0, pos);
         }

         getFileList(*param, fl);
      }
      else
      {
         size_t pos = param->rfind('/');
         if (pos != string::npos)
            prefix = param->substr(0, pos);

         string path = *param;
         string orig = path;
         size_t p = path.rfind('/');
         if (p == string::npos)
         {
            path = ".";
         }
         else
         {
            path = path.substr(0, p);
            orig = orig.substr(p + 1, orig.length() - p);
         }

         // as this is a wildcard, list all files in the current dir, choose those matched ones
         vector<SNode> curr_fl;
         if (LocalFS::list_dir(path, curr_fl) < 0)
            return -1;

         for (vector<SNode>::iterator s = curr_fl.begin(); s != curr_fl.end(); ++ s)
         {
            // skip "." and ".."
            if ((s->m_strName == ".") || (s->m_strName == ".."))
               continue;

            if (WildCard::match(orig, s->m_strName))
            {
               if (path == ".")
                  getFileList(s->m_strName, fl);
               else
                  getFileList(path + "/" + s->m_strName, fl);
            }
         }
      }

      // upload all files in the file list
      for (vector<string>::const_iterator i = fl.begin(); i != fl.end(); ++ i)
      {
         // process directory name change: /src/mydata -> /dst/mydata
         string dst = *i;
         if (prefix.length() > 0)
            dst.replace(0, prefix.length(), dstdir + "/");
         else
            dst = dstdir + "/" + dst;

         SNode s;
         if (LocalFS::stat(*i, s) < 0)
            continue;

         if (s.m_bIsDir)
            client.mkdir(dst);
         else
         {
   
            int result = upload(i->c_str(), dst.c_str(), client, replica_num, ip, cluster, encryption, smart);
            if ((result == SectorError::E_CONNECTION) ||
                (result == SectorError::E_BROKENPIPE))
            {
               // connection fail, retry once.
               result = upload(i->c_str(), dst.c_str(), client, replica_num, ip, cluster, encryption, smart);
            }
 
            if (result < 0)
            {
               // failed, remove the file in Sector.
               client.remove(dst);
               success = false;
               Utility::logout(client);
               return -1;
            }
         }
      }
   }

   Utility::logout(client);
   return success ? 0 : -1;
}
コード例 #30
0
ファイル: main.cpp プロジェクト: rmbl/openspeak
int main (int argc, char** argv)
{
    int ret = 0;
    CmdLineParser *cmdline = 0;
    Config *config = 0;

    if (!initNLS ("openspeak"))
    {
        std::cerr << "Initialising NLS failed!\n";
        return -1;
    }

    try
    {
    /* Parse the commandline */
        cmdline = new CmdLineParser (_("openSpeak Server"), "0.2-git");
        CmdLineParser::CmdLineOption options[] = {
            { "debug", 'd', CmdLineParser::OPTION_ARG_NONE, _("Display more informations"), "" },
            {0}
        };
        cmdline->addOption (options);
        cmdline->parseArguments (argc, argv);

    /* Check if the config path exists and if not create it */
        std::string confdir = FileUtils::getConfigPath ();
        if (!FileUtils::dirExists (confdir))
            FileUtils::mkdir (confdir);

    /* Also check for the log dir in the config dir */
        if (!FileUtils::dirExists (confdir + "log/"))
            FileUtils::mkdir (confdir + "log/");

    /* Create the log file */
        new LogMgr (confdir + "log/openspeakd.log",
                StringUtils::toBool (cmdline->getOption ("debug")) ?
                Log::LVL_DEBUG : Log::LVL_SILENT);
        LOG_SILENT (_("Started logging"));

    /* Open the config file and parse it */
        config = new Config ("openspeakd.conf");
        config->parse ();
        LOG_DEBUG (format (_("Parsed config file %1%openspeakd.conf")) % confdir);
    }
    catch (Exception ex)
    {
        if (LogMgr::getSingleton () && !ex.empty ())
            LOG_FATAL (format (_("Exception: %1%")) % ex.what ());
        else if (!ex.empty ())
            ex.print ();
        ret = -1;
    }
    catch (...)
    {
        if (LogMgr::getSingleton ())
            LOG_FATAL (_("Catched unknown exception"));
        else
            std::cout << _("Catched unknown exception");
        ret = -1;
    }

    delete cmdline;
    if (config)
        delete config;

    if (LogMgr::getSingleton ())
    {
        LOG_SILENT (_("Finished logging"));
        delete LogMgr::getSingleton ();
    }

    return ret;
}