Stroka CCommonParm::GetOutputFileName() const { if (NULL != Config.Get() && Config->has_output() && Config->output().has_file()) { Stroka fn = Config->output().GetFile(); fn.to_lower(); if ("stdout" == fn) return "-"; return Config->output().GetFile(); } return Stroka("-"); }
Stroka CCommonParm::GetPrettyOutputFileName() const { if (NULL != Config.Get() && Config->has_prettyoutput()) { Stroka fn = Config->GetPrettyOutput(); fn.to_lower(); if ("stdout" == fn || "stderr" == fn) return fn; if ("-" == fn) return "stdout"; if (fn.size() > 0) return Config->GetPrettyOutput(); } return Stroka(""); }
void CCommonParm::AnalizeParameter(const TStringBuf& name, const TStringBuf& value) { Stroka paramName = ToString(StripString(name)); Stroka paramValue = ToString(StripString(value)); paramName.to_lower(); }
bool CCommonParm::ParseConfig(const Stroka& fn) { Config.Reset(NProtoConf::LoadFromFile<TTextMinerConfig>(fn)); if (!Config) ythrow yexception() << "Cannot read the config from \"" << fn << "\"."; if (m_args.has(OPT_BINARY_DIR)) { if (Config->has_binarydir() && Config->binarydir().length() > 0) ythrow yexception() << "Both \"--" << OPT_BINARY_DIR << "\" command line argument and \"BinaryDir\" config parameter specified"; Config->set_binarydir(m_args[OPT_BINARY_DIR]); } if (Config->has_input()) { TTextMinerConfig_TInputParams inputParams = Config->input(); if (inputParams.has_file() && !inputParams.file().empty() && inputParams.has_dir() && !inputParams.dir().empty()) ythrow yexception() << "Input\\File and Input\\Dir options are meaningless together"; Stroka fn = inputParams.file(); fn.to_lower(); if (fn.empty() || "stdin" == fn || "-" == fn) m_strInputFileName = ""; else m_strInputFileName = inputParams.file(); if (inputParams.has_dir()) { if (inputParams.has_type()) ythrow yexception() << "Input\\Type field is meaningless for directory processing"; m_strSourceType = "dir"; m_strInputFileName = inputParams.dir(); m_strDocDir = inputParams.dir(); if (!PathHelper::IsDir(m_strDocDir)) ythrow yexception() << "\"" << m_strDocDir << "\" isn't a directory"; } else { if (inputParams.has_type()) { switch (inputParams.type()) { case TTextMinerConfig::TInputParams::no: m_strSourceType = "no"; break; case TTextMinerConfig::TInputParams::dpl: m_strSourceType = "dpl"; break; case TTextMinerConfig::TInputParams::arcview: m_strSourceType = "arcview"; break; case TTextMinerConfig::TInputParams::mapreduce: m_strSourceType = "mapreduce"; break; case TTextMinerConfig::TInputParams::tar: if (m_strInputFileName.empty()) ythrow yexception() << "Please specify Input\\File field in configuration file in order to use .tar archive."; m_strSourceType = "tar"; break; case TTextMinerConfig::TInputParams::som: if (m_strInputFileName.empty()) ythrow yexception() << "Please specify Input\\File field in configuration file in order to read SOM data."; m_strSourceType = "som"; break; case TTextMinerConfig::TInputParams::yarchive: if (m_strInputFileName.empty()) ythrow yexception() << "Please specify Input\\File field in configuration file in order to read Yandex archive."; m_strSourceType = "yarchive"; break; default: ythrow yexception() << "This type of input isn't supported"; } } else m_strSourceType = "no"; } } if (NULL == ParserOptions.Get()) ParserOptions.Reset(new CParserOptions); ParserOptions->InitFromConfigObject(*Config.Get()); return true; }