britebox 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0949a7ddc1540e0c8374818c3647930eb3560ded
4
- data.tar.gz: 24c7939e3c0ca1e318ea9ff8af22c485649558b9
3
+ metadata.gz: 4b984224096de7c93471e4b5c00df2f83685ceb7
4
+ data.tar.gz: 6f8825ccc06078bd2d86a0e284b4086343c2bd27
5
5
  SHA512:
6
- metadata.gz: c0a6695c78f1daed658d42c1826cb7ad5d43efdb9f3fe35bc7e371a6804e726f5c7d05a47f7a98722a897fd6c3a8efb028165367528d93aa0aa22d4a022d9f3f
7
- data.tar.gz: b71b27e62b1877698515972d0afe8935edbfd262cac51c2087193fdcd83acfa271eac77ba93e7d6535a20f6ed09fcc46cb8b381c7002ac0e7c5e4158156ac2eb
6
+ metadata.gz: 7bcb3672dc53043bb600b140d8193ac065124a3c6f4cda7ee33d396015cc6ed60754543c1299b7c7cefa1787eba96a843004fd52cf9a7b743f5d5184ba314108
7
+ data.tar.gz: 9fcc5126c0c8728402f4dcbec8d14bb749febf1082728d099af763a0c18d6197c9fea5803ae1b42438db4a7a93e353eccd7b7d739da452b08c10fd2fff4e6a7a
data/bin/britebox CHANGED
@@ -89,8 +89,13 @@ if command == 'watch'
89
89
  Britebox::Config.threads = v.to_i
90
90
  end
91
91
 
92
- opts.on('--save', 'Save options to config file') do |v|
93
- params[:save] = true
92
+
93
+ opts.on('-l', '--log [on/off]', 'Enable logging') do |v|
94
+ Britebox::Config.logging_enabled = !['off', 'false', '0'].include?(v.to_s.downcase)
95
+ end
96
+
97
+ opts.on('--log-file LOG_FILE', 'Path to operation log file') do |v|
98
+ Britebox::Config.log_file = v
94
99
  end
95
100
 
96
101
  opts.on('-p', '--port PORT', 'Set port number for web interface, ' +
@@ -110,6 +115,10 @@ if command == 'watch'
110
115
  Britebox::Config.simulate = !['off', 'false', '0'].include?(v.to_s.downcase)
111
116
  end
112
117
 
118
+ opts.on('--save', 'Save options to config file') do |v|
119
+ params[:save] = true
120
+ end
121
+
113
122
  common_opts(opts)
114
123
  end
115
124
 
data/lib/britebox/cli.rb CHANGED
@@ -48,7 +48,9 @@ module Britebox
48
48
  puts "Output directory is #{@out_dir}"
49
49
 
50
50
  if Britebox::Config.simulate
51
- EventLog.add 'WARN', "Running in simulation mode. No real requests to API will be made."
51
+ warn = "Running in simulation mode. No real requests to API will be made."
52
+ EventLog.add 'WARN', warn
53
+ puts warn
52
54
  end
53
55
 
54
56
  puts "Press Ctrl-C to quit"
@@ -7,19 +7,24 @@ module Britebox
7
7
  include Singleton
8
8
  include ActiveModel::Validations
9
9
 
10
- OPTIONS = [:threads, :api_key, :watch_dir, :out_dir, :port, :ui_enabled, :simulate]
10
+ OPTIONS = [
11
+ :threads, :api_key, :watch_dir, :out_dir, :port, :ui_enabled, :simulate,
12
+ :logging_enabled, :log_file
13
+ ]
11
14
  OPTIONS.each { |o| attr_accessor(o) }
12
15
 
13
16
  MAX_THREADS = 10
14
17
 
15
- validates_presence_of :threads, :api_key, :watch_dir, :out_dir, :port
18
+ validates_presence_of :threads, :api_key, :watch_dir, :out_dir, :port, :log_file
16
19
  validates_inclusion_of :port, in: 1..65535, message: ' should be in range 1..65535'
17
20
  validates_inclusion_of :threads, in: 1..MAX_THREADS, message: "should be in range 1..#{MAX_THREADS}"
18
21
  validate :watch_dir_present
19
22
 
20
23
  DEFAULT_OPTIONS = {
21
24
  threads: 10,
22
- port: 7000
25
+ port: 7000,
26
+ logging_enabled: false,
27
+ log_file: '~/britebox.log'
23
28
  }
24
29
 
25
30
  CONFIG_PATH = '~/.britebox.json'
@@ -18,8 +18,7 @@ module Britebox
18
18
  event = OpenStruct.new(type: event_type, message: message, time: Time.now)
19
19
  self.instance.log_lines.push(event)
20
20
 
21
- # if Britebox::Config.log ...
22
- # save event to log
21
+ write_to_log(event)
23
22
 
24
23
  true
25
24
  end
@@ -28,6 +27,18 @@ module Britebox
28
27
  self.instance.log_lines.pop
29
28
  end
30
29
 
30
+ def self.write_to_log(event)
31
+ if Config.logging_enabled
32
+ begin
33
+ File.open(File.expand_path(Config.log_file), 'a+') do |f|
34
+ f.write "#{event.time.to_s} [#{event.type.to_s.upcase}] #{event.message}\n"
35
+ end
36
+ rescue Exception => ex
37
+ print "[ERROR] Can't save log: #{ex.message}\n"
38
+ end
39
+ end
40
+ end
41
+
31
42
  class << self
32
43
  alias_method :add, :push
33
44
  end
@@ -75,7 +75,8 @@ module Britebox
75
75
 
76
76
  def print_event_log
77
77
  if (event = EventLog.pop)
78
- puts "[#{event.type}] #{event.message}"
78
+ # disable printing events for now
79
+ # puts "[#{event.type}] #{event.message}"
79
80
  end
80
81
  end
81
82
 
@@ -1,3 +1,3 @@
1
1
  module Britebox
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -73,9 +73,13 @@ module Britebox
73
73
  data = JSON.parse request.body.read
74
74
 
75
75
  if Config.update(data)
76
+ EventLog.add 'web ui', "Settings updated"
77
+
76
78
  Config.values.to_json
77
79
  else
78
80
  status 422
81
+ EventLog.add 'web ui', "Some errors preventing settings from being saved: #{Config.errors.full_messages.join(', ')}"
82
+
79
83
  {errors: Config.errors.messages}.to_json
80
84
  end
81
85
  end
@@ -118,6 +118,13 @@
118
118
  key: 'port',
119
119
  title: 'Port',
120
120
  help: 'Launch web server on this port'
121
+ }, {
122
+ key: 'logging_enabled',
123
+ title: 'Enable logging',
124
+ type: 'checkbox'
125
+ }, {
126
+ key: 'log_file',
127
+ title: 'Log file'
121
128
  }
