コード例 #1
0
void InfoFileReader::read(const std::string& text, StringToStringMap& res)
{
  res.clear();
  m_currentLineNumber = 1;
  std::string line;
  for(std::string::size_type i = 0;i < text.length();i++)
    {
      if (text[i] == '\r')
	continue;
      if (text[i] != '\n')
	{
	  line += text[i];
	  continue;
	}
      std::string name, value;
      parseLine(line, name, value);
      m_currentLineNumber++;
      line.erase();
      if (name.empty())
	continue;
      res.insert(StringToStringMap::value_type(name, value));
    }
  if (line.empty())
    return;
  std::string name, value;
  parseLine(line, name, value);
  if (name.empty())
    return;
  res.insert(StringToStringMap::value_type(name, value));
}
コード例 #2
0
/** Creates or updates the json file of a directories contents
* @param directoryPath The path to the directory to catalog
* @return A map of file names to sha1 values
**/
DownloadInstrument::StringToStringMap
DownloadInstrument::getFileShas(const std::string &directoryPath) {
  StringToStringMap filesToSha;
  try {
    using Poco::DirectoryIterator;
    DirectoryIterator end;
    for (DirectoryIterator it(directoryPath); it != end; ++it) {
      const auto &entryPath = Poco::Path(it->path());
      if (entryPath.getExtension() != "xml")
        continue;
      std::string sha1 = ChecksumHelper::gitSha1FromFile(entryPath.toString());
      // Track sha1
      filesToSha.insert(std::make_pair(entryPath.getFileName(), sha1));
    }
  } catch (Poco::Exception &ex) {
    g_log.error() << "DownloadInstrument: failed to parse the directory: "
                  << directoryPath << " : " << ex.className() << " : "
                  << ex.displayText() << std::endl;
    // silently ignore this exception.
  } catch (std::exception &ex) {
    std::stringstream ss;
    ss << "unknown exception while checking local file system. " << ex.what()
       << ". Input = " << directoryPath;
    throw std::runtime_error(ss.str());
  }

  return filesToSha;
}
コード例 #3
0
void RpmTransaction::process(const StringVector& install,
			     const StringVector& remove,
			     const StringToStringMap& upgrade,
			     const StringToStringMap& downgrade)
{
  int rc = 0;
  int probFilter = 0;
  int notifyFlags = 0;
  int tsFlags = 0;
  rpmProblemSet probs;
  if (!upgrade.empty()) 
    probFilter |= RPMPROB_FILTER_OLDPACKAGE;
  //  probFilter |= RPMPROB_FILTER_REPLACEPKG//reinstall;;
  //  probFilter |= RPMPROB_FILTER_REPLACEOLDFILES;
  //      probFilter |= RPMPROB_FILTER_REPLACENEWFILES;
  notifyFlags |= INSTALL_LABEL | INSTALL_HASH;
  if (!remove.empty())
    addToTransactionRemove(remove);
  if (!install.empty())
    addToTransactionInstall(install);
  if (!upgrade.empty())
    addToTransactionUpgrade(upgrade);
  rpmDependencyConflict conflicts = NULL;
  int numConflicts;
  if (rpmdepCheck(m_ts, &conflicts, &numConflicts) || conflicts) 
    {
      std::cerr << "Conflicts found!!" << std::endl;
      if (conflicts)
	{
	  printDepProblems(stderr, conflicts, numConflicts);
	  rpmdepFreeConflicts(conflicts, numConflicts);
	}
      exit(EXIT_FAILURE);
    }
  rc = rpmdepOrder(m_ts);
  if (rc > 0) 
    {
      std::cerr << "Ordering failed" << std::endl;
      return;
    }
  rc = rpmRunTransactions(m_ts, rpmShowProgress, (void *)(intptr_t)notifyFlags, NULL,
			  &probs, (rpmtransFlags)tsFlags,
			  (rpmprobFilterFlags)probFilter);
  if (rc > 0) 
    {
      std::cerr << "Error while running transaction" << std::endl;
      //	if (probs->numProblems > 0)
      //	  rpmpsPrint(stderr, probs);
    } else 
    if (rc < 0)
      std::cerr << "warning:some errors occurred while running transaction" << std::endl; 
  //  rpmpsFree(probs);
}
コード例 #4
0
EStatusCode PreprocessorTest::RunTest(const string& inName, const string& inOriginalFile, const string& inOutputFile, const string& inComparisonFile)
{
	EStatusCode status = eSuccess;

	StringToStringMap preprocessorDefinitions;
	StringList includeFolders;

	includeFolders.push_back(scSamplesBasePath);
	preprocessorDefinitions.insert(StringToStringMap::value_type("PREDEFINED_SYMBOL","2"));

	InputFile sourceFile;
	sourceFile.OpenFile(inOriginalFile);

	OutputFile outputFile;
	outputFile.OpenFile(inOutputFile);
	mCurrentStream = outputFile.GetOutputStream();

	PreProcessor preProcessor;

	preProcessor.Setup(sourceFile.GetInputStream(),inOriginalFile,preprocessorDefinitions,includeFolders);

	preProcessor.AddListener(this);

	mStartRow = true;
	BoolAndString tokenizerResult = preProcessor.GetNextToken();
	while(tokenizerResult.first)
	{
		if(!mStartRow)
			mCurrentStream->Write((const Byte*)"  ",2); // 2 spaces, so we can clearly distinct tokens
		mCurrentStream->Write((const Byte*)tokenizerResult.second.c_str(),tokenizerResult.second.size());

		mStartRow = false;

		tokenizerResult = preProcessor.GetNextToken();
	}

	sourceFile.CloseFile();
	outputFile.CloseFile();

	mCurrentStream = NULL;
	
	SimpleFileComparer comparer;

	if(!comparer.Same(inOutputFile,inComparisonFile))
	{
		cout<<"TokenizerTest::Run, failed in test named "<<inName<<". see result in "<<inOutputFile<<" and compare with the required result in "<<inComparisonFile<<"\n";
		status = eFailure;
	}

	return status;	

}
コード例 #5
0
ファイル: FilesFetch.cpp プロジェクト: marigostra/deepsolver
DEEPSOLVER_BEGIN_NAMESPACE

