Skip to content

Commit

Permalink
Vendorize the ooniprobe-cli config
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Jan 12, 2018
1 parent fde1bd2 commit 1e8f131
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main/config/config-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Autogenerated code. Do not edit
import { readFileSync, writeFileSync } from 'fs'

import path from 'path'

import { getOoniDir } from './global-path'

const OONI_DIR = getOoniDir()
const CONFIG_FILE_PATH = path.join(OONI_DIR, 'config.json')

export const prettify = obj => JSON.stringify(obj, null, 2)

export const readConfigFile = () => readFileSync(CONFIG_FILE_PATH, 'utf8')

export const writeToConfigFile = obj => writeFileSync(CONFIG_FILE_PATH, prettify(obj))

export const getConfigFilePath = () => CONFIG_FILE_PATH
79 changes: 79 additions & 0 deletions main/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Autogenerated code. Do not edit
import * as fs from 'fs-extra'
import path from 'path'

import moment from 'moment'
import Sequelize from 'sequelize'

import { getOoniDir } from './global-path'

const debug = require('debug')('config.db')

const OONI_DIR = getOoniDir()

const DB_DIR = path.join(OONI_DIR, 'db')

export const sequelize = new Sequelize({
dialect: 'sqlite',
storage: path.join(DB_DIR, 'main.sqlite3'),
logging: debug,
operatorsAliases: false
})

/* Models */
export const Measurement = sequelize.define('measurement', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
startTime: Sequelize.DATE,
endTime: Sequelize.DATE,
// This is an opaque JSON that is test dependent
summary: Sequelize.JSON,

ip: Sequelize.STRING,
asn: Sequelize.INTEGER,
country: Sequelize.STRING(2),
networkName: Sequelize.STRING,
// The possible states of a measurements are:
// * active, while the measurement is in progress
// * done, when it's finished, but not necessarily uploaded
// * uploaded, if it has been uploaded successfully
// * processed, if the pipeline has processed the measurement
state: {
type: Sequelize.ENUM,
values: ['active', 'done', 'uploaded', 'processed']
},
failure: Sequelize.STRING,

reportFile: Sequelize.STRING,
reportId: Sequelize.STRING,
input: Sequelize.STRING,
measurementId: Sequelize.STRING
})

export const Result = sequelize.define('result', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
startTime: Sequelize.DATE,
endTime: Sequelize.DATE,
summary: Sequelize.JSON,
done: Sequelize.BOOLEAN,
dataUsageUp: Sequelize.INTEGER,
dataUsageDown: Sequelize.INTEGER
})
Result.hasMany(Measurement, { as: 'Measurements' })
sequelize.sync()

export const initDb = async () => {
await fs.ensureDir(DB_DIR)
await sequelize.sync()
}

export default initDb
19 changes: 19 additions & 0 deletions main/config/global-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Autogenerated code. Do not edit
const { homedir } = require('os')
const path = require('path')

const mri = require('mri')

export const getOoniDir = () => {
const args = mri(process.argv.slice(2), {
string: ['ooni-home']
})

const customPath = args['ooni-home']

if (!customPath) {
return path.join(homedir(), '.ooni')
}
return path.resolve(customPath)
}
export default getOoniDir
37 changes: 37 additions & 0 deletions scripts/vendor-ooniprobe-cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from glob import glob
import sys
import shutil

OONIPROBE_DESKTOP_ROOT = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'..'
))

OONIPROBE_CLI_ROOT = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'..',
'..',
'ooniprobe-cli'
))

# Vendorize the config related files from ooniprobe-cli
def main():
if not os.path.isdir(OONIPROBE_CLI_ROOT):
print('error: ooniprobe-cli must exist in ' + OONIPROBE_CLI_ROOT)
sys.exit(1)

ignore_files = ['ipc.js', 'geoip.js']
for path in glob(os.path.join(OONIPROBE_CLI_ROOT, 'src', 'config', '*')):
config_root = os.path.join(OONIPROBE_DESKTOP_ROOT, 'main', 'config')
filename = os.path.basename(path)
if filename in ignore_files:
continue
dst_path = os.path.join(config_root, filename)
with open(path) as in_file:
with open(dst_path, 'w+') as out_file:
out_file.write('// Autogenerated code. Do not edit\n')
shutil.copyfileobj(in_file, out_file)

if __name__ == '__main__':
main()

0 comments on commit 1e8f131

Please sign in to comment.