nutella_framework 0.2.0 → 0.2.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: 2e2c581262282b014fb5dc0911616b442534da8c
4
- data.tar.gz: 3908173709fc9ee02ba4cd339615dde180e4776c
3
+ metadata.gz: 4fa6667c9ae02d2334bae79b81176c8297cb4d60
4
+ data.tar.gz: 8a7cbbb915d58d5a7c1de1e4010647a7ef618cd0
5
5
  SHA512:
6
- metadata.gz: 5715373d4edeac20b922d507261b496bb961bc71c3d812e3d5ffd74ddf5ed0904cf096b8929e10788bdae78750e39b40427af224ca65bf46386e3956c8aa0872
7
- data.tar.gz: d7e8d4b278eb8df7275f209cc21828bad2e678ee0116c3d45556245713b8d835256285df2522ded4487607ec0cbf14f22ff95409b2270c4b04bb343861728d11
6
+ metadata.gz: 5fcc6cab7b5665c59329d0e5ed75265094ec763ad7ed20578411696424e90f89ad1a2be1bfffddcaa6366370c6b69109c0ceb381f094d651eb3841696e5f8e87
7
+ data.tar.gz: 42b82c3abefeb8145934b03729b4f93fdce1df48e0a325503c02bab44e04e8b914b0bf04cf1ce5bcbf72215d325292edc4459d65d6ebd38978d735fb2f77eb95
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ gem 'ansi', '~> 1.4', '>= 1.4.3'
4
4
  gem 'semantic', '~> 1.3', '>=1.3'
5
5
  gem 'logging', '~> 1.8', '>=1.8.2'
6
6
  gem 'git', '~> 1.2', '>=1.2.8'
7
- gem 'thin', '~> 1.6.3', '>= 1.6.3'
8
7
  gem 'sinatra', '~>1.4.5', '>=1.4.5'
9
8
  gem 'nokogiri', '~>1.6.3', '>=1.6.3'
10
9
 