void FilesFetch::fetch(const StringToStringMap& files)
{
  curlInitialize();
  m_lastPartPercents = 0;
  m_lastTotalPercents = 0;
  m_partCount = files.size();
  m_currentPartNumber = 0;
  for(StringToStringMap::const_iterator it = files.begin();it != files.end();it++)
    {
      logMsg(LOG_DEBUG, "fetch:fetching \'%s\'", it->first.c_str());
      m_currentFileName = it->first;
      processFile(it->first, it->second);
      m_currentPartNumber++;
    }
}
コード例 #6
0
ファイル: RepoParams.cpp プロジェクト: marigostra/deepsolver
static void writeInfoFileParamsToDisk(const std::string& fileName, const StringToStringMap& params)
{
  std::ostringstream ss;
  time_t t;
  time(&t);
  ss << "# Deepsolver repository index information file" << std::endl;
  ss << "# Generated on " << ctime(&t);
  ss << "#" << std::endl;
  ss << "# This file was created automatically. Do not edit!" << std::endl;
  ss << "#" << std::endl;
  ss << std::endl;
  for(StringToStringMap::const_iterator it = params.begin();it != params.end();it++)
      ss << it->first << " = " << escapeString(it->second) << std::endl;
  File f;
  f.create(fileName);
  f.write(ss.str().c_str(), ss.str().length());
}
コード例 #7
0
void RpmTransaction::addToTransactionUpgrade(const StringToStringMap& files)
{
  for (StringToStringMap::const_iterator it = files.begin();it != files.end();it++)
    {
      FD_t fd = Fopen(it->second.c_str(), "r.ufdio");
      if (fd == NULL)
	throw PkgBackEndException("Fopen(" + it->second + ")");
      Header hdr;
      int rc = rpmReadPackageHeader(fd, &hdr, 0, NULL, NULL);
      if (rc != 0)
	throw PkgBackEndException("rpmReadPackageHeader()");
      rc = rpmtransAddPackage(m_ts, hdr, NULL, it->second.c_str(), 1, 0);
      if (rc != 0)
	throw PkgBackEndException("rpmtransAddPackage()");
      headerFree(hdr);
      Fclose(fd);
    }
}
コード例 #8
0
ファイル: RpmBackEnd.cpp プロジェクト: marigostra/deepsolver
bool RpmBackEnd::transaction(const StringVector& toInstall,
			     const StringVector& toRemove,
			     const StringToStringMap& toUpgrade,
			     const StringToStringMap& toDowngrade)
{
  if (!toDowngrade.empty())
    throw NotImplementedException("Downgrading tasks in a transaction");
  logMsg(LOG_DEBUG, "backend:starting transaction with %zu packages to install, %zu packages to remove, %zu packages to upgrade and %zu packages to downgrade", toInstall.size(), toRemove.size(), toUpgrade.size(), toDowngrade.size());
  for(StringVector::size_type i = 0;i < toInstall.size();i++)
    logMsg(LOG_DEBUG, "backend:%s to install", toInstall[i].c_str());
  for(StringVector::size_type i = 0;i < toRemove.size();i++)
    logMsg(LOG_DEBUG, "backend:%s to remove", toRemove[i].c_str());
  for(StringToStringMap::const_iterator it = toUpgrade.begin();it != toUpgrade.end();it++)
    logMsg(LOG_DEBUG, "backend:%s -> %s to upgrade", it->first.c_str(), it->second.c_str());
  for(StringToStringMap::const_iterator it = toDowngrade.begin();it != toDowngrade.end();it++)
    logMsg(LOG_DEBUG, "backend:%s -> %s to downgrade", it->first.c_str(), it->second.c_str());
  RpmTransaction transact;
  transact.init();
  transact.process(toInstall, toRemove, toUpgrade, toDowngrade);
  transact.close();
  logMsg(LOG_DEBUG, "backend:transaction is completed");
  return 1;
}
コード例 #9
0
void HunspellInterface::UpdatePossibleValues(SpellCheckEngineOption& OptionDependency, SpellCheckEngineOption& OptionToUpdate)
{
  if ((OptionDependency.GetName().IsSameAs(_T("dictionary-path"))) && (OptionToUpdate.GetName().IsSameAs(_T("language"))))
  {
    StringToStringMap tempLookupMap;
    wxString strDictionaryPath = OptionDependency.GetValueAsString();
    PopulateDictionaryMap(&tempLookupMap, strDictionaryPath);

    StringToStringMap::iterator start = tempLookupMap.begin();
    StringToStringMap::iterator stop = tempLookupMap.end();
    while (start != stop)
    {
      OptionToUpdate.AddPossibleValue((*start).first);
      start++;
    }
  }
  else
  {
    wxMessageOutput* msgOut = wxMessageOutput::Get();
    if (msgOut)
      msgOut->Printf(_T("Unsure how to update the possible values for %s based on the value of %s"), OptionDependency.GetText().c_str(), OptionToUpdate.GetText().c_str());
  }
}
コード例 #10
0
ファイル: RepoParams.cpp プロジェクト: marigostra/deepsolver
void RepoParams::readInfoFile(const std::string& fileName)
{
  File f;
  logMsg(LOG_DEBUG, "Opening \'%s\' info file in read-only mode", fileName.c_str());
  f.openReadOnly(fileName);
  std::string content;
  f.readTextFile(content);
  InfoFileReader reader;
  StringToStringMap params;
  reader.read(content, params);
  for(StringToStringMap::const_iterator it = params.begin();it != params.end();it++)
    {
      const std::string& name = it->first;
      const std::string& value = it->second;
      logMsg(LOG_DEBUG, "%s:parsing \'%s\' = \'%s\'", fileName.c_str(), name.c_str(), value.c_str());
      //Format type;
      if (trim(name) == INFO_FILE_FORMAT_TYPE)
	{
	  if (trim(value) == INFO_FILE_FORMAT_TYPE_TEXT)
	    formatType = FormatTypeText; else
	    if (trim(value) == INFO_FILE_FORMAT_TYPE_BINARY)
	      formatType = FormatTypeBinary; else
	      throw InfoFileValueException(InfoFileValueException::InvalidFormatType, trim(value));
	  continue;
	} //Format type;
      //Compression type;
      if (trim(name) == INFO_FILE_COMPRESSION_TYPE)
	{
	  if (trim(value) == INFO_FILE_COMPRESSION_TYPE_NONE)
	    compressionType = CompressionTypeNone; else
	    if (trim(value) == INFO_FILE_COMPRESSION_TYPE_GZIP)
	      compressionType = CompressionTypeGzip; else
	      throw InfoFileValueException(InfoFileValueException::InvalidCompressionType, trim(value));
	  continue;
	} //Compression type;
      //Version;
      if (trim(name) == INFO_FILE_VERSION)
	{
	  version = trim(value);
	  continue;
	} //Version;
      //Md5sum;
      if (trim(name) == INFO_FILE_MD5SUM)
	{
	md5sumFileName = trim(value);
	continue;
	} //Md5sum;
      // Change log binary;
      if (trim(name) == INFO_FILE_CHANGELOG_BINARY)
	{
	  changeLogBinary = parseBooleanValue(trim(value), trim(name));
	  continue;
	} //Change log binary;
      //Change log sources;
      if (trim(name) == INFO_FILE_CHANGELOG_SOURCES)
	{
	  changeLogSources = parseBooleanValue(trim(value), trim(name));
	  continue;
	} //Change log sources;
      //Filter provides by references;
      if (trim(name) == INFO_FILE_FILTER_PROVIDES_BY_REFS)
	{
	  filterProvidesByRefs = parseBooleanValue(trim(value), trim(name));
	  continue;
	}
      //Filter provides by dirs;
      if (trim(name) == INFO_FILE_FILTER_PROVIDES_BY_DIRS)
	{
	  parseStringVector(trim(value), filterProvidesByDirs);
	  continue;
	} //Filter provides by dirs;
      //Exclude requires;
      if (trim(name) == INFO_FILE_EXCLUDE_REQUIRES)
	{
	  parseStringVector(trim(value), excludeRequiresRegExp);
	  continue;
	}
      userParams.insert(StringToStringMap::value_type(trim(name), trim(value)));
    } //for(values);
}
コード例 #11
0
ファイル: RepoParams.cpp プロジェクト: marigostra/deepsolver
void RepoParams::writeInfoFile(const std::string& fileName) const
{
  logMsg(LOG_DEBUG, "Saving info file in \'%s\'", fileName.c_str());
  StringToStringMap params;
  switch(formatType)
    {
    case FormatTypeText:
      params.insert(StringToStringMap::value_type(INFO_FILE_FORMAT_TYPE, INFO_FILE_FORMAT_TYPE_TEXT));
      break;
    case FormatTypeBinary:
      params.insert(StringToStringMap::value_type(INFO_FILE_FORMAT_TYPE, INFO_FILE_FORMAT_TYPE_BINARY));
      break;
    default:
      assert(0);
    }; //switch(formatType);
  switch(compressionType)
    {
    case CompressionTypeNone:
      params.insert(StringToStringMap::value_type(INFO_FILE_COMPRESSION_TYPE, INFO_FILE_COMPRESSION_TYPE_NONE));
      break;
    case CompressionTypeGzip:
      params.insert(StringToStringMap::value_type(INFO_FILE_COMPRESSION_TYPE, INFO_FILE_COMPRESSION_TYPE_GZIP));
      break;
    default:
      assert(0);
    }; //switch(compressionType);
  params.insert(StringToStringMap::value_type(INFO_FILE_VERSION, version));
  params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_DIRS, saveStringVector(filterProvidesByDirs)));
  params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_DIRS, saveStringVector(filterProvidesByDirs)));
  params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_REFS, booleanValue(filterProvidesByRefs)));
  params.insert(StringToStringMap::value_type(INFO_FILE_EXCLUDE_REQUIRES, saveStringVector(excludeRequiresRegExp)));
  params.insert(StringToStringMap::value_type(INFO_FILE_CHANGELOG_BINARY, booleanValue(changeLogBinary)));
  params.insert(StringToStringMap::value_type(INFO_FILE_CHANGELOG_SOURCES, booleanValue(changeLogSources)));
  params.insert(StringToStringMap::value_type(INFO_FILE_MD5SUM, REPO_INDEX_MD5SUM_FILE));
  for(StringToStringMap::const_iterator it = userParams.begin();it != userParams.end();it++)
    params.insert(*it);
  writeInfoFileParamsToDisk(fileName, params);
}