File size: 5,501 Bytes
3f268e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Copyright 2017 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const cwd = process.cwd();
const fs = require('fs');
const global = {
  ws: {},
  states: {},
  repositories: {},
  series: {},
  debug: false,
  version: undefined,
  config: require(cwd + '/configs/dana.js'),
  projectsConfig: {},
  projects: {},
  admin: {},
  emailIsEnabled: true,
  comparesConfig: {},
};

if (global.config === undefined) {
  console.log('ERROR Invalid configuration file, undefined');
  process.exit(2);
}

const ModuleFiles = require(cwd + '/src/files');
global.admin = new ModuleFiles(cwd + '/configs/db/admin', 200);

if (global.admin.existsSync('projects')) {
  global.projectsConfig = global.admin.readSync('projects');
}

const serieIdFind = /stringToFindInSerieId/; // regex
const serieIdReplace = "stringToReplaceInSerieId";
const serieInfosFind = /stringToFindInInfos/; // regex
const serieInfosReplace = "stringToReplaceInInfos";

let k = Object.keys(global.projectsConfig);
for (let ii = 0; ii < k.length; ii++) {
  global.projects[k[ii]] = {};
  if (!fs.existsSync(cwd + '/configs/db/' + k[ii])) {
    fs.mkdirSync(cwd + '/configs/db/' + k[ii]);
  }
  global.projects[k[ii]].series =
    new ModuleFiles(cwd + '/configs/db/' + k[ii] + '/series', 10);
  global.projects[k[ii]].comments =
    new ModuleFiles(cwd + '/configs/db/' + k[ii] + '/comments', 10);
  global.projects[k[ii]].infos =
    new ModuleFiles(cwd + '/configs/db/' + k[ii] + '/infos', 200);
}

if (global.admin.existsSync('compares')) {
  global.comparesConfig = global.admin.readSync('compares');
}

let projectId, serieId, compareId;

var kProjects = Object.keys(global.projects);
for (var ii = 0; ii < kProjects.length; ii++) {
  let series, kSeries;
  projectId = kProjects[ii];
  if (global.projects[projectId].infos.existsSync('tests.series')) {
    series = global.projects[projectId].infos
      .readSync('tests.series');
    kSeries = Object.keys(series);
    for (let ii = 0; ii < kSeries.length; ii++) {
      let serie;
      serieId = kSeries[ii];
      if (serieId.search(serieIdFind) !== -1) {
        if (!global.projects[projectId].series.existsSync(serieId)) {
          console.log('Database integrity error - ', projectId, serieId);
          process.exit(1);
        }
        serie = global.projects[projectId].series.readSync(serieId);
        let newSerieId = serieId.replace(serieIdFind, serieIdReplace);
        if (serie.infos)
          serie.infos = serie.infos.replace(serieInfosFind, serieInfosReplace);
        console.log(projectId, 'Tests.series converting "', serieId, '" into "', newSerieId, '"');
        global.projects[projectId].series.writeSync(newSerieId, serie);
        global.projects[projectId].series.deleteSync(serieId);
        series[newSerieId] = series[serieId];
        delete series[serieId];
      }
    }
    series = global.projects[projectId].infos
      .writeSync('tests.series', series);
  }

  if (global.projects[projectId].infos.existsSync('benchmarks.series')) {
    series = global.projects[projectId].infos
      .readSync('benchmarks.series');
    kSeries = Object.keys(series);
    for (let ii = 0; ii < kSeries.length; ii++) {
      let serie;
      serieId = kSeries[ii];
      if (serieId.search(serieIdFind) !== -1) {
        if (!global.projects[projectId].series.existsSync(serieId)) {
          console.log('Database integrity error - ', projectId, serieId);
          process.exit(1);
        }
        serie = global.projects[projectId].series.readSync(serieId);
        let newSerieId = serieId.replace(serieIdFind, serieIdReplace);
        if (serie.infos)
          serie.infos = serie.infos.replace(serieInfosFind, serieInfosReplace);
        console.log(projectId, 'Benchmark.series converting "', serieId, '" into "', newSerieId, '"');
        global.projects[projectId].series.writeSync(newSerieId, serie);
        global.projects[projectId].series.deleteSync(serieId);
        series[newSerieId] = series[serieId];
        delete series[serieId];
      }
    }
    series = global.projects[projectId].infos
      .writeSync('benchmarks.series', series);
  }

  let k = Object.keys(global.comparesConfig);
  for (let ii = 0; ii < k.length; ii++) {
    let compareId = k[ii];
    let cp = global.comparesConfig[compareId];
    if (cp.projectId !== projectId) continue;
    let compare = global.projects[projectId].infos
      .readSync('benchmarks.compare_' + compareId);
    kSeries = Object.keys(compare);
    for (let ii = 0; ii < kSeries.length; ii++) {
      serieId = kSeries[ii];
      if (serieId.search(serieIdFind) !== -1) {
        let newSerieId = serieId.replace(serieIdFind, serieIdReplace)
        console.log(projectId, 'Compares Converting "', serieId, '" into "', newSerieId, '"');
        compare[newSerieId] = compare[serieId];
        delete compare[serieId];
      }
    }
    global.projects[projectId].infos
      .writeSync('benchmarks.compare_' + compareId, compare);
  }
}