-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |