lace 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2EwOWNjNGJiNTg5NWE0YTM0NGVmZjcyMGJlZGEwNzkyZmRlZWU3YQ==
4
+ YTE1YjU3OTUwMmFjYzNkOTYwZWFjODA1ZjUyZDU5NWY3YzYwMDA2ZQ==
5
5
  data.tar.gz: !binary |-
6
- NzM4NzhkMWU0NTRhZjljYjVjZTA1OWFlMjA1MmQyMWViYjg1NmQ1Ng==
6
+ OGYxN2E5M2ZhY2VjZDQzMWJmY2I3MWFmYWM1YzRiMDA0ODRmOGRmNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzQ3ZjA0OWU5OTU2YWVmOTAzMDAxYjQ5MDU3NWI4MDFkMDNkMDZjMzMxZDVm
10
- NjVmODEwMjcyYzcxZTk2MDAyMWE5NDI2MTlhMWEyMjAyYTc5NWM4NmQxMmFk
11
- OThkODU1NzM5MWRhNDk0NmRkMjM1NDNiNTIxYjJlZjc3MTk4MmU=
9
+ MjEzNDY5ZmQxNzE5ODJlMmNiZjM2YmRkZjkxOWY1MWY5MzE1YmRmYzZlZDIx
10
+ ODRiY2EwMjYwMDEzYjJiZDEzM2JlZTVlMjllNjNhODlmZWJiNTZiZmZlNzYy
11
+ ZDc0MjVjYmZhMTNjNGM4ODYwMTMxNWJiMGZiNzhkMTUxNzI1N2M=
12
12
  data.tar.gz: !binary |-
13
- ZjI3N2ZkMTczNDdkMWZkY2U1ZDgwMzYzYTZkMGY5NTRlMzY0ZTVhZDM5ZWJi
14
- MjdjY2RjYjY4NDAxMjBjODkzMmM1NjkzNGM1M2Y1ZGFjNDMxNTIyOWQ4ZDAx
15
- MmYxMTQ3ZTU1M2ZmN2ZhMzY2MDA1NjUwN2QxMTRhYmY0Y2RiMDM=
13
+ Y2RkNzExZWJiNzQ2NjJmNzNmNTg5NjZmZjA1OTlhM2Y2MWU3ZjE4NjJiYWU5
14
+ NWUwOTJhMzYxYWRjMTIxODg4ZTUyN2I3MWE2MjY5YWRlNzZlOWUzN2QwNWI0
15
+ NWQyM2QwNWZkZTgzYTcyZjE3NmQwNDJhOWU4M2U5NGRmNjM1ZTY=
data/bin/lace CHANGED
@@ -61,6 +61,7 @@ begin
61
61
  end
62
62
 
63
63
  aliases = {'ls' => 'list',
64
+ 'info' => 'inspect',
64
65
  'rm' => 'remove'}
65
66
 
66
67
  cmd = ARGV.shift
data/lib/cmd/fetch.rb CHANGED
@@ -5,6 +5,14 @@ module Lace extend self
5
5
  def fetch
6
6
  resource = ARGV.shift
7
7
  raise ResourceNotSpecified if not resource
8
- PackageUtils.fetch resource
8
+ package_name, target_folder = PackageUtils.fetch resource
9
+ begin
10
+ Package.new package_name, false
11
+ rescue PackageFactsNotFound => e
12
+ onoe e.message
13
+ onoe "Removing fetched files"
14
+ FileUtils.rm_rf target_folder
15
+ Lace.failed = true
16
+ end
9
17
  end
10
18
  end
data/lib/cmd/help.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  HELP = <<-EOS
2
2
  Example usage:
3
3
  Synopsis:
4
- lace <cmd> <pkg-uri/name> [<flavor>] [--name=<name>] [--version] [--no-hooks]
4
+ lace <cmd> <pkg-uri/name> [<flavor>] [--name=<name>] [--version] [--no-hooks] [--force]
5
5
 
6
6
  lace ls
7
7
 
8
8
  lace fetch <pkg-uri>
9
9
  lace fetch <pkg-uri>
10
10
 
11
- lace install <pkg-uri>
12
- lace install <pkg-uri> <flavor>
11
+ lace setup <pkg-uri>
12
+ lace setup <pkg-uri> <flavor>
13
13
 
14
14
  lace activate <pkg-name>
15
15
  lace activate <pkg-name> <flavor>
