<commit_before>/*
 * Scanner.js
 * A simple node app to communicate with a set of Code Scanner 3500 units 
 * and push scans to an API endpoint. 
 *
 * Code Scanner 3500 settings: 
 *		usb keyboard factory reset, save, send and log mode, qr code on, save
 */
(function() {
	var self = this;
	var request = require('request');
	var fs = require('fs');
	var os = require('os');
	var prompt = require('prompt');
	var RSVP = require('rsvp');

	this.HID = require('node-hid');
	this.config = require('./config');
	this.activeDevices = {};
	this.scanData = [];
	this.errData = [];
	this.loop = null;
	this.mac = null;
	this.sendErrorCount = 0;

	var ExitError = {};

	/*
	 *  DEAL WITH COMMAND LINE INPUTS
	 */
	this.hasArguments = function() {
		return process.argv.length > 2;
	};

	this.processArguments = function() {
		var i = 0;
		for (var i=0; i < process.argv.length; i++) {
			if ([0,1].indexOf(i) > -1) {
				i++;
				continue;
			}

			var val = process.argv[i];

			switch(val) {
				case 'devices':
				case '--devices':
				case '-d':
					console.log(self.HID.devices());
					throw ExitError;
				break;

				case 'hostname':
				case '--hostname':
				case '-ho':
					console.log(os.hostname());
					throw ExitError;
				break;

				case 'config':
				case '--config':
				case '-c':
					console.log(self.config);
					throw ExitError;
				break;

				case 'help':
				case '--help':
				case '-h':
					console.log('\n  SCANNER.JS CODE READER 3500 SCAN SERVER');
					console.log('  Written by <NAME> 2014.\n')
					console.log('  USE: sudo node scanner [options]');
					console.log('  OPTIONS ARE ONE OF: ');
					console.log('\t[none]   -> start the scan server');
					console.log('\tdevices  -> list all connected usb devices');
					console.log('\thostname -> display the machine\'s hostname');
					console.log('\tconfig   -> dump app configuration');

					throw ExitError;
				break

				case 'logtype':
				case '--logtype':
				case '-l':
					var nextIndex = i+1;
					self.config.logType = process.argv[nextIndex];
					console.log('log type set to '+self.config.logType);
					return false;
				break

				case '--clear-logs':
				case 'clear-logs':
					var logs = ['debug_log', 'scan_log', 'error_log'];

					for (var i=0; i < logs.length; i++) {
						var log = logs[i];
						fs.writeFile(config[log], '', function(err) {
							if (err) console.log('could not write to '+log);
						});
					}

					throw ExitError;
				break

				case '--push-logs':
				case 'push-logs':
					var data = fs.readFileSync(config['scan_log']);<commit_msg>Added push logs test<commit_after>/*
 * Scanner.js
 * A simple node app to communicate with a set of Code Scanner 3500 units 
 * and push scans to an API endpoint. 
 *
 * Code Scanner 3500 settings: 
 *		usb keyboard factory reset, save, send and log mode, qr code on, save
 */
(function() {
	var self = this;
	var request = require('request');
	var fs = require('fs');
	var os = require('os');
	var prompt = require('prompt');
	var RSVP = require('rsvp');

	this.HID = require('node-hid');
	this.config = require('./config');
	this.activeDevices = {};
	this.scanData = [];
	this.errData = [];
	this.loop = null;
	this.mac = null;
	this.sendErrorCount = 0;

	var ExitError = {};

	/*
	 *  DEAL WITH COMMAND LINE INPUTS
	 */
	this.hasArguments = function() {
		return process.argv.length > 2;
	};

	this.processArguments = function() {
		var i = 0;
		for (var i=0; i < process.argv.length; i++) {
			if ([0,1].indexOf(i) > -1) {
				i++;
				continue;
			}

			var val = process.argv[i];

			switch(val) {
				case 'devices':
				case '--devices':
				case '-d':
					console.log(self.HID.devices());
					throw ExitError;
				break;

				case 'hostname':
				case '--hostname':
				case '-ho':
					console.log(os.hostname());
					throw ExitError;
				break;

				case 'config':
				case '--config':
				case '-c':
					console.log(self.config);
					throw ExitError;
				break;

				case 'help':
				case '--help':
				case '-h':
					console.log('\n  SCANNER.JS CODE READER 3500 SCAN SERVER');
					console.log('  Written by <NAME> 2014.\n')
					console.log('  USE: sudo node scanner [options]');
					console.log('  OPTIONS ARE ONE OF: ');
					console.log('\t[none]   -> start the scan server');
					console.log('\tdevices  -> list all connected usb devices');
					console.log('\thostname -> display the machine\'s hostname');
					console.log('\tconfig   -> dump app configuration');

					throw ExitError;
				break

				case 'logtype':
				case '--logtype':
				case '-l':
					var nextIndex = i+1;
					self.config.logType = process.argv[nextIndex];
					console.log('log type set to '+self.config.logType);
					return false;
				break

				case '--clear-logs':
				case 'clear-logs':
					var logs = ['debug_log', 'scan_log', 'error_log'];

					for (var i=0; i < logs.length; i++) {
						var log = logs[i];
						fs.writeFile(config[log], '', function(err) {
							if (err) console.log('could not write to '+log);
						});
					}

					throw ExitError;
				break

				case '--push-logs':
				case 'push-logs':
					var data = fs.readFileSync(config['scan_log'], 'utf8');
{'fraction_non_alphanumeric': 0.1629529161015307, 'fraction_numerical': 0.009881805851579151, 'mean_word_length': 2.582234559333796, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7073344', 'n_tokens_mistral': 2226, 'n_tokens_neox': 1713, 'n_words': 487}