<commit_before>/**
 *
 *  ioBroker.js-controller Controller start/stop and install script
 *
 *  7'2014 hobbyquaker <<EMAIL>>
 *         bluefox <<EMAIL>>
 *
 *
 */

/* jshint -W097 */// jshint strict:false
/*jslint node: true */
"use strict";


// TODO need info about progress of stopping
// Make command restart

var yargs = require('yargs')
    .usage('Commands:\n' +
        '$0 setup [--couch <host>] [--redis <host>]\n' +
        '$0 start\n' +
        '$0 stop\n' +
        '$0 add <adapter> [--enabled] [--host <host>]\n' +
        '$0 del <adapter>\n' +
        '$0 del <adapter>.<instance>\n' +
        '$0 update <repository url>\n' +
        '$0 upgrade <repository url>\n' +
        '$0 upgrade self <repository url>\n' +
        '$0 upgrade <adapter> <repository url>\n' +
        '$0 object get <id>\n' +
        '$0 state get <id>\n' +
        '$0 state getplain <id>\n' +
        '$0 state set <id> <value>\n' +
        '$0 state setplain <id> <value>\n' +
        '$0 clean\n' +
        '$0 backup\n' +
        '$0 restore <backup name or path>')
    .default('couch',   '127.0.0.1')
    .default('redis',   '127.0.0.1')
    .default('lang',    'en')
;

var Objects; // constructor
var objects; // instance
var fs;
var ncp;
var password;
var tools;
var extend;
var mime;
var os;
var states;