data/lib/cmd/list.rb CHANGED
@@ -26,7 +26,7 @@ module Lace extend self
26
26
  if installed_packages.length > 0
27
27
  installed_packages.map do |d|
28
28
  package = Package.new d, false
29
- puts "- [#{Tty.green}#{package.is_active? ? "*" : " "}#{Tty.reset}] #{d}"
29
+ puts "[#{Tty.green}#{package.is_active? ? "*" : " "}#{Tty.reset}] #{d}"
30
30
  end
31
31
  else
32
32
  puts "There are no pkgs installed"
data/lib/cmd/setup.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'lace/package'
2
+ require 'lace/exceptions'
3
+
4
+ module Lace extend self
5
+ def setup
6
+ package_name = ARGV.shift
7
+ PackageUtils.setup package_name
8
+ end
9
+ end
data/lib/cmd/validate.rb CHANGED
@@ -40,7 +40,7 @@ class PackageValidator
40
40
  validate 'config-files', :config_files_present
41
41
  validate 'version', :version_present
42
42
  validate 'homepage', :homepage_present
43
- validate 'post-install hook', :post_install_hooks_ok
43
+ validate 'setup', :setup_ok
44
44
  validate 'post-update hook', :post_update_hooks_ok
45
45
 
46
46
  def initialize facts, flavor=nil
@@ -64,8 +64,8 @@ class PackageValidator
64
64
  end.compact
65
65
  end
66
66
 
67
- def hook_ok hook
68
- hook_cmd = @facts.post(hook)
67
+ def hook_ok config_files
68
+ hook_cmd = config_files
69
69
  if hook_cmd.empty?
70
70
  ["#{Tty.green}skipped#{Tty.reset}", nil]
71
71
  else
@@ -78,12 +78,12 @@ class PackageValidator
78
78
  end
79
79
  end
80
80
 
81
- def post_install_hooks_ok
82
- hook_ok :install
81
+ def setup_ok
82
+ hook_ok @facts.setup_files
83
83
  end
84
84
 
85
85
  def post_update_hooks_ok
86
- hook_ok :update
86
+ hook_ok @facts.post :update
87
87
  end
88
88
 
89
89
  def homepage_present
data/lib/extend/ARGV.rb CHANGED
@@ -33,6 +33,10 @@ module LaceArgvExtension
33
33
  flag? '--no-hooks'
34
34
  end
35
35
 
36
+ def force?
37
+ flag? '--force'
38
+ end
39
+
36
40
  def interactive?
37
41
  flag? '--interactive'
38
42
  end
@@ -12,16 +12,6 @@ class Pathname
12
12
  return dst
13
13
  end
14
14
 
15
- # extended to support common double extensions
16
- alias extname_old extname
17
- def extname(path=to_s)
18
- BOTTLE_EXTNAME_RX.match(path)
19
- return $1 if $1
20
- /(\.(tar|cpio|pax)\.(gz|bz2|xz|Z))$/.match(path)
21
- return $1 if $1
22
- return File.extname(path)
23
- end
24
-
25
15
  # for filetypes we support, basename without extension
26
16
  def stem
27
17
  File.basename((path = to_s), extname(path))
@@ -49,68 +39,6 @@ class Pathname
49
39
  FileUtils.chmod_R perms, to_s
50
40
  end
51
41
 
