ds_utils 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a279d4943d45ce36efd8684df84168b8b9a246b4
4
+ data.tar.gz: f5909fd4674c6021e0f22b1cfd4c56ab6efecb5c
5
+ SHA512:
6
+ metadata.gz: 958eab4d2e55b2de4f2108d6e447cfb2a5afc8e038e4a830048994840f123c403edd073089ae353aa3a0ea783b677342a5194937dcd3d1fce226c4e305d792a3
7
+ data.tar.gz: 8493bd71898acdda62a15506bedf5a313887c064a83325a678157f018d348a89e39c37a85498c5cb341fe907b134f6dc1c4a7890635345ff67037e046042d1a0
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # DsUtils
2
+
3
+ Utilities for managing files on Synology DS.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ds_utils'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ds_utils
20
+
21
+ ## Usage
22
+
23
+ require 'ds_utils'
24
+
25
+ # Flatten a directory structure
26
+ DSUtils.flatten '.'
27
+ DSUtils.flatten 'photos/2004'
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ds_utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ds_utils"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
11
+
12
+
data/bin/flatten ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ds_utils'
4
+
5
+ if ARGV[0]
6
+ DsUtils.flatten(ARGV[0])
7
+ else
8
+ DsUtils.flatten('.')
9
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module DsUtils
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ds_utils.rb ADDED
@@ -0,0 +1,85 @@
1
+ require "ds_utils/version"
2
+
3
+ module DsUtils
4
+ # Move tiles from subdirectories of topdir to topdir
5
+ def self.flatten(thisdir,allowed_extensions_arr=[])
6
+ @do_listing = []
7
+ @undo_listing = []
8
+ @move_files = []
9
+
10
+ flatten_recurse(thisdir,allowed_extensions_arr)
11
+
12
+ @subdirectories = @move_files.map{|f| File.dirname(f)}.uniq
13
+
14
+ create_do_file
15
+ create_undo_file
16
+
17
+ puts "Please examine the contents of file #{@do_file} and then execute it with the command:"
18
+ puts " ./#{@do_file}"
19
+ puts "To undo the changes, please execute:"
20
+ puts " ./#{@undo_file}"
21
+
22
+ return [@do_file, @undo_file]
23
+ end
24
+
25
+
26
+ def self.flatten_recurse(thisdir,allowed_extensions_arr=[])
27
+ Dir.foreach(thisdir) do |filename|
28
+ abspath = File.join(thisdir,filename)
29
+ if (!filename.eql?(".") and !filename.eql?("..") and (allowed_extensions_arr.empty? || allowed_extensions_arr.include?(File.extname(filename))))
30
+ # If the listed file is a directory, then flatten it and move contents up to this directory
31
+ if File.directory?(abspath)
32
+ #full_file_path = File.join(File.absolute_path(thisdir),filename)
33
+ self.flatten_recurse(abspath,allowed_extensions_arr)
34
+ #rename_and_move_contents(abspath,File.absolute_path(thisdir),allowed_extensions_arr)
35
+ else
36
+ @move_files << abspath
37
+ end
38
+ else
39
+ puts "skipped: #{abspath}"
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+ def self.create_do_file
46
+ @do_file = "flatten_directory_#{timestamp}.rb"
47
+
48
+ File.open(@do_file, 'w', 0744) {|file|
49
+ file.puts "#!/usr/bin/env ruby"
50
+ @move_files.each {|ll|
51
+ file.puts "File.rename '#{ll}', '#{move_to_name(ll)}'"
52
+ }
53
+ @subdirectories.sort{|a,b| b.count(File::SEPARATOR) - a.count(File::SEPARATOR)}.each {|sd|
54
+ file.puts "Dir.rmdir('#{sd}')"
55
+ }
56
+ }
57
+
58
+ end
59
+
60
+ def self.create_undo_file
61
+ @undo_file = "unflatten_directory_#{timestamp}.rb"
62
+
63
+ File.open(@undo_file, 'w', 0744) {|file|
64
+ file.puts "#!/usr/bin/env ruby"
65
+ file.puts "require 'fileutils'"
66
+ @subdirectories.each {|sd|
67
+ file.puts "FileUtils.mkdir_p '#{sd}' unless Dir.exist?('#{sd}')"
68
+ }
69
+ @move_files.each {|ll|
70
+ file.puts "File.rename '#{move_to_name(ll)}', '#{ll}'"
71
+ }
72
+ }
73
+ end
74
+
75
+ def self.move_to_name(filename)
76
+ split_string_array = filename.split(File::SEPARATOR)
77
+ return split_string_array[0] + File::SEPARATOR + split_string_array[1..-1].join('_')
78
+ end
79
+
80
+ def self.timestamp
81
+ return Time.now.strftime("%Y_%m_%d_%Y%m%dT%H%M%S%z")
82
+ end
83
+
84
+ end
85
+
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ds_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jen Dobson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ description: Tools to help manage files on Synology DS including photo utilities.
84
+ email:
85
+ - jendobson@gmail.com
86
+ executables:
87
+ - flatten
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - bin/console
93
+ - bin/flatten
94
+ - bin/setup
95
+ - lib/ds_utils.rb
96
+ - lib/ds_utils/version.rb
97
+ homepage: ''
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Utilities for Synology DS.
121
+ test_files: []