kiip 0.1.1 → 0.1.2

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: 93e5818f0a0325b3bcf27992b9625999ee7fd84b
4
- data.tar.gz: 680475d12c6fff02f03712998dd18f3737c31d64
3
+ metadata.gz: edaf299795e1246288dbdaa727437701b4735b3f
4
+ data.tar.gz: 5484c36987dcf1bf0e0689ead7363711bc4d7eaf
5
5
  SHA512:
6
- metadata.gz: ff4a62f82c33481ac4b599aff38ca7b820190dad8fd48ee6b09b9f6cf103189a0066973c06d06806767c4d5ad60d02b02f8481dbac92abd8199e7d9a51f73b67
7
- data.tar.gz: 510ff324195741f64c08702b83495fa2af27bd02d584e457b5168975695a331a42a38fb9bef0b7a2b3800c1f2417572304866bc017e058aec314eb3b961f793c
6
+ metadata.gz: 854f64eb1af85ba527dbf117b877785a45f70af60eb621bb6723106a076e65f219d926ce58e2016af5a4ef7a37ef77c1f769c9ce01da4320c38283be75715f4f
7
+ data.tar.gz: af9d9dbb390769891c12aea566ba9250daa91f6b8bd428b3c45545e2445eb3937c6e5f32bbb90b39ae9f1a4f7ac5f03440ea498bbccc86c4ebbe735b6cfb7692
@@ -8,20 +8,27 @@ module Kiip
8
8
  repository.track(package_name, file_or_folder)
9
9
  end
10
10
 
11
- desc 'sync PACKAGE_NAME', 'recreates the source of the package (via symlink, copy, etc)'
12
- def sync package_name
11
+ desc 'link PACKAGE_NAME', 'ensures links to the package files exist'
12
+ def link package_name
13
13
  repository.sync!(package_name)
14
14
  end
15
15
 
16
- desc 'list', 'lists all packages'
16
+ desc 'unlink PACKAGE_NAME', 'removes the links to the package files'
17
+ def unlink package_name
18
+ repository.unlink(package_name)
19
+ end
20
+
21
+ desc 'restore PACKAGE_NAME', 'restores the content of the package to the original places'
22
+ def restore package_name
23
+ repository.restore package_name
24
+ end
25
+
26
+ desc 'list', 'lists all packages with content'
17
27
  def list
18
28
  puts repository.print_content
19
29
  end
20
30
 
21
- option :remove_source, default: false, type: :boolean, desc: 'if the source should be removed, defaults to false'
22
- option :remove_target, default: false, type: :boolean, desc: 'if the source should be removed, defaults to false'
23
- option :replace_source, default: false, type: :boolean, desc: 'if the source should be replaced with the target, defaults to false'
24
- desc 'rm NAME', 'removes package with name NAME, see: kiip help rm'
31
+ desc 'rm NAME', 'removes package with name NAME from the repository'
25
32
  def rm package_name
26
33
  repository.rm package_name
27
34
  end
@@ -23,6 +23,18 @@ module Kiip
23
23
  File.exists? id_file_path
24
24
  end
25
25
 
26
+ def unlink *package_names
27
+ package_names.each do |name|
28
+ get_package(name).unlink
29
+ end
30
+ end
31
+
32
+ def restore *package_names
33
+ package_names.each do |name|
34
+ get_package(name).restore
35
+ end
36
+ end
37
+
26
38
  def sync! *names
27
39
  names = package_names if names.empty?
28
40
  names.each { |name| get_package(name).sync! }
@@ -40,7 +52,24 @@ module Kiip
40
52
  StringIO.open do |result|
41
53
  packages.each do |package|
42
54
  result.puts package.name + ':'
43
- package.decoded_content.each { |content| result.puts ' ' + content }
55
+ package.content.each do |content|
56
+ decoded_path_original = Kiip::Repository::Package.decode(content)
57
+ decoded_path_expanded = File.expand_path decoded_path_original
58
+
59
+ if File.symlink?(decoded_path_expanded)
60
+ status = File.readlink(decoded_path_expanded) == File.join(package.path, content) ? 'linked' : 'symlink'
61
+ elsif File.directory?(decoded_path_expanded)
62
+ status = 'directory'
63
+ elsif File.file? decoded_path_expanded
64
+ status = 'file'
65
+ elsif not File.exist? decoded_path_expanded
66
+ status = 'not existant'
67
+ else
68
+ raise 'unknown status'
69
+ end
70
+
71
+ result.puts " #{decoded_path_original} | #{status}"
72
+ end
44
73
  end
