nutella_framework 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25372f33a5d356902733e9c5c56e632cf7d03f00
4
- data.tar.gz: 615a93c90ef6cba3206ee4f10e819bd3179c58fe
3
+ metadata.gz: 74e4ed28b0dc3798dd7c0d2316d4cc1b7b4b00dc
4
+ data.tar.gz: 8b1bd9b75e807c5e061720bdf21a2a367c969d6b
5
5
  SHA512:
6
- metadata.gz: 12dd8ec3456123428114c3c9b1c32eb611ff51c46346a7e1d2cb834ce76bc9fcbcd0efa3b65423c73fe2ba9f4359a2e58df056cd0454a1254a6368771e210495
7
- data.tar.gz: 605229b6c2f71386d74b7930d23b80ab89e55e52d0eb35293348029c036923d71f196cf4c4bb60166d272607bed4cfa9c96a22d8d0fb5a3bb819603836e5a2a7
6
+ metadata.gz: b7416f84abc2fcde32f84d728d41c9f229e194aadf07be54f77e54231b33f3359f932d1742259064a3e29987072836811cdd485b921fd59f4bff3cf22b34e7bd
7
+ data.tar.gz: 9e03507f6f0a018ad06c64ac5b29b02d6989b5fbebb323ff1edc588e464ddb51aa3351c21bf26fa0c7d5407edef08a77df1529ea2b9a59d3533f8aa919b60bae
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "nutella_framework"
18
18
  gem.homepage = "https://github.com/nutella-framework/nutella_framework"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{IoT-like learning applications framework}
21
- gem.description = %Q{Nutella is a framework to build and run "Internet of Things"-like learning applications}
20
+ gem.summary = %Q{A framework to create and run classroom narratives}
21
+ gem.description = %Q{Nutella is a framework to create and run classroom narratives}
22
22
  gem.email = "tebemis@gmail.com"
23
23
  gem.authors = ["Alessandro Gnoli"]
24
24
  # dependencies defined in Gemfile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/config/config.rb CHANGED
@@ -5,7 +5,7 @@ module Nutella
5
5
  # Calling this method (Nutella.config) simply returns and instance of
6
6
  # PersistedHash linked to file config.json in nutella home directory
7
7
  def Nutella.config
8
- PersistedHash.new("#{File.dirname(__FILE__)}/../../config.json")
8
+ PersistedHash.new( "#{ENV['HOME']}/.nutella/config.json" )
9
9
  end
10
10
 
11
11
  end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'fileutils'
2
3
 
3
4
  module Nutella
4
5
 
@@ -90,6 +91,8 @@ module Nutella
90
91
  private
91
92
 
92
93
  def store_hash(hash)
94
+ dirname = File.dirname(@config_file)
95
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
93
96
  File.open(@config_file, 'w+') do |f|
94
97
  f.write(JSON.pretty_generate(hash))
95
98
  end
@@ -26,7 +26,7 @@ module Nutella
26
26
  # Calling this method (Nutella.runlist) simply returns and instance of
27
27
  # RunListHash linked to file runlist.json in the nutella home directory
28
28
  def Nutella.runlist
29
- RunListHash.new( "#{File.dirname(__FILE__)}/../../runlist.json" )
29
+ RunListHash.new( "#{ENV['HOME']}/.nutella/runlist.json" )
30
30
  end
31
31
 
32
32
  end
@@ -35,12 +35,13 @@ module Nutella
35
35
 
36
36
  def install_local_broker
37
37
  # Clone, cd and npm install
38
- out1 = system "git clone git://github.com/mcollina/mosca.git #{Nutella.config['broker_dir']} > /dev/null 2>&1"
38
+ broker_version = 'v0.28.1'
39
+ out1 = system "git clone -b #{broker_version} --depth 1 git://github.com/mcollina/mosca.git #{Nutella.config['broker_dir']} > /dev/null 2>&1"
39
40
  Dir.chdir(Nutella.config['broker_dir'])
40
41
  out2 = system 'npm install > /dev/null 2>&1'
41
42
 
42
43
  # Add startup script and make it executable
43
- File.open('startup', 'w') { |file| file.write("#!/bin/sh\n\nBASEDIR=$(dirname $0)\n$BASEDIR/bin/mosca --http-port 1884 &\necho $! > $BASEDIR/bin/.pid\n") }
44
+ File.open('startup', 'w') { |file| file.write("#!/bin/sh\n\nBASEDIR=$(dirname $0)\n$BASEDIR/bin/mosca --http-port 1884 > /dev/null 2>&1 &\necho $! > $BASEDIR/bin/.pid\n") }
44
45
  File.chmod( 0755, 'startup' )
45
46
 
46
47
  # Write configuration into config.json
@@ -47,8 +47,13 @@ module Nutella
47
47
 
48
48
 
49
49
  def is_template_a_git_repo?( template_git_url )
50
+ return false unless template_git_url =~ /\A#{URI::regexp(['http', 'https'])}\z/
50
51
  begin
51
- tmp_dest_dir = template_git_url[template_git_url.rindex('/')+1 .. template_git_url.length-5]
52
+ if template_git_url.end_with? '.git'
53
+ tmp_dest_dir = template_git_url[template_git_url.rindex('/')+1 .. template_git_url.length-5]
54
+ else
55
+ tmp_dest_dir = template_git_url[template_git_url.rindex('/')+1 .. template_git_url.length]
56
+ end
52
57
  clone_template_from_repo_to( template_git_url, tmp_dest_dir )
53
58
  return validate_template "#{Nutella.config['tmp_dir']}/#{tmp_dest_dir}"
54
59
  rescue
@@ -46,7 +46,7 @@ module Nutella
46
46
  config_file_hash = {
47
47
  :name => cur_prj_dir,
48
48
  :version => '0.1.0',
49
- :nutella_version => File.open("#{NUTELLA_HOME}VERSION", 'rb').read,
49
+ :nutella_version => File.open("#{Nutella.config['nutella_home']}VERSION", 'rb').read,
50
50
  :type => 'project',
51
51
  :description => 'A quick description of your project'
52
52
  }
@@ -38,7 +38,7 @@ module Nutella
38
38
 
39
39
  # Check that there is at least a regular bot that will be started,
40
40
  # otherwise it makes no sense to create a run
41
- if run_bots_list_minus_project_bots(cur_prj_dir, params).empty? && project_bots_started?
41
+ if bots_list_wo_project(cur_prj_dir, params).empty? && project_bots_started?
42
42
  console.warn "Run #{run} not created: your project bots are already started and you specified no regular bots exclusively for this run"
43
43
  return
44
44
  end
@@ -48,7 +48,7 @@ module Nutella
48
48
  return unless add_to_run_list( run_id, cur_prj_dir )
49
49
 
50
50
  # If running on the internal broker, start it if needed
51
- if Nutella.config['broker'] == 'localhost'
51
+ if running_on_internal_broker?
52
52
  return unless start_internal_broker
53
53
  end
54
54
 
@@ -70,7 +70,7 @@ module Nutella
70
70
  private
71
71
 
72
72
 
73
- def run_bots_list_minus_project_bots( cur_prj_dir, params )
73
+ def bots_list_wo_project( cur_prj_dir, params )
74
74
  # Fetch the list of project bots
75
75
  project_bots_list = Nutella.current_project.config['project_bots']
76
76
  run_bots_list = run_actors_list("#{cur_prj_dir}/bots/")
@@ -90,7 +90,7 @@ module Nutella
90
90
  def project_bots_started?
91
91
  project_name = Nutella.current_project.config['name']
92
92
  tmux_session_name = "#{project_name}-project-bots"
93
- return Tmux.session_exist? tmux_session_name
93
+ Tmux.session_exist? tmux_session_name
94
94
  end
95
95
 
96
96
 
@@ -186,8 +186,8 @@ module Nutella
186
186
  # Actor is not running and there is no pid file so we try to start
187
187
  # the actor and create a new pid file. Note that the pid file is created by
188
188
  # the startup script!
189
- nutella_config_file = "#{Nutella.config['nutella_home']}config.json"
190
- runs_list_file = "#{Nutella.config['nutella_home']}runlist.json"
189
+ nutella_config_file = "#{Nutella.config['config_dir']}config.json"
190
+ runs_list_file = "#{Nutella.config['config_dir']}runlist.json"
191
191
  if nutella_config_file==nil || runs_list_file==nil
192
192
  return false
193
193
  end
@@ -231,7 +231,7 @@ module Nutella
231
231
  # Fetch bots dir
232
232
  bots_dir = "#{cur_prj_dir}/bots/"
233
233
  # Start the appropriate bots
234
- run_bots_list_minus_project_bots( cur_prj_dir, params ).each { |bot| start_bot(bots_dir, bot, tmux) }
234
+ bots_list_wo_project( cur_prj_dir, params ).each { |bot| start_bot(bots_dir, bot, tmux) }
235
235
  true
236
236
  end
237
237
 
@@ -255,7 +255,7 @@ module Nutella
255
255
  unless project_bots_list.nil? || project_bots_list.empty?
256
256
  console.success "Do `tmux attach-session -t #{tmux_session_name}` to monitor your project bots."
257
257
  end