data/README.md CHANGED
@@ -5,43 +5,39 @@
5
5
  [![Code Climate](https://codeclimate.com/github/nutella-framework/nutella_framework/badges/gpa.svg)](https://codeclimate.com/github/nutella-framework/nutella_framework)
6
6
 
7
7
  # Nutella
8
- Nutella is a framework to build and run "Internet of Things"-like learning applications. It's still _very_ under development so keep an eye on new versions and help fix the bugs you find by [submitting issues](https://waffle.io/nutella-framework/nutella_framework). Nutella's goal is to be for the "Internet of Things" what Ruby on Rails has been for web applications. Ambitious? You bet, but where is the fun if the challenge is trivial?
8
+ Nutella is a framework to build and run classroom narratives. It's still _very_ under development so any help [finding and fixing bugs](https://github.com/nutella-framework/nutella_framework/issues) will be greatly appreciated!
9
9
 
10
10
  # Installing
11
- Nutella is a ruby gem so to install it we do:
11
+ Nutella is written in ruby but it leverages lots of technologies that already exists. Therefore, before you can successfully install nutella, you need to install (if you don't have them already):
12
+
13
+ 1. _ruby_ (version >= 2.1.0). Do yourself a favor and use [RVM](https://rvm.io/rvm/install).
14
+ 1. _git_ (version >= 1.8.0). Do yourself a favor and use [Homebrew](http://brew.sh/) if you are on OSX.
15
+ 1. _tmux_ (version >= 1.8.0). Do yourself a favor and use [Homebrew](http://brew.sh/) if you are on OSX.
16
+ 1. _node.js_ (version >= 0.10.0). Yes, really, you need to install node becaue we use it to run the broker that handles all communications between all the pieces of the framework. Do yourself a favor and use [nvm](https://github.com/creationix/nvm).
17
+
18
+ Once you have all the pieces that you need, to install nutella simply do:
12
19
  ```
13
20
  gem install nutella_framework
14
21
  ```
15
- If all goes as expected you should be able to type `nutella` in your shell and get a welcome message (yay!) together with a warnining (booooo!). Let's see why...
22
+ Once the installation is complete you should be able to type `nutella` in your shell and get a welcome message.
23
+
24
+ ## nutella checkup
25
+ If you are reading this you probably already saw the warning: "Looks like this is a fresh installation of nutella. Please run 'nutella checkup' to check all dependencies are installed".
16
26
 
17
27
  Nutella is written in ruby but is designed to run bots and interfaces written in virtually any programming language. All communications among these components are routed through an _MQTT broker_ which needs to be installed (together with its dependencies) before nutella can actually work correctly. Therefore **right after your install nutella** you should run:
18
28
  ```
19
29
  nutella checkup
20
30
  ```
21
- in order to make sure all the dependencies have been correctly installed.
31
+ This will install the [Mosca](http://www.mosca.io/) MQTT broker and make sure all the dependencies required by nutella are installed as well.
22
32
 
33
+ Congratulations! Nutella is ready to use!
23
34
 
24
- # Hello world
25
- So what does nutella do for me? Suppose we want to create a new application called "crepe" (because I like nutella crêpes). Let's do that:
26
- ```
27
- nutella new crepe
28
- ```
29
- Nutella will create the basic project structure in a directory called `crepe`. Now that we have created a basic project, we can
30
- ```
31
- cd crepe
32
- ```
33
- and start our new project by doing
34
- ```
35
- nutella start
36
- ```
37
- Pretty boring isn't it? Nothing is happeninig! Why? Well, because the project we just created is simply an empty shell. Let's spice things up a bit and throw some cinnamon into this crêpe!
38
35
 
39
- ## Templates
40
- What are templates? Templates are simply [boilerplate code](http://en.wikipedia.org/wiki/Boilerplate_code) that you don't have to write. Templates are there to simplify your life. Let's see how. Our new application is a ...
41
- **This tutorial is a work in progress**
36
+ # Where next?
37
+ If you already have a projects you want to tinker with (like [RoomQuake](https://github.com/ltg-uic/roomquake)) simply checkout the project to a local folder, `cd /to/my/local/folder` and start tinkering away. Not sure what to do? Check out our [nutella Command Line Tool man page](https://github.com/nutella-framework/nutella_framework/wiki/Nutella-Command-Line-Interface).
42
38
 
39
+ If you want to create your own project, check out the [new project tutorial](https://github.com/nutella-framework/nutella_framework/wiki/New-project-tutorial).
43
40
 
44
- For a complete guide on how to use Nutella, please refer to [this wiki](https://github.com/nutella-framework/nutella_framework/wiki).
45
41
 
46
- # Building & contributing
47
- Clone the repo, `bundle install` to take care of the dependencies and then `rake` to run all the tests. If you want to perform some fancier task simply type `rake -T` for a list of awesomeness.
42
+ # Contributing
43
+ Check out our [contributing wiki page](https://github.com/nutella-framework/nutella_framework/wiki/Contributing)! Thanks!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -15,6 +15,9 @@ rescue
15
15
  abort 'Impossible to parse configuration and/or runlist files!'
16
16
  end
17
17
 
18
+ # Set Sinatra to run in production mode
19
+ set :environment, :production
20
+
18
21
  # Set Sinatra's port to nutella's main_interface_port
19
22
  set :port, config_h['main_interface_port']
20
23
 
@@ -26,7 +29,7 @@ end
26
29
 
27
30
 
28
31
  # Renders the run template
29
- get '/:run_id' do
32
+ get '/:run_id/?' do
30
33
 
31
34
  # Parse the run_id from URL and extract the run path from runlist.json
32
35
  @run_id = params[:run_id]
@@ -1,5 +1,5 @@
1
1
  #!/bin/sh
2
2
 
3
3
  BASEDIR=$(dirname $0)
4
- ruby $BASEDIR/main_interface_bot.rb $1 $2 &>/dev/null &
4
+ ruby $BASEDIR/main_interface_bot.rb $1 $2 > /dev/null 2>&1 &
5
5
  echo $! > $BASEDIR/.pid
@@ -43,9 +43,12 @@ module Nutella
43
43
 
44
44
  def add_to_run_list(run_id, prj_dir)
45
45
  unless Nutella.runlist.add?( run_id, prj_dir )
46
- console.error 'Impossible to start project: an instance of this project with the same run_id is already running!'
47
- console.error "You might want to kill it with 'nutella stop #{run_id}'"
48
- return false
46
+ # If the run_id is already in the list, check that it's actually live
47
+ if Tmux.session_exists? run_id
48
+ console.error 'Impossible to start project: an instance of this project with the same run_id is already running!'
49
+ console.error "You might want to kill it with 'nutella stop #{run_id}'"
50
+ return false
51
+ end
49
52
  end
50
53
  true
51
54
  end
@@ -54,13 +57,18 @@ module Nutella
54
57
  def start_internal_broker
55
58
  pid_file_path = "#{Nutella.config['broker_dir']}bin/.pid"
56
59
  return true if sanitize_pid_file pid_file_path
60
+ # Check that broker is not running unsupervised (check port)
61
+ unless broker_port_free?
62
+ console.error 'Impossible to start project: looks like a broker is already running on port 1883. Stop it before trying to start the project again'
63
+ return false
64
+ end
57
65
  # Broker is not running and there is no file so we try to start
58
66
  # and create a new pid file. Note that the pid file is created by
59
67
  # the startup script!
60
68
  pid = fork
61
69
  exec("#{Nutella.config['broker_dir']}/startup") if pid.nil?
62
70
  # Sleep a bit to give the chance to the broker to actually start up
63
- sleep(0.8)
71
+ sleep(1)
64
72
  # All went well so we return true
65
73
  true
66
74
  end
@@ -93,6 +101,19 @@ module Nutella
93
101
  end
94
102
 
95
103
 
104
+ # Checks if port 1883 (MQTT broker port) is free
105
+ # or some other service is already listening on it
106
+ def broker_port_free?
107
+ begin
108
+ s = TCPServer.new('0.0.0.0', 1883)
109
+ s.close
110
+ rescue
111
+ return false
112
+ end
113
+ true
114
+ end
115
+
116
+
96
117
  def start_nutella_actors
97
118
  nutella_actors_dir = "#{Nutella.config['nutella_home']}actors"
98
119
  for_each_actor_in_dir nutella_actors_dir do |actor|
data/lib/core/tmux.rb CHANGED
@@ -25,24 +25,13 @@ module Nutella
25
25
  `tmux send-keys "cd bots/#{bot};./startup #{@run_id} #{Nutella.config['broker']}" C-m`
26
26
  end
27
27
 
28
- def new_interface_window( iface )
29
- # Create new window for `iface`
30
- # note: -k option destroys it if it can't be created
31
- # hide window creation info
32
- `tmux new-window -kP -n #{iface} &> /dev/null`
33
- @sessions.push(iface)
34
- # Select window
35
- `tmux select-window -t #{@run_id}:#{@sessions.length-1} &> /dev/null`
36
- port = Nutella.config['main_interface_port'] + @sessions.length
37
- url = "http://localhost:#{port}/index.html"
38
- # Start serving interface
39
- `tmux send-keys "cd interfaces/#{iface};thin -R #{Nutella.config['nutella_home']}/lib/extra/config.ru -p #{port.to_s} start" C-m`
40
- url
41
- end
42
-
43
28
  def self.kill_session( run_id )
44
29
  `tmux kill-session -t #{run_id} &> /dev/null`
45
30
  end
31
+
32
+ def self.session_exists?( run_id )
33
+ system( "tmux has-session -t #{run_id} &> /dev/null" )
34
+ end
46
35
 
47
36
  end
48
37
 
@@ -2,16 +2,16 @@
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.2.0 ruby lib
5
+ # stub: nutella_framework 0.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "nutella_framework"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.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 = "2014-11-26"
14
+ s.date = "2015-01-20"
15
15
  s.description = "Nutella is a framework to build and run \"Internet of Things\"-like learning applications"
16
16
  s.email = "tebemis@gmail.com"
17
17
  s.executables = ["nutella"]
@@ -74,7 +74,6 @@ Gem::Specification.new do |s|
74
74
  s.add_runtime_dependency(%q<semantic>, [">= 1.3", "~> 1.3"])
75
75
  s.add_runtime_dependency(%q<logging>, [">= 1.8.2", "~> 1.8"])
76
76
  s.add_runtime_dependency(%q<git>, [">= 1.2.8", "~> 1.2"])
77
- s.add_runtime_dependency(%q<thin>, [">= 1.6.3", "~> 1.6.3"])
78
77
  s.add_runtime_dependency(%q<sinatra>, [">= 1.4.5", "~> 1.4.5"])
79
78
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.6.3", "~> 1.6.3"])
80
79
  s.add_development_dependency(%q<shoulda>, [">= 3", "~> 3"])
@@ -88,7 +87,6 @@ Gem::Specification.new do |s|
88
87
  s.add_dependency(%q<semantic>, [">= 1.3", "~> 1.3"])
89
88
  s.add_dependency(%q<logging>, [">= 1.8.2", "~> 1.8"])
90
89
  s.add_dependency(%q<git>, [">= 1.2.8", "~> 1.2"])
91
- s.add_dependency(%q<thin>, [">= 1.6.3", "~> 1.6.3"])
92
90
  s.add_dependency(%q<sinatra>, [">= 1.4.5", "~> 1.4.5"])
93
91
  s.add_dependency(%q<nokogiri>, [">= 1.6.3", "~> 1.6.3"])
94
92
  s.add_dependency(%q<shoulda>, [">= 3", "~> 3"])
@@ -103,7 +101,6 @@ Gem::Specification.new do |s|
103
101
  s.add_dependency(%q<semantic>, [">= 1.3", "~> 1.3"])
104
102
  s.add_dependency(%q<logging>, [">= 1.8.2", "~> 1.8"])
105
103
  s.add_dependency(%q<git>, [">= 1.2.8", "~> 1.2"])
106
- s.add_dependency(%q<thin>, [">= 1.6.3", "~> 1.6.3"])
107
104
  s.add_dependency(%q<sinatra>, [">= 1.4.5", "~> 1.4.5"])
108
105
  s.add_dependency(%q<nokogiri>, [">= 1.6.3", "~> 1.6.3"])
109
106
  s.add_dependency(%q<shoulda>, [">= 3", "~> 3"])
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.2.0
4
+ version: 0.2.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: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ansi
@@ -90,26 +90,6 @@ dependencies:
90
90
  - - "~>"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '1.2'
93
- - !ruby/object:Gem::Dependency
94
- name: thin
95
- requirement: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: 1.6.3
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 1.6.3
103
- type: :runtime
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: 1.6.3
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: 1.6.3
113
93
  - !ruby/object:Gem::Dependency
114
94
  name: sinatra
115
95
  requirement: !ruby/object:Gem::Requirement