Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build_statistics.cpp « build_style « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 84b3a4765d1b03f03faede23c167605b1cad7070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "build_statistics.h"

#include "build_common.h"

#include "platform/platform.hpp"

#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QStringList>

#include <exception>

namespace
{
QString GetScriptPath()
{
  return GetExternalPath("drules_info.py", "kothic/src", "../tools/python/stylesheet");
}
}  // namespace

namespace build_style
{

QString GetStyleStatistics(QString const & mapcssMappingFile, QString const & drulesFile)
{
  if (!QFile(mapcssMappingFile).exists())
    throw std::runtime_error("mapcss-mapping file does not exist");

  if (!QFile(drulesFile).exists())
    throw std::runtime_error("drawing-rules file does not exist");

  // Prepare command line
  QStringList params;
  params << "python" << GetScriptPath() << mapcssMappingFile << drulesFile;
  QString const cmd = params.join(' ');

  // Add path to the protobuf EGG in the PROTOBUF_EGG_PATH environment variable
  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
  env.insert("PROTOBUF_EGG_PATH", GetProtobufEggPath());

  // Run the script
  auto const res = ExecProcess(cmd, &env);

  QString text;
  if (res.first != 0)
  {
    text = QString("System error ") + to_string(res.first).c_str();
    if (!res.second.isEmpty())
      text = text + "\n" + res.second;
  }
  else
    text = res.second;

  return text;
}

QString GetCurrentStyleStatistics()
{
  QString const resourceDir = GetPlatform().ResourcesDir().c_str();
  QString const mappingPath = JoinFoldersToPath({resourceDir, "mapcss-mapping.csv"});
  QString const drulesPath = JoinFoldersToPath({resourceDir, "drules_proto_design.bin"});
  return GetStyleStatistics(mappingPath, drulesPath);
}
}  // namespace build_style