258
- if run_bots_list_minus_project_bots(cur_prj_dir, params).empty?
258
+ if bots_list_wo_project(cur_prj_dir, params).empty?
259
259
  console.success 'No tmux session was created for this run because you specified no regular bots exclusively for this run'
260
260
  else
261
261
  console.success "Do `tmux attach-session -t #{run_id}` to monitor your bots."
@@ -29,7 +29,7 @@ module Nutella
29
29
  end
30
30
 
31
31
  # If running on the internal broker, stop it if needed
32
- if Nutella.runlist.empty? and Nutella.config['broker'] == 'localhost'
32
+ if Nutella.runlist.empty? and running_on_internal_broker?
33
33
  stop_broker
34
34
  end
35
35
 
@@ -29,14 +29,16 @@ module Nutella
29
29
  end
30
30
 
31
31
  # This method initializes the nutella configuration file (config.json) with:
32
- # - NUTELLA_HOME: the directory nutella is installed in
32
+ # - nutella_home: the directory nutella is installed in
33
33
  # - tmp_dir: temporary directory used when installing remote templates
34
+ # - config_dir: directory where the configuration files are stored in
34
35
  # - broker_dir: directory where the local broker is installed in
35
36
  # - main_interface_port: the port used to serve interfaces
36
37
  def Nutella.init
37
38
  Nutella.config['nutella_home'] = NUTELLA_HOME
38
39
  Nutella.config['tmp_dir'] = "#{NUTELLA_HOME}.tmp/"
39
- Nutella.config['broker_dir'] = "#{NUTELLA_HOME}broker/"
40
+ Nutella.config['config_dir'] = "#{ENV['HOME']}/.nutella/"
41
+ Nutella.config['broker_dir'] = "#{Nutella.config['config_dir']}broker/"
40
42
  Nutella.config['main_interface_port'] = 57880
41
43
  end
42
44
 
@@ -93,6 +93,14 @@ module Nutella
93
93
  end
94
94
 
95
95
 
96
+ # If the broker is set to one of the current ip addresses,
97
+ # localhost or 127.0.0.1 return true.
98
+ def running_on_internal_broker?
99
+ broker = Nutella.config['broker']
100
+ Socket.ip_address_list.find_all{|a| a.ipv4? }.map{|a| a.ip_address}.include?(broker) || broker == 'localhost' || broker == '127.0.0.1'
101
+ end
102
+
103
+
96
104
  end
97
105
 
98
106
  end
@@ -7,6 +7,7 @@ require 'config/current_project'
7
7
  require 'cli/nutella_cli'
8
8
 
9
9
  module Nutella
10
+ # Initialize nutella home
10
11
  home_dir = File.dirname(__FILE__)
11
12
  NUTELLA_HOME = home_dir[0..-4]
12
13
 
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: nutella_framework 0.3.0 ruby lib
5
+ # stub: nutella_framework 0.3.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "nutella_framework"
9
- s.version = "0.3.0"
9
+ s.version = "0.3.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Alessandro Gnoli"]
14
- s.date = "2015-01-29"
15
- s.description = "Nutella is a framework to build and run \"Internet of Things\"-like learning applications"
14
+ s.date = "2015-02-26"
15
+ s.description = "Nutella is a framework to create and run classroom narratives"
16
16
  s.email = "tebemis@gmail.com"
17
17
  s.executables = ["nutella"]
18
18
  s.extra_rdoc_files = [
@@ -70,8 +70,8 @@ Gem::Specification.new do |s|
70
70
  ]
71
71
  s.homepage = "https://github.com/nutella-framework/nutella_framework"
72
72
  s.licenses = ["MIT"]
73
- s.rubygems_version = "2.2.2"
74
- s.summary = "IoT-like learning applications framework"
73
+ s.rubygems_version = "2.4.3"
74
+ s.summary = "A framework to create and run classroom narratives"
75
75
 
76
76
  if s.respond_to? :specification_version then
77
77
  s.specification_version = 4
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutella_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Gnoli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ansi
@@ -270,8 +270,7 @@ dependencies:
270
270
  - - "~>"
271
271
  - !ruby/object:Gem::Version
272
272
  version: '0'
273
- description: Nutella is a framework to build and run "Internet of Things"-like learning
274
- applications
273
+ description: Nutella is a framework to create and run classroom narratives
275
274
  email: tebemis@gmail.com
276
275
  executables:
277
276
  - nutella
@@ -347,8 +346,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
346
  version: '0'
348
347
  requirements: []
349
348
  rubyforge_project:
350
- rubygems_version: 2.2.2
349
+ rubygems_version: 2.4.3
351
350
  signing_key:
352
351
  specification_version: 4
353
- summary: IoT-like learning applications framework
352
+ summary: A framework to create and run classroom narratives
354
353
  test_files: []