52
- def abv
53
- out=''
54
- n=`find #{to_s} -type f ! -name .DS_Store | wc -l`.to_i
55
- out<<"#{n} files, " if n > 1
56
- out<<`/usr/bin/du -hs #{to_s} | cut -d"\t" -f1`.strip
57
- end
58
-
59
- def compression_type
60
- # Don't treat jars or wars as compressed
61
- return nil if self.extname == '.jar'
62
- return nil if self.extname == '.war'
63
-
64
- # OS X installer package
65
- return :pkg if self.extname == '.pkg'
66
-
67
- # If the filename ends with .gz not preceded by .tar
68
- # then we want to gunzip but not tar
69
- return :gzip_only if self.extname == '.gz'
70
-
71
- # Get enough of the file to detect common file types
72
- # POSIX tar magic has a 257 byte offset
73
- # magic numbers stolen from /usr/share/file/magic/
74
- case open('rb') { |f| f.read(262) }
75
- when /^PK\003\004/n then :zip
76
- when /^\037\213/n then :gzip
77
- when /^BZh/n then :bzip2
78
- when /^\037\235/n then :compress
79
- when /^.{257}ustar/n then :tar
80
- when /^\xFD7zXZ\x00/n then :xz
81
- when /^Rar!/n then :rar
82
- when /^7z\xBC\xAF\x27\x1C/n then :p7zip
83
- else
84
- # This code so that bad-tarballs and zips produce good error messages
85
- # when they don't unarchive properly.
86
- case extname
87
- when ".tar.gz", ".tgz", ".tar.bz2", ".tbz" then :tar
88
- when ".zip" then :zip
89
- end
90
- end
91
- end
92
-
93
- def text_executable?
94
- %r[^#!\s*\S+] === open('r') { |f| f.read(1024) }
95
- end
96
-
97
- def incremental_hash(hasher)
98
- incr_hash = hasher.new
99
- buf = ""
100
- open('rb') { |f| incr_hash << buf while f.read(1024, buf) }
101
- incr_hash.hexdigest
102
- end
103
-
104
- def sha1
105
- require 'digest/sha1'
106
- incremental_hash(Digest::SHA1)
107
- end
108
-
109
- def sha256
110
- require 'digest/sha2'
111
- incremental_hash(Digest::SHA2)
112
- end
113
-
114
42
  if '1.9' <= RUBY_VERSION
115
43
  alias_method :to_str, :to_s
116
44
  end
@@ -140,59 +68,8 @@ class Pathname
140
68
  join that.to_s
141
69
  end
142
70
 
143
- def ensure_writable
144
- saved_perms = nil
145
- unless writable_real?
146
- saved_perms = stat.mode
147
- chmod 0644
148
- end
149
- yield
150
- ensure
151
- chmod saved_perms if saved_perms
152
- end
153
-
154
- # Writes an exec script in this folder for each target pathname
155
- def write_exec_script *targets
156
- targets.flatten!
157
- if targets.empty?
158
- opoo "tried to write exec scripts to #{self} for an empty list of targets"
159
- end
160
- targets.each do |target|
161
- target = Pathname.new(target) # allow pathnames or strings
162
- (self+target.basename()).write <<-EOS.undent
163
- #!/bin/bash
164
- exec "#{target}" "$@"
165
- EOS
166
- end
71
+ def as_dotfile base_folder
72
+ Pathname.new File.join(base_folder, ".#{basename}")
167
73
  end
168
74
 
169
- # We redefine these private methods in order to add the /o modifier to
170
- # the Regexp literals, which forces string interpolation to happen only
171
- # once instead of each time the method is called. This is fixed in 1.9+.
172
- if RUBY_VERSION <= "1.8.7"
173
- alias_method :old_chop_basename, :chop_basename
174
- def chop_basename(path)
175
- base = File.basename(path)
176
- if /\A#{Pathname::SEPARATOR_PAT}?\z/o =~ base
177
- return nil
178
- else
179
- return path[0, path.rindex(base)], base
180
- end
181
- end
182
- private :chop_basename
183
-
184
- alias_method :old_prepend_prefix, :prepend_prefix
185
- def prepend_prefix(prefix, relpath)
186
- if relpath.empty?
187
- File.dirname(prefix)
188
- elsif /#{SEPARATOR_PAT}/o =~ prefix
189
- prefix = File.dirname(prefix)
190
- prefix = File.join(prefix, "") if File.basename(prefix + 'a') != 'a'
191
- prefix + relpath
192
- else
193
- prefix + relpath
194
- end
195
- end
196
- private :prepend_prefix
197
- end
198
75
  end
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  class NonActiveFlavorError < RuntimeError
18
18
  def initialize
19
- super "It looks like the flavor you tried to deactivate is not active after all"
19
+ super "Cannot deactivate package that is not active"
20
20
  end
21
21
  end
22
22
 
data/lib/lace/package.rb CHANGED
@@ -16,14 +16,8 @@ class PackageUtils
16
16
  downloader = DownloadStrategyDetector.detect(uri).new(uri)
17
17
  raise PackageAlreadyInstalled.new if downloader.target_folder.exist?
18
18
  downloader.fetch
19
- begin
20
- package = Package.new downloader.name, false
21
- rescue PackageFactsNotFound => e
22
- onoe e.message
23
- onoe "Removing fetched files"
24
- FileUtils.rm_rf downloader.target_folder
25
- end
26
- end
19
+ return downloader.name, downloader.target_folder
20
+ end
27
21
 
28
22
  def self.remove package_name
29
23
  package = Package.new package_name, false
@@ -32,13 +26,11 @@ class PackageUtils
32
26
  FileUtils.rm_rf package.path
33
27
  end
34
28
 
35
- def self.install uri
36
- downloader = DownloadStrategyDetector.detect(uri).new(uri)
37
- self.fetch uri
29
+ def self.setup package_name
38
30
  begin
39
- package = Package.new downloader.name, ARGV.first
31
+ package = Package.new package_name, ARGV.first
40
32
  package.activate!
41
- package.after_install
33
+ package.setup
42
34
  rescue FlavorError => e
43
35
  onoe e.message
44
36
  onoe "Package remains installed but was not activated"
@@ -47,7 +39,7 @@ class PackageUtils
47
39
 
48
40
  def self.deactivate package_name
49
41
  package = Package.new package_name, ARGV.first
50
- raise NonActiveFlavorError.new unless package.is_active?
42
+ raise NonActiveFlavorError.new unless package.is_active? || ARGV.force?
51
43
  ohai "Deactivating"
52
44
  package.deactivate!
53
45
  end
@@ -104,6 +96,10 @@ class Facts
104
96
  @_facts["version"] if @_facts.key? "version"
105
97
  end
106
98
 
99
+ def setup_files
100
+ @facts["setup"].flatten rescue []
101
+ end
102
+
107
103
  def homepage
108
104
  @_facts["homepage"] if @_facts.key? "homepage"
109
105
  end
@@ -149,11 +145,10 @@ class Package
149
145
  include GitCommands
150
146
  attr_reader :name, :facts, :path
151
147
 
152
- def after_install
148
+ def setup
153
149
  return if ARGV.nohooks?
154
150
  @path.cd do
155
- ENV["CURRENT_DOTTY"] = @path
156
- facts.post(:install).each do |cmd|
151
+ facts.setup_files.each do |cmd|
157
152
  safe_system cmd
158
153
  end
159
154
  end
@@ -162,7 +157,6 @@ class Package
162
157
  def after_update
163
158
  return if ARGV.nohooks?
164
159
  @path.cd do
165
- ENV["CURRENT_DOTTY"] = @path
166
160
  facts.post(:update).each do |cmd|
167
161
  system cmd
168
162
  end
@@ -207,8 +201,9 @@ class Package
207
201
  files = @facts.config_files
208
202
  home_dir = ENV["HOME"]
209
203
  files.each do |file|
210
- pn = Pathname.new file
211
- FileUtils.rm_f File.join(home_dir, "." + pn.basename)
204
+ file = Pathname.new(file)
205
+ dotfile = file.as_dotfile(home_dir)
206
+ FileUtils.rm_f dotfile if dotfile.exist? && dotfile.readlink == file
212
207
  end
213
208
  end
214
209
 
@@ -217,8 +212,7 @@ class Package
217
212
  home_dir = ENV["HOME"]
218
213
  files.each do |file|
219
214
  # if ends in erb -> generate it
220
- pn = Pathname.new file
221
- FileUtils.ln_s file, File.join(home_dir, "." + pn.basename)
215
+ FileUtils.ln_s file, Pathname.new(file).as_dotfile(home_dir), force: ARGV.force?
222
216
  end
223
217
  end
224
218
  end
data/lib/lace/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lace
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Richard Koenig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-09 00:00:00.000000000 Z
11
+ date: 2014-01-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is a simple/unfinished tool which i use to manage my dotfiles on
14
14
  all the different machines
@@ -24,9 +24,9 @@ files:
24
24
  - lib/cmd/fetch.rb
25
25
  - lib/cmd/help.rb
26
26
  - lib/cmd/inspect.rb
27
- - lib/cmd/install.rb
28
27
  - lib/cmd/list.rb
29
28
  - lib/cmd/remove.rb
29
+ - lib/cmd/setup.rb
30
30
  - lib/cmd/update.rb
31
31
  - lib/cmd/validate.rb
32
32
  - lib/extend/ARGV.rb
data/lib/cmd/install.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'lace/package'
2
- require 'lace/exceptions'
3
-
4
- module Lace extend self
5
- def install
6
- resource = ARGV.shift
7
- raise ResourceNotSpecified if not resource
8
- PackageUtils.install resource
9
- end
10
- end