[new downloader] Removing code responsable for saving countries.txt.

This commit is contained in:
Vladimir Byko-Ianko 2016-02-02 13:33:24 +03:00 committed by Sergey Yershov
parent 93964bf15b
commit 8a3d36d1a4
7 changed files with 0 additions and 229 deletions

View file

@ -34,7 +34,6 @@ SOURCES += \
tesselator.cpp \
towns_dumper.cpp \
unpack_mwm.cpp \
update_generator.cpp \
HEADERS += \
borders_generator.hpp \
@ -66,7 +65,6 @@ HEADERS += \
tesselator.hpp \
towns_dumper.hpp \
unpack_mwm.hpp \
update_generator.hpp \
ways_merger.hpp \
world_map_generator.hpp \

View file

@ -10,7 +10,6 @@
#include "generator/search_index_builder.hpp"
#include "generator/statistics.hpp"
#include "generator/unpack_mwm.hpp"
#include "generator/update_generator.hpp"
#include "indexer/classificator.hpp"
#include "indexer/classificator_loader.hpp"
@ -32,10 +31,6 @@
#include "3party/gflags/src/gflags/gflags.h"
DEFINE_bool(generate_update, false,
"If specified, update.maps file will be generated from cells in the data path");
DEFINE_bool(generate_classif, false, "Generate classificator.");
DEFINE_bool(preprocess, false, "1st pass - create nodes/ways/relations data");
@ -210,13 +205,6 @@ int main(int argc, char ** argv)
}
}
// Create http update list for countries and corresponding files.
if (FLAGS_generate_update)
{
LOG(LINFO, ("Updating countries file..."));
update::UpdateCountries(path);
}
string const datFile = path + FLAGS_output + DATA_FILE_EXTENSION;
if (FLAGS_calc_statistics)

View file

@ -1,146 +0,0 @@
#include "generator/update_generator.hpp"
#include "defines.hpp"
#include "platform/platform.hpp"
#include "storage/country.hpp"
#include "coding/file_writer.hpp"
#include "base/string_utils.hpp"
#include "base/logging.hpp"
#include "base/macros.hpp"
#include "base/timer.hpp"
#include "std/iterator.hpp"
using namespace storage;
namespace update
{
// we don't support files without name or without extension
/*
bool SplitExtension(string const & file, string & name, string & ext)
{
// get extension
size_t const index = file.find_last_of('.');
if (index == string::npos || (index + 1) == file.size() || index == 0 || file == "." || file == "..")
{
name = file;
ext.clear();
return false;
}
ext = file.substr(index);
name = file.substr(0, index);
return true;
}
*/
class SizeUpdater
{
size_t m_processedFiles;
string m_dataDir;
Platform::FilesList & m_files;
uint64_t GetFileSize(platform::CountryFile const & cnt, MapOptions opt) const
{
uint64_t sz = 0;
string const fName = cnt.GetNameWithExt(opt);
if (!GetPlatform().GetFileSizeByFullPath(m_dataDir + fName, sz))
{
LOG(opt == MapOptions::Map ? LCRITICAL : LWARNING, ("File was not found:", fName));
return 0;
}
CHECK_GREATER(sz, 0, ("Zero file size?", fName));
return sz;
}
public:
SizeUpdater(string const & dataDir, Platform::FilesList & files)
: m_processedFiles(0), m_dataDir(dataDir), m_files(files)
{
}
~SizeUpdater()
{
LOG(LINFO, (m_processedFiles, "file sizes were updated in the country list"));
if (!m_files.empty())
LOG(LWARNING, ("Files left unprocessed:", m_files));
}
template <class T> void operator() (T & c)
{
for (size_t i = 0; i < c.Value().m_files.size(); ++i)
{
platform::CountryFile & cnt = c.Value().m_files[i];
++m_processedFiles;
uint64_t szMap = GetFileSize(cnt, MapOptions::Map);
uint64_t szRouting = GetFileSize(cnt, MapOptions::CarRouting);
ASSERT_EQUAL(static_cast<uint32_t>(szMap), szMap, ());
ASSERT_EQUAL(static_cast<uint32_t>(szRouting), szRouting, ());
cnt.SetRemoteSizes(static_cast<uint32_t>(szMap),
static_cast<uint32_t>(szRouting));
string const fName = cnt.GetNameWithExt(MapOptions::Map);
auto found = find(m_files.begin(), m_files.end(), fName);
if (found != m_files.end())
m_files.erase(found);
else
LOG(LWARNING, ("No file ", fName, " on disk for the record in countries.txt"));
}
}
};
bool UpdateCountries(string const & dataDir)
{
Platform::FilesList mwmFiles;
GetPlatform().GetFilesByExt(dataDir, DATA_FILE_EXTENSION, mwmFiles);
// remove some files from list
char const * filesToRemove[] = {
"minsk-pass" DATA_FILE_EXTENSION,
WORLD_FILE_NAME DATA_FILE_EXTENSION,
WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION
};
for (size_t i = 0; i < ARRAY_SIZE(filesToRemove); ++i)
{
auto found = find(mwmFiles.begin(), mwmFiles.end(), filesToRemove[i]);
if (found != mwmFiles.end())
mwmFiles.erase(found);
}
if (mwmFiles.empty())
return false;
else
LOG(LINFO, (mwmFiles.size(), "mwm files were found"));
// load current countries information to update file sizes
storage::CountriesContainerT countries;
string jsonBuffer;
{
ReaderPtr<Reader>(GetPlatform().GetReader(COUNTRIES_FILE)).ReadAsString(jsonBuffer);
storage::LoadCountries(jsonBuffer, countries);
// using move semantics for mwmFiles
SizeUpdater sizeUpdater(dataDir, mwmFiles);
countries.ForEachDescendant(sizeUpdater);
}
storage::SaveCountries(my::TodayAsYYMMDD(), countries, jsonBuffer);
{
string const outFileName = dataDir + COUNTRIES_FILE ".updated";
FileWriter f(outFileName);
f.Write(&jsonBuffer[0], jsonBuffer.size());
LOG(LINFO, ("Saved updated countries to", outFileName));
}
return true;
}
} // namespace update

