org-converge 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +9 -6
- data/bin/org-converge +1 -1
- data/examples/apt-get-install/setup.org +4 -2
- data/examples/fluentd/setup.org +6 -1
- data/examples/simple/setup.org +16 -13
- data/lib/org-converge.rb +3 -0
- data/lib/org-converge/babel.rb +1 -2
- data/lib/org-converge/command.rb +24 -2
- data/lib/org-converge/version.rb +1 -1
- data/spec/converge_examples/commented_block/run.org +34 -0
- data/spec/converge_examples/specified_block/run.org +21 -0
- data/spec/converge_spec.rb +31 -0
- metadata +14 -10
data/TODO
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#+TODO: TODO | DONE CANCELED
|
3
3
|
#+startup: showeverything
|
4
4
|
|
5
|
-
* [0/
|
5
|
+
* [0/8] > 0.0.9 version
|
6
6
|
|
7
7
|
- [ ] Macros can be loaded and applied to the configuration
|
8
8
|
- [ ] Actually support converging and idempotency
|
@@ -14,12 +14,14 @@
|
|
14
14
|
: org-converge setupfile.org --dry-run
|
15
15
|
- [ ] Use :eval for evaling blocks (off by default)
|
16
16
|
- [ ] Can use :dir for running a process relative to that directory
|
17
|
+
- [ ] Use rake task manager
|
17
18
|
|
18
|
-
* [
|
19
|
+
* [3/3] 0.0.6 version
|
19
20
|
|
20
|
-
- [ ] Keyword to accumulate run blocks
|
21
|
-
- [
|
22
|
-
- [
|
21
|
+
# - [ ] Keyword to accumulate run blocks
|
22
|
+
- [X] Run specific blocks defined by name (using a regex expression)
|
23
|
+
- [X] Change the format of the logger
|
24
|
+
- [X] Do not run blocks in commented headlines
|
23
25
|
|
24
26
|
* [2/2] 0.0.5 version
|
25
27
|
|
@@ -53,7 +55,7 @@ Need some basic functionality of what Org babel offers first.
|
|
53
55
|
- [X] ~--tangle~ flag
|
54
56
|
- [X] Support a root dir for when not running relative to the directory
|
55
57
|
|
56
|
-
* [3/
|
58
|
+
* [3/20] Ideas
|
57
59
|
** CANCELED How to set the permissions from the directory from the file that is being tangled when it does not exists?
|
58
60
|
|
59
61
|
By default, this would be 0644, but we also need to specify the
|
@@ -65,6 +67,7 @@ hmm dont't like this syntax for folders
|
|
65
67
|
|
66
68
|
Let's keep it simple and just use a babel block that shells out to create the directories
|
67
69
|
until I can think of something better.
|
70
|
+
** TODO Inject macros within the environment variables from a runnable process
|
68
71
|
** TODO Clarify which ones of the header arguments to implement
|
69
72
|
|
70
73
|
http://orgmode.org/manual/Specific-header-arguments.html#Specific-header-arguments
|
data/bin/org-converge
CHANGED
@@ -8,7 +8,7 @@ doc = <<OPTIONS
|
|
8
8
|
org-converge: A light configuration management tool for Org mode
|
9
9
|
|
10
10
|
Usage:
|
11
|
-
org-converge <org_file> [--tangle] [--showfiles] [--log=<logfile>] [--root-dir=<root_dir>] [--runmode=<runmode>]
|
11
|
+
org-converge <org_file> [--tangle] [--showfiles] [--log=<logfile>] [--root-dir=<root_dir>] [--runmode=<runmode>] [--name=<block_name>]
|
12
12
|
|
13
13
|
Options:
|
14
14
|
|
@@ -1,9 +1,11 @@
|
|
1
|
-
#+TITLE:
|
1
|
+
#+TITLE: Installing some packages
|
2
|
+
#+runmode: sequential
|
2
3
|
|
3
4
|
* Just install some packages for example
|
4
5
|
|
6
|
+
#+name: install_build_essentials
|
5
7
|
#+begin_src sh
|
6
|
-
sudo apt-get install build-
|
8
|
+
sudo apt-get install build-essential -y
|
7
9
|
#+end_src
|
8
10
|
|
9
11
|
Should be able to be run with something like:
|
data/examples/fluentd/setup.org
CHANGED
@@ -12,7 +12,9 @@ Fluentd can be installed either as a package from treasure data or
|
|
12
12
|
just as a gem. In this example, we only install as a gem:
|
13
13
|
|
14
14
|
# Fails because of permissions
|
15
|
-
|
15
|
+
|
16
|
+
#+name: install_fluentd
|
17
|
+
#+begin_src sh :shebang #!/bin/bash :before all
|
16
18
|
gem list | grep fluentd
|
17
19
|
fluentd_installed=$?
|
18
20
|
if [ $fluentd_installed -ne 0 ]; then
|
@@ -53,6 +55,7 @@ to ~fluentd_filepath~.
|
|
53
55
|
|
54
56
|
Send some logs:
|
55
57
|
|
58
|
+
#+name: flush_logs
|
56
59
|
#+begin_src ruby :shebang #!/usr/local/bin/ruby
|
57
60
|
require 'fluent-logger'
|
58
61
|
|
@@ -70,12 +73,14 @@ end
|
|
70
73
|
|
71
74
|
And yet another process which will be tailing the file that we are sending logs too:
|
72
75
|
|
76
|
+
#+name: tail_logs
|
73
77
|
#+begin_src sh :shebang #!/bin/bash
|
74
78
|
tail -f here.*
|
75
79
|
#+end_src
|
76
80
|
|
77
81
|
* Start which was configured here :start:
|
78
82
|
|
83
|
+
#+name: fluentd_run
|
79
84
|
#+begin_src bash :shebang #!/bin/bash
|
80
85
|
fluentd -c fluentd.conf -vvv
|
81
86
|
#+end_src
|
data/examples/simple/setup.org
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
#+TITLE:
|
1
|
+
#+TITLE: Simple tangle example
|
2
|
+
#+runmode: sequential
|
2
3
|
|
3
4
|
It does not get more simple than this:
|
4
5
|
|
5
|
-
|
6
|
+
First, configure something:
|
6
7
|
|
7
|
-
|
8
|
+
#+begin_src conf :tangle /tmp/my-conf
|
8
9
|
<source>
|
9
10
|
bind 0.0.0.0
|
10
11
|
port 4224
|
@@ -14,29 +15,31 @@ It does not get more simple than this:
|
|
14
15
|
type file
|
15
16
|
path /var/tmp/a.log
|
16
17
|
</match>
|
17
|
-
|
18
|
+
#+end_src
|
18
19
|
|
19
|
-
|
20
|
+
Then run something:
|
20
21
|
|
21
|
-
|
22
|
+
#+name: first_run
|
23
|
+
#+begin_src sh
|
22
24
|
echo "1) Hello world" > /tmp/my-echo
|
23
25
|
echo "2) Hello world" > /tmp/my-echo
|
24
26
|
echo "3) Hello world" > /tmp/my-echo
|
25
|
-
|
27
|
+
#+end_src
|
26
28
|
|
27
|
-
|
29
|
+
Then configure something again:
|
28
30
|
|
29
|
-
|
31
|
+
#+name: second_run
|
32
|
+
#+begin_src sh
|
30
33
|
echo "4) Hello world" >> /tmp/my-echo
|
31
34
|
echo "5) Hello world" >> /tmp/my-echo
|
32
35
|
echo "6) Hello world" >> /tmp/my-echo
|
33
36
|
|
34
37
|
echo "7) Hello world" >> /tmp/my-echo
|
35
|
-
|
38
|
+
#+end_src
|
36
39
|
|
37
|
-
|
40
|
+
And send something to babel once again:
|
38
41
|
|
39
|
-
|
42
|
+
#+begin_src conf :tangle /tmp/hello-conf.yml
|
40
43
|
status_port: 9090
|
41
44
|
no_tab_after_that: true
|
42
|
-
|
45
|
+
#+end_src
|
data/lib/org-converge.rb
CHANGED
@@ -11,6 +11,8 @@ module Orgmode
|
|
11
11
|
# This would return a babel output buffer which has the methods
|
12
12
|
# needed in order to be able to tangle the files
|
13
13
|
def babelize
|
14
|
+
mark_trees_for_export
|
15
|
+
|
14
16
|
# Feed the parsed contens and create the necessary internal structures
|
15
17
|
# for doing babel like features
|
16
18
|
output = ''
|
@@ -20,6 +22,7 @@ module Orgmode
|
|
20
22
|
ob = BabelOutputBuffer.new(output, babel_options)
|
21
23
|
translate(@header_lines, ob)
|
22
24
|
@headlines.each do |headline|
|
25
|
+
next if headline.export_state == :exclude
|
23
26
|
translate(headline.body_lines, ob)
|
24
27
|
end
|
25
28
|
|
data/lib/org-converge/babel.rb
CHANGED
@@ -33,7 +33,6 @@ module Orgmode
|
|
33
33
|
if not Dir.exists?(directory)
|
34
34
|
begin
|
35
35
|
if script[:header][:mkdirp] == 'true'
|
36
|
-
p script
|
37
36
|
logger.info "Create dir for #{file} since it does not exists..."
|
38
37
|
FileUtils.mkdir_p(File.dirname(file), :mode => 0755)
|
39
38
|
else
|
@@ -65,7 +64,7 @@ module Orgmode
|
|
65
64
|
logger.info "Tangling succeeded!"
|
66
65
|
end
|
67
66
|
|
68
|
-
def tangle_runnable_blocks!(run_dir='run')
|
67
|
+
def tangle_runnable_blocks!(run_dir='run', options={})
|
69
68
|
FileUtils.mkdir_p(run_dir)
|
70
69
|
|
71
70
|
logger.info "Tangling #{ob.scripts.count} scripts within directory: #{run_dir}..."
|
data/lib/org-converge/command.rb
CHANGED
@@ -8,7 +8,6 @@ module OrgConverge
|
|
8
8
|
def initialize(options)
|
9
9
|
@options = options
|
10
10
|
@dotorg = options['<org_file>']
|
11
|
-
@logger = Logger.new(options['--log'] || STDOUT)
|
12
11
|
@root_dir = options['--root-dir']
|
13
12
|
@run_dir = if @root_dir
|
14
13
|
File.expand_path(File.join(@root_dir, 'run'))
|
@@ -17,6 +16,10 @@ module OrgConverge
|
|
17
16
|
end
|
18
17
|
@ob = Orgmode::Parser.new(File.read(dotorg)).babelize
|
19
18
|
@babel = nil
|
19
|
+
@logger = Logger.new(options['--log'] || STDOUT)
|
20
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
21
|
+
"[#{datetime.strftime('%Y-%m-%dT%H:%M:%S %z')}] #{msg}\n"
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
def execute!
|
@@ -37,8 +40,11 @@ module OrgConverge
|
|
37
40
|
|
38
41
|
def converge!
|
39
42
|
tangle!
|
40
|
-
|
43
|
+
case
|
44
|
+
when @options['--runmode']
|
41
45
|
dispatch_runmode(@options['--runmode'])
|
46
|
+
when @options['--name']
|
47
|
+
run_matching_blocks!
|
42
48
|
else
|
43
49
|
# Try to find one in the buffer
|
44
50
|
runmode = ob.in_buffer_settings['RUNMODE']
|
@@ -110,6 +116,22 @@ module OrgConverge
|
|
110
116
|
logger.info "Run has completed successfully.".fg 'green'
|
111
117
|
end
|
112
118
|
|
119
|
+
def run_matching_blocks!
|
120
|
+
@engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel)
|
121
|
+
babel.tangle_runnable_blocks!(@run_dir, :filter => @options['--name'])
|
122
|
+
scripts = babel.ob.scripts.select {|k, h| h[:header][:name] =~ Regexp.new(@options['--name']) }
|
123
|
+
scripts.each do |key, script|
|
124
|
+
file = File.expand_path("#{@run_dir}/#{key}")
|
125
|
+
cmd = "#{script[:lang]} #{file}"
|
126
|
+
display_name = script[:header][:name]
|
127
|
+
@engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger }
|
128
|
+
end
|
129
|
+
|
130
|
+
logger.info "Running code blocks now! (#{scripts.count} runnable blocks found in total)"
|
131
|
+
@engine.start
|
132
|
+
logger.info "Run has completed successfully.".fg 'green'
|
133
|
+
end
|
134
|
+
|
113
135
|
def with_running_engine
|
114
136
|
engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel)
|
115
137
|
yield engine
|
data/lib/org-converge/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- mode: org -*-
|
2
|
+
#+TITLE: Runnable vs. Commented blocks
|
3
|
+
#+DATE: 2014-05-03
|
4
|
+
#+STARTUP: showeverything
|
5
|
+
#+NOTEBOOK: commented_block
|
6
|
+
#+runmode: sequential
|
7
|
+
|
8
|
+
** Runnable blocks
|
9
|
+
|
10
|
+
#+name: runnable_block_1
|
11
|
+
#+begin_src sh :results output
|
12
|
+
echo "first" > output.log
|
13
|
+
#+end_src
|
14
|
+
|
15
|
+
** COMMENT Non runnable blocks
|
16
|
+
|
17
|
+
#+name: not_runnable_block_2
|
18
|
+
#+begin_src sh :results output
|
19
|
+
echo "should not run" >> output.log
|
20
|
+
#+end_src
|
21
|
+
|
22
|
+
** More runnable blocks
|
23
|
+
|
24
|
+
#+name: runnable_block_3
|
25
|
+
#+begin_src sh :results output
|
26
|
+
echo "third" >> output.log
|
27
|
+
#+end_src
|
28
|
+
|
29
|
+
*** COMMENT Not runnable block
|
30
|
+
|
31
|
+
#+name: not_runnable_block_4
|
32
|
+
#+begin_src sh :results output
|
33
|
+
echo "fourth" >> output.log
|
34
|
+
#+end_src
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- mode: org -*-
|
2
|
+
#+OPTIONS: ^:nil
|
3
|
+
#+TITLE: Runs specified blocks
|
4
|
+
#+DATE: 2014-05-03
|
5
|
+
#+STARTUP: showeverything
|
6
|
+
|
7
|
+
Considering that there are the following blocks defined:
|
8
|
+
|
9
|
+
#+name: first_block
|
10
|
+
#+begin_src sh
|
11
|
+
echo "Running first block!"
|
12
|
+
echo 'First block' > same.log
|
13
|
+
#+end_src
|
14
|
+
|
15
|
+
Second block:
|
16
|
+
|
17
|
+
#+name: second_block
|
18
|
+
#+begin_src sh
|
19
|
+
echo "Running second block!"
|
20
|
+
echo 'Second block' >> same.log
|
21
|
+
#+end_src
|
data/spec/converge_spec.rb
CHANGED
@@ -38,6 +38,37 @@ describe OrgConverge::Command do
|
|
38
38
|
expected_contents.lines.count.should == 16
|
39
39
|
end
|
40
40
|
|
41
|
+
it "should run specified block from 'specified_block' example" do
|
42
|
+
example_dir = File.join(EXAMPLES_DIR, 'specified_block')
|
43
|
+
setup_file = File.join(example_dir, 'run.org')
|
44
|
+
o = OrgConverge::Command.new({
|
45
|
+
'<org_file>' => setup_file,
|
46
|
+
'--root-dir' => example_dir,
|
47
|
+
'--name' => 'first'
|
48
|
+
})
|
49
|
+
success = o.execute!
|
50
|
+
success.should == true
|
51
|
+
|
52
|
+
expected_contents = File.read(File.join(example_dir, 'same.log'))
|
53
|
+
expected_contents.lines.count.should == 1
|
54
|
+
expected_contents.should == "First block\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should run not commented blocks from 'commented_block' example" do
|
58
|
+
example_dir = File.join(EXAMPLES_DIR, 'commented_block')
|
59
|
+
setup_file = File.join(example_dir, 'run.org')
|
60
|
+
o = OrgConverge::Command.new({
|
61
|
+
'<org_file>' => setup_file,
|
62
|
+
'--root-dir' => example_dir,
|
63
|
+
})
|
64
|
+
success = o.execute!
|
65
|
+
success.should == true
|
66
|
+
|
67
|
+
expected_contents = File.read(File.join(example_dir, 'output.log'))
|
68
|
+
expected_contents.lines.count.should == 2
|
69
|
+
expected_contents.should == "first\nthird\n"
|
70
|
+
end
|
71
|
+
|
41
72
|
it "should converge 'runlist_example' sequentially" do
|
42
73
|
example_dir = File.join(EXAMPLES_DIR, 'runlist_example')
|
43
74
|
setup_file = File.join(example_dir, 'setup.org')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: org-converge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: docopt
|
16
|
-
requirement: &
|
16
|
+
requirement: &70130002051260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70130002051260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: org-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &70130002050780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.4
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70130002050780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: foreman
|
38
|
-
requirement: &
|
38
|
+
requirement: &70130002050320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.63.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70130002050320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: tco
|
49
|
-
requirement: &
|
49
|
+
requirement: &70130002049860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 0.1.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70130002049860
|
58
58
|
description: A light configuration management tool for Org mode
|
59
59
|
email:
|
60
60
|
- waldemar.quevedo@gmail.com
|
@@ -85,7 +85,9 @@ files:
|
|
85
85
|
- spec/converge_examples/basic_run_example/setup.org
|
86
86
|
- spec/converge_examples/basic_tangle/conf.yml.expected
|
87
87
|
- spec/converge_examples/basic_tangle/setup.org
|
88
|
+
- spec/converge_examples/commented_block/run.org
|
88
89
|
- spec/converge_examples/runlist_example/setup.org
|
90
|
+
- spec/converge_examples/specified_block/run.org
|
89
91
|
- spec/converge_spec.rb
|
90
92
|
- spec/spec_helper.rb
|
91
93
|
homepage: https://github.com/wallyqs/org-converge
|
@@ -117,7 +119,9 @@ test_files:
|
|
117
119
|
- spec/converge_examples/basic_run_example/setup.org
|
118
120
|
- spec/converge_examples/basic_tangle/conf.yml.expected
|
119
121
|
- spec/converge_examples/basic_tangle/setup.org
|
122
|
+
- spec/converge_examples/commented_block/run.org
|
120
123
|
- spec/converge_examples/runlist_example/setup.org
|
124
|
+
- spec/converge_examples/specified_block/run.org
|
121
125
|
- spec/converge_spec.rb
|
122
126
|
- spec/spec_helper.rb
|
123
127
|
has_rdoc:
|