122
129
  ];
123
130
  $scope.texts = {
@@ -138,23 +145,13 @@
138
145
  });
139
146
  };
140
147
  $scope.save = function(cb_ok, cb_error) {
141
- var sett;
142
148
  if (cb_ok == null) {
143
149
  cb_ok = null;
144
150
  }
145
151
  if (cb_error == null) {
146
152
  cb_error = null;
147
153
  }
148
- sett = {};
149
- $('.settings-field input.form-control').each(function(k, elem) {
150
- var value;
151
- value = $(elem).val();
152
- if ($scope.isNumber(value)) {
153
- value = parseFloat(value);
154
- }
155
- return sett[$(elem).attr('name')] = value;
156
- });
157
- return $http.post('/settings', sett).success(function(data, status, headers, config) {
154
+ return $http.post('/settings', $scope.settings).success(function(data, status, headers, config) {
158
155
  $scope.errors = {};
159
156
  if (cb_ok) {
160
157
  cb_ok();
@@ -187,10 +184,19 @@
187
184
  return !$scope.errors[field];
188
185
  };
189
186
  $scope.formGroupClass = function(field) {
187
+ var k, type, _i, _len, _ref;
188
+ type = '';
189
+ _ref = $scope.modal_fields;
190
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
191
+ k = _ref[_i];
192
+ if (k.key === field && k.type === 'checkbox') {
193
+ type = 'checkbox ';
194
+ }
195
+ }
190
196
  if ($scope.isValidField(field)) {
191
- return '';
197
+ return type;
192
198
  } else {
193
- return 'has-error';
199
+ return type + 'has-error';
194
200
  }
195
201
  };
196
202
  $scope.isNumber = function(n) {
@@ -8,6 +8,8 @@ app.controller 'SettingsCtrl', ['$scope', '$http', '$injector', ($scope, $http,
8
8
  {key: 'out_dir', title: 'Output directory', help: 'Processed files will be placed here'}
9
9
  {key: 'threads', title: 'Threads', help: 'Number of parallel threads used for processing, minimum is 1, maximum is 10'}
10
10
  {key: 'port', title: 'Port', help: 'Launch web server on this port'}
11
+ {key: 'logging_enabled', title: 'Enable logging', type: 'checkbox'}
12
+ {key: 'log_file', title: 'Log file'}
11
13
  ]
12
14
 
13
15
  $scope.texts = {
@@ -28,13 +30,7 @@ app.controller 'SettingsCtrl', ['$scope', '$http', '$injector', ($scope, $http,
28
30
 
29
31
 
30
32
  $scope.save = (cb_ok = null, cb_error = null) ->
31
- sett = {}
32
- $('.settings-field input.form-control').each (k, elem) ->
33
- value = $(elem).val()
34
- value = parseFloat(value) if $scope.isNumber(value)
35
- sett[$(elem).attr('name')] = value
36
-
37
- $http.post('/settings', sett).success (data, status, headers, config) ->
33
+ $http.post('/settings', $scope.settings).success (data, status, headers, config) ->
38
34
  $scope.errors = {}
39
35
  cb_ok() if cb_ok
40
36
  $injector.get('$rootScope').$broadcast('settingsUpdated')
@@ -62,10 +58,14 @@ app.controller 'SettingsCtrl', ['$scope', '$http', '$injector', ($scope, $http,
62
58
  !$scope.errors[field]
63
59
 
64
60
  $scope.formGroupClass = (field) ->
61
+ type = ''
62
+ for k in $scope.modal_fields
63
+ if k.key == field && k.type == 'checkbox'
64
+ type = 'checkbox '
65
65
  if $scope.isValidField(field)
66
- ''
66
+ type
67
67
  else
68
- 'has-error'
68
+ type + 'has-error'
69
69
 
70
70
  $scope.isNumber = (n) ->
71
71
  !isNaN(parseFloat(n)) && isFinite(n)
@@ -118,6 +118,13 @@
118
118
  key: 'port',
119
119
  title: 'Port',
120
120
  help: 'Launch web server on this port'
121
+ }, {
122
+ key: 'logging_enabled',
123
+ title: 'Enable logging',
124
+ type: 'checkbox'
125
+ }, {
126
+ key: 'log_file',
127
+ title: 'Log file'
121
128
  }
122
129
  ];
123
130
  $scope.texts = {
@@ -138,23 +145,13 @@
138
145
  });
139
146
  };
140
147
  $scope.save = function(cb_ok, cb_error) {
141
- var sett;
142
148
  if (cb_ok == null) {
143
149
  cb_ok = null;
144
150
  }
145
151
  if (cb_error == null) {
146
152
  cb_error = null;
147
153
  }
148
- sett = {};
149
- $('.settings-field input.form-control').each(function(k, elem) {
150
- var value;
151
- value = $(elem).val();
152
- if ($scope.isNumber(value)) {
153
- value = parseFloat(value);
154
- }
155
- return sett[$(elem).attr('name')] = value;
156
- });
157
- return $http.post('/settings', sett).success(function(data, status, headers, config) {
154
+ return $http.post('/settings', $scope.settings).success(function(data, status, headers, config) {
158
155
  $scope.errors = {};
159
156
  if (cb_ok) {
160
157
  cb_ok();
@@ -187,10 +184,19 @@
187
184
  return !$scope.errors[field];
188
185
  };
189
186
  $scope.formGroupClass = function(field) {
187
+ var k, type, _i, _len, _ref;
188
+ type = '';
189
+ _ref = $scope.modal_fields;
190
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
191
+ k = _ref[_i];
192
+ if (k.key === field && k.type === 'checkbox') {
193
+ type = 'checkbox ';
194
+ }
195
+ }
190
196
  if ($scope.isValidField(field)) {
191
- return '';
197
+ return type;
192
198
  } else {
193
- return 'has-error';
199
+ return type + 'has-error';
194
200
  }
195
201
  };
196
202
  $scope.isNumber = function(n) {
@@ -9,13 +9,23 @@
9
9
  <form>
10
10
 
11
11
  <div ng-repeat="opts in modal_fields" class="form-group settings-field {{formGroupClass(opts.key)}}">
12
- <label for="settings-{{opts.key}}" class="control-label">{{opts.title}}</label>
12
+ <label for="settings-{{opts.key}}" class="control-label" ng-if="!opts.type">{{opts.title}}</label>
13
13
  <input type="text"
14
14
  class="form-control"
15
15
  id="settings-{{opts.key}}"
16
16
  placeholder=""
17
17
  name="{{opts.key}}"
18
+ ng-if="!opts.type"
18
19
  ng-model="settings[opts.key]">
20
+
21
+ <label ng-if="opts.type == 'checkbox'">
22
+ <input type="checkbox"
23
+ id="settings-{{opts.key}}"
24
+ name="{{opts.key}}"
25
+ ng-model="settings[opts.key]">
26
+ {{opts.title}}
27
+ </label>
28
+
19
29
  <p class="help-block" ng-if="opts.help && isValidField(opts.key)">{{opts.help}}</p>
20
30
  <p class="help-block" ng-if="!isValidField(opts.key)">{{opts.title}} {{errors[opts.key]}}</p>
21
31
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: britebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shapiotko
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: brite-api