View file

@ -1,8 +0,0 @@
#pragma once
#include "std/string.hpp"
namespace update
{
bool UpdateCountries(string const & dataDir);
} // namespace update

View file

@ -181,62 +181,4 @@ void LoadCountryCode2File(string const & jsonBuffer, multimap<string, string> &
DoStoreCode2File doStore(code2file);
LoadCountriesImpl(jsonBuffer, doStore);
}
template <class T>
void SaveImpl(T const & v, json_t * jParent)
{
size_t const childrenCount = v.ChildrenCount();
CHECK_GREATER(childrenCount, 0, ());
my::JsonHandle jArray;
jArray.AttachNew(json_array());
for (size_t i = 0; i < childrenCount; ++i)
{
my::JsonHandle jCountry;
jCountry.AttachNew(json_object());
string const strName = v.Child(i).Value().Name();
CHECK(!strName.empty(), ("Empty country name?"));
json_object_set_new(jCountry.get(), "n", json_string(strName.c_str()));
string const strFlag = v.Child(i).Value().Flag();
if (!strFlag.empty())
json_object_set_new(jCountry.get(), "c", json_string(strFlag.c_str()));
size_t countriesCount = v.Child(i).Value().GetFilesCount();
ASSERT_LESS_OR_EQUAL(countriesCount, 1, ());
if (countriesCount > 0)
{
CountryFile const & file = v.Child(i).Value().GetFile();
string const & strFile = file.GetNameWithoutExt();
if (strFile != strName)
json_object_set_new(jCountry.get(), "f", json_string(strFile.c_str()));
json_object_set_new(jCountry.get(), "s", json_integer(file.GetRemoteSize(MapOptions::Map)));
json_object_set_new(jCountry.get(), "rs",
json_integer(file.GetRemoteSize(MapOptions::CarRouting)));
}
if (v.Child(i).ChildrenCount())
SaveImpl(v.Child(i), jCountry.get());
json_array_append(jArray.get(), jCountry.get());
}
json_object_set(jParent, "g", jArray.get());
}
bool SaveCountries(int64_t version, CountriesContainerT const & countries, string & jsonBuffer)
{
my::JsonHandle root;
root.AttachNew(json_object());
json_object_set_new(root.get(), "v", json_integer(version));
json_object_set_new(root.get(), "n", json_string("World"));
SaveImpl(countries, root.get());
char * res = json_dumps(root.get(), JSON_PRESERVE_ORDER | JSON_COMPACT | JSON_INDENT(1));
jsonBuffer = res;
free(res);
return true;
}
} // namespace storage

View file

@ -67,6 +67,4 @@ int64_t LoadCountries(string const & jsonBuffer, CountriesContainerT & countries
void LoadCountryFile2CountryInfo(string const & jsonBuffer, map<string, CountryInfo> & id2info);
void LoadCountryCode2File(string const & jsonBuffer, multimap<string, string> & code2file);
bool SaveCountries(int64_t version, CountriesContainerT const & countries, string & jsonBuffer);
} // namespace storage

View file

@ -34,7 +34,6 @@
#include "std/unique_ptr.hpp"
#include "std/vector.hpp"
#include <QtCore/QCoreApplication>
using namespace platform;