switch (yargs.argv._[0]) {

    case "start":
    case "stop":
        var daemon = require("daemonize2").setup({
            main: "../controller.js",
            name: "ioBroker controller",
            pidfile: __dirname + "/iobroker.pid",
            cwd: "../",
            stopTimeout: 12000
        });
        daemon[yargs.argv._[0]]();
        break;

    case "update":
        fs =            require('fs');
        tools =         require(__dirname + '/tools.js');
        Objects =       require(__dirname + '/objects');
        extend =        require('node.extend');
        var repoUrl =   yargs.argv._[1]; // Repo url or name
        dbConnect(function () {
            showRepo(repoUrl, function () {
                setTimeout(function () {
                    process.exit();
                }, 2000);
            });
        });
        break;

    case "setup":
        fs =            require('fs');
        setup(function () {
            process.exit();
        });
        break;

    case "add":
    case "install":
        fs =            require('fs');
        os =            require('os');

        tools =         require(__dirname + '/tools.js');
        Objects =       require(__dirname + '/objects');

        mime =          require('mime');
        extend =        require('node.extend');
        ncp =           require('ncp').ncp;

        ncp.limit =     16;

        var name =      yargs.argv._[1];
        var repoUrl =   yargs.argv._[2];
        var hostname =  os.hostname();

        if (!fs.existsSync(__dirname + '/../node_modules/iobroker.' + name) && !fs.existsSync(__dirname + '/../adapter/' + name)) {
            downloadPacket(repoUrl, name, function () {
                if (yargs.argv._[0] != 'install') {
                    dbConnect(function () {
                        createInstance(name, yargs.argv.enabled, yargs.argv.host || hostname);
                    });
                }
            });
        } else {
            if (yargs.argv._[0] != 'install') {
                dbConnect(function () {
                    createInstance(name, yargs.argv.enabled, yargs.argv.host || hostname);
                });
            } else {
                console.log('adapter "' + name + '" yet installed. Use "upgrade" to install newer version.');
            }
        }
        break;

    case "upload":
        fs =           require('fs');
        mime =         require('mime');
        tools =        require(__dirname + '/tools.js');
        Objects =      require(__dirname + '/objects');
        var name =     yargs.argv._[1];
        if (name) {
            dbConnect(function () {
                uploadAdapter(name, true, true, function () {
                    uploadAdapter(name, false, true, function () {

                    });<commit_msg>(bluefox) exit by upload adapter<commit_after>/**
 *
 *  ioBroker.js-controller Controller start/stop and install script
 *
 *  7'2014 hobbyquaker <<EMAIL>>
 *         bluefox <<EMAIL>>
 *
 *
 */

/* jshint -W097 */// jshint strict:false
/*jslint node: true */
"use strict";


// TODO need info about progress of stopping
// Make command restart

var yargs = require('yargs')
    .usage('Commands:\n' +
        '$0 setup [--couch <host>] [--redis <host>]\n' +
        '$0 start\n' +
        '$0 stop\n' +
        '$0 add <adapter> [--enabled] [--host <host>]\n' +
        '$0 del <adapter>\n' +
        '$0 del <adapter>.<instance>\n' +
        '$0 update <repository url>\n' +
        '$0 upgrade <repository url>\n' +
        '$0 upgrade self <repository url>\n' +
        '$0 upgrade <adapter> <repository url>\n' +
        '$0 object get <id>\n' +
        '$0 state get <id>\n' +
        '$0 state getplain <id>\n' +
        '$0 state set <id> <value>\n' +
        '$0 state setplain <id> <value>\n' +
        '$0 clean\n' +
        '$0 backup\n' +
        '$0 restore <backup name or path>')
    .default('couch',   '127.0.0.1')
    .default('redis',   '127.0.0.1')
    .default('lang',    'en')
;

var Objects; // constructor
var objects; // instance
var fs;
var ncp;
var password;
var tools;
var extend;
var mime;
var os;
var states;

switch (yargs.argv._[0]) {

    case "start":
    case "stop":
        var daemon = require("daemonize2").setup({
            main: "../controller.js",
            name: "ioBroker controller",
            pidfile: __dirname + "/iobroker.pid",
            cwd: "../",
            stopTimeout: 12000
        });
        daemon[yargs.argv._[0]]();
        break;

    case "update":
        fs =            require('fs');
        tools =         require(__dirname + '/tools.js');
        Objects =       require(__dirname + '/objects');
        extend =        require('node.extend');
        var repoUrl =   yargs.argv._[1]; // Repo url or name
        dbConnect(function () {
            showRepo(repoUrl, function () {
                setTimeout(function () {
                    process.exit();
                }, 2000);
            });
        });
        break;

    case "setup":
        fs =            require('fs');
        setup(function () {
            process.exit();
        });
        break;

    case "add":
    case "install":
        fs =            require('fs');
        os =            require('os');

        tools =         require(__dirname + '/tools.js');
        Objects =       require(__dirname + '/objects');

        mime =          require('mime');
        extend =        require('node.extend');
        ncp =           require('ncp').ncp;

        ncp.limit =     16;

        var name =      yargs.argv._[1];
        var repoUrl =   yargs.argv._[2];
        var hostname =  os.hostname();

        if (!fs.existsSync(__dirname + '/../node_modules/iobroker.' + name) && !fs.existsSync(__dirname + '/../adapter/' + name)) {
            downloadPacket(repoUrl, name, function () {
                if (yargs.argv._[0] != 'install') {
                    dbConnect(function () {
                        createInstance(name, yargs.argv.enabled, yargs.argv.host || hostname);
                    });
                }
            });
        } else {
            if (yargs.argv._[0] != 'install') {
                dbConnect(function () {
                    createInstance(name, yargs.argv.enabled, yargs.argv.host || hostname);
                });
            } else {
                console.log('adapter "' + name + '" yet installed. Use "upgrade" to install newer version.');
            }
        }
        break;

    case "upload":
        fs =           require('fs');
        mime =         require('mime');
        tools =        require(__dirname + '/tools.js');
        Objects =      require(__dirname + '/objects');
        var name =     yargs.argv._[1];
        if (name) {
            dbConnect(function () {
                uploadAdapter(name, true, true, function () {
                    uploadAdapter(name, false, true, function () {
                        process.exit();
                    });
{'fraction_non_alphanumeric': 0.1596921596921597, 'fraction_numerical': 0.013949013949013949, 'mean_word_length': 1.4975975975975977, 'pattern_counts': {'":': 14, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1488203', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2390, 'n_words': 577}