45
74
 
46
75
  result.string
@@ -17,6 +17,24 @@ module Kiip
17
17
  property :name, required: true, coerce: String
18
18
  property :repository, required: true
19
19
 
20
+ def restore
21
+ unlink
22
+ content.each do |encoded_orginal_path|
23
+ decoded_original_path = self.class.decode encoded_orginal_path
24
+ FileUtils.cp_r(File.join(path, encoded_orginal_path), decoded_original_path,
25
+ verbose: repository.is_verbose, noop: repository.is_dry)
26
+ end
27
+ end
28
+
29
+ # removes the links to the package content
30
+ def unlink
31
+ content.each do |encoded_orginal_path|
32
+ decoded_original_path = self.class.decode encoded_orginal_path
33
+ if File.symlink?(decoded_original_path) and File.readlink(decoded_original_path) == File.join(path, encoded_orginal_path)
34
+ FileUtils.rm decoded_original_path
35
+ end
36
+ end
37
+ end
20
38
 
21
39
  def track(tracking_path)
22
40
  raise "path does not exist: #{tracking_path}" unless File.exists?(File.expand_path tracking_path)
@@ -50,11 +68,7 @@ module Kiip
50
68
  end
51
69
 
52
70
  def rm
53
- content.each do |subpath|
54
- source = self.class.decode subpath
55
- task = Tasks::SymlinkTask.new(name: 'task-name', source: source, target: File.join(path, subpath))
56
- task.restore
57
- end
71
+ FileUtils.rm_r(path, verbose: repository.is_verbose, noop: repository.is_dry)
58
72
  end
59
73
 
60
74
  # @return [boolean]
@@ -66,7 +80,6 @@ module Kiip
66
80
  File.join(repository.path, name)
67
81
  end
68
82
 
69
- private
70
83
  # @return [String[]] array of package content files/folders
71
84
  def content
72
85
  Pathname.new(path).children.map(&:basename).map(&:to_s)
@@ -21,6 +21,7 @@ module Kiip::Tasks
21
21
  # actually execute the task
22
22
  def exec!
23
23
  return initialize! unless File.exists? target
24
+
24
25
  if File.symlink? source
25
26
  return if File.readlink(source) == target
26
27
 
@@ -38,19 +39,15 @@ module Kiip::Tasks
38
39
  end
39
40
  end
40
41
 
41
- def restore
42
- remove_source
43
- copy_target_to_source
44
- end
45
-
46
42
  private
43
+
47
44
  def cli
48
45
  HighLine.new
49
46
  end
50
47
 
51
48
  def initialize!
52
49
  raise "source must exist to initalize: #{source}" unless File.exists? source
53
- raise "source must not be a symlink: #{source}" if File.symlink? source
50
+ return if File.symlink?(source) and not cli.agree("source is a symlink: #{source}. Continue?")
54
51
 
55
52
  move_source_to_target
56
53
  create_symlink_from_source_to_target
@@ -61,10 +58,7 @@ module Kiip::Tasks
61
58
  end
62
59
 
63
60
  def remove_source
64
- # only force on real directories
65
- do_force = !File.symlink?(source) and File.directory?(source)
66
-
67
- FileUtils.rm(source, verbose: is_verbose, noop: is_dry, force: do_force)
61
+ FileUtils.rm_r(source, verbose: is_verbose, noop: is_dry)
68
62
  end
69
63
 
70
64
  def move_source_to_target
@@ -1,3 +1,3 @@
1
1
  module Kiip
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Wenglewski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-23 00:00:00.000000000 Z
11
+ date: 2016-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  version: '0'
214
214
  requirements: []
215
215
  rubyforge_project:
216
- rubygems_version: 2.4.6
216
+ rubygems_version: 2.4.8
217
217
  signing_key:
218
218
  specification_version: 4
219
219
  summary: just another dotfiles tool