specks 0.2.0

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.
Files changed (3) hide show
  1. data/bin/specks +10 -0
  2. data/lib/specks.rb +101 -0
  3. metadata +48 -0
data/bin/specks ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'specks'
4
+
5
+ app = Specks.new
6
+ if ARGV.size > 0
7
+ app.run_one(ARGV[0])
8
+ else
9
+ app.run_all
10
+ end
data/lib/specks.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+
4
+ # usage: specks [module]
5
+ class Specks
6
+
7
+ DOT_ROOT = File.join(ENV["HOME"], '.dot')
8
+ MODULES_DIR = "#{DOT_ROOT}/modules"
9
+ EXPORTS_DIR = "#{DOT_ROOT}/.exports"
10
+
11
+ def run_one(mod)
12
+
13
+ recipe_path = "#{MODULES_DIR}/#{mod}/recipe.yml"
14
+ if File.exists?(recipe_path)
15
+ recipe = YAML.load_file(recipe_path)
16
+
17
+ comment = recipe[:comment] || '#'
18
+
19
+ (recipe[:export] || {}).each do |file|
20
+ export mod, file, comment
21
+ end
22
+
23
+ (recipe[:symlink] || {}).each do |file, dest|
24
+ export mod, file, comment
25
+ symlink mod, file, dest
26
+ end
27
+
28
+ (recipe[:inject] || {}).each do |file, dest|
29
+ inject mod, file, dest, comment
30
+ end
31
+
32
+ else
33
+ puts "No recipe.yml for #{mod}, skipping"
34
+ end
35
+
36
+ end
37
+
38
+ def run_all
39
+ modules = Dir.entries(MODULES_DIR).reject {|e| e == '.' || e == '..'}
40
+ modules.each {|name| run_one(name)}
41
+ end
42
+
43
+ private
44
+
45
+ def bannerise(source, mod, file, action, comment)
46
+ "#{comment} -- [specks:start #{action} #{file}] --\n" +
47
+ "#{source.chomp}\n" +
48
+ "#{comment} -- [specks:end #{action} #{file}] --\n"
49
+ end
50
+
51
+ def export(mod, file, comment)
52
+ FileUtils.mkdir_p("#{EXPORTS_DIR}/#{mod}") unless File.exists?("#{EXPORTS_DIR}/#{mod}")
53
+
54
+ puts "Exporting #{file} for #{mod}"
55
+ if File.directory?("#{MODULES_DIR}/#{mod}/#{file}")
56
+ # TODO: no banner?
57
+ FileUtils.cp_r("#{MODULES_DIR}/#{mod}/#{file}",
58
+ "#{EXPORTS_DIR}/#{mod}/#{file}")
59
+ else
60
+ source = File.read("#{MODULES_DIR}/#{mod}/#{file}")
61
+ File.open("#{EXPORTS_DIR}/#{mod}/#{file}", 'w') do |f|
62
+ # TODO: run through erb ?
63
+ # add banner at the beginning and end
64
+ bannered = bannerise(source, mod, file, 'export', comment)
65
+ f.write(bannered)
66
+ end
67
+ end
68
+ end
69
+
70
+ def symlink(mod, file, dest)
71
+ dest_path = File.expand_path(dest)
72
+ if File.exists?(dest_path) && ! File.symlink?(dest_path)
73
+ # TODO: iff ! symlink pointing to the same place
74
+ puts "Skipping symlinking to #{dest}, file exists"
75
+ else
76
+ # TODO: check if file pristine, i.e. nothing before/after banner
77
+ puts "Symlink #{file} for #{mod} to #{dest}"
78
+
79
+ FileUtils.mkdir_p File.dirname(dest_path)
80
+ FileUtils.rm_rf(dest_path)
81
+ FileUtils.ln_s("#{EXPORTS_DIR}/#{mod}/#{file}",
82
+ dest_path)
83
+ end
84
+ end
85
+
86
+ def inject(mod, file, dest, comment)
87
+ dest_path = File.expand_path(dest)
88
+ content = File.read("#{MODULES_DIR}/#{mod}/#{file}")
89
+
90
+ bannered = bannerise(content, mod, file, 'inject', comment)
91
+
92
+ # TODO: open dest, look for banner
93
+ # TODO: if none, inject with banner
94
+ # TODO: if found, replace within banner
95
+
96
+ puts "Inject #{file} for #{mod} in #{dest}"
97
+ File.open(dest_path, 'w') do |f|
98
+ f.write(bannered)
99
+ end
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: specks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sébastien Cevey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Small application to manage your dot-files
15
+ email: seb@cine7.net
16
+ executables:
17
+ - specks
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/specks.rb
22
+ - bin/specks
23
+ homepage: http://rubygems.org/gems/specks
24
+ licenses:
25
+ - GPL
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.23
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: dot-files manager
48
+ test_files: []