organisir 0.1.0 → 0.1.2
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 +4 -4
- data/.gitignore +2 -1
- data/Gemfile.lock +1 -11
- data/README.md +55 -13
- data/lib/organisir/cli.rb +2 -21
- data/lib/organisir/client.rb +6 -4
- data/lib/organisir/file_op.rb +9 -6
- data/lib/organisir/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b5a8a59f69fe29c8aad7552739f29e6ad21605ea00a0eee59978a489cf4b46f
|
|
4
|
+
data.tar.gz: 55ad2e84a64eb396d6b2838528da475822c36f0fc7b4f01372d48394cffd6e51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f266331405326ed542974a62fb3ac7a6d6a4b2397351f55a265df52bff5ddb5a2675ce0e16d36266ac10bb71d8fafcad1c5e75a516f3d84761e0830e44a534b
|
|
7
|
+
data.tar.gz: f1c19c78a5d7ff7ca4d54f17a6ddbab0aa9b619109937203564ddd7abfaf120ae2b301f78ce8f37d40f89fd56f837ce5e6915d520d9726dea9cbc9db7620a449
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
organisir (0.1.
|
|
4
|
+
organisir (0.1.2)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
ast (2.4.1)
|
|
10
|
-
coderay (1.1.3)
|
|
11
10
|
colorize (0.8.1)
|
|
12
|
-
method_source (1.0.0)
|
|
13
|
-
minitest (5.14.2)
|
|
14
|
-
optparse (0.1.0)
|
|
15
11
|
parallel (1.20.1)
|
|
16
12
|
parser (2.7.2.0)
|
|
17
13
|
ast (~> 2.4.1)
|
|
18
|
-
pry (0.13.1)
|
|
19
|
-
coderay (~> 1.1)
|
|
20
|
-
method_source (~> 1.0)
|
|
21
14
|
rainbow (3.0.0)
|
|
22
15
|
rake (13.0.1)
|
|
23
16
|
regexp_parser (2.0.0)
|
|
@@ -42,10 +35,7 @@ PLATFORMS
|
|
|
42
35
|
|
|
43
36
|
DEPENDENCIES
|
|
44
37
|
colorize (~> 0.8.1)
|
|
45
|
-
minitest (~> 5.0)
|
|
46
|
-
optparse (~> 0.1.0)
|
|
47
38
|
organisir!
|
|
48
|
-
pry (~> 0.13.1)
|
|
49
39
|
rake (~> 13.0)
|
|
50
40
|
rubocop (~> 0.80)
|
|
51
41
|
thor (~> 1.0)
|
data/README.md
CHANGED
|
@@ -1,32 +1,69 @@
|
|
|
1
1
|
# Organisir
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
3
|
+
A Ruby gem made to organise large number of files effectively using a simple set of predfined rules and checks based on filenames. Currently the rules are hardcoded based on my personal preferences although I am planning to implement a custom rule injection to allow others with working knowledge of ruby to write their own rules for file management.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
Run this command to install organisir
|
|
10
8
|
|
|
11
|
-
```
|
|
12
|
-
gem
|
|
9
|
+
```{shell}
|
|
10
|
+
gem install organisir
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## Usage
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
In its current state, organisir supports two types of file organisation.
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
### 1. Moving files inside a source directory(S) to a destination directory(D)
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
Suppose your directory S has a lot of files and your D directory has multiple sub-directories with names d1, d2,...,dn. Each file inside S contains the word(s) d1..dn inside them. Organisir can scan each of these files in S and move them inside the subdirectories inside D. If a filename contains multiple combinations of d1..dn, the first match is selected for moving the file.
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
#### Example
|
|
22
|
+
|
|
23
|
+
Source directory is `~/Images`
|
|
24
|
+
Destination directory is `~/Images/Organised`
|
|
25
|
+
|
|
26
|
+
Your files inside `Images` directory contains the year in their file names eg. `IMG_01_JAN_2018.jpg` and your destination directory has multiple directories with year name eg. `~/Images/Organised/2017, ~/Images/Organised/2018, ~/Images/Organised/2019` and so on.
|
|
27
|
+
|
|
28
|
+
To move all files inside the `Images` directory to the sub-directories inside `Images/Organised` directory, you can invoke the following command.
|
|
29
|
+
|
|
30
|
+
```{shell}
|
|
31
|
+
cd ~
|
|
32
|
+
organisir start --source Images --destination Images/Organised
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
By default, organisir never modifies any files unless specified explicitly. Running the command will give you a full result of the files which matched the rule and the chosen directory for moving. You can review the output and if it looks good, pass an additional `--commit true` flag to the earlier command.
|
|
36
|
+
|
|
37
|
+
```{shell}
|
|
38
|
+
cd ~
|
|
39
|
+
organisir start --source Images --destination Images/Organised --commit true
|
|
40
|
+
```
|
|
24
41
|
|
|
25
|
-
|
|
42
|
+
### 2. Creating references to a file in multiple directories inside a parent directory(P)
|
|
43
|
+
|
|
44
|
+
This command is useful if you have files inside directory which may also required to be present in other directories based on their filenames. It usually extends on the first scenario.
|
|
45
|
+
|
|
46
|
+
#### Example
|
|
47
|
+
|
|
48
|
+
Parent directory is `~/Images/Organised`
|
|
49
|
+
|
|
50
|
+
Your parent directory may contain multiple sub-directories with some names `d1,d2,..,dn` etc. If you have files in any of these sub-directory which may fulfill the filename rule matching criteria, the symlink command can create symlinks of the original files inside each sub-directory which matches the filename rule match.
|
|
51
|
+
|
|
52
|
+
```{shell}
|
|
53
|
+
cd ~
|
|
54
|
+
organisir symlink --source Images/Organised
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Again by default, organisir never modifies any files unless specified explicitly. Running the command will give you a full list of matches found. You can review the output and if it looks good, pass an additional `--commit true` flag to the earlier command.
|
|
58
|
+
|
|
59
|
+
```{shell}
|
|
60
|
+
cd ~
|
|
61
|
+
organisir symlink --source Images/Organised --commit true
|
|
62
|
+
```
|
|
26
63
|
|
|
27
64
|
## Development
|
|
28
65
|
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
30
67
|
|
|
31
68
|
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
69
|
|
|
@@ -34,3 +71,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
34
71
|
|
|
35
72
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/organisir.
|
|
36
73
|
|
|
74
|
+
## TODO
|
|
75
|
+
|
|
76
|
+
- [ ] Provide support for users to write their own ruby code to allow custom matching rules.
|
|
77
|
+
|
|
78
|
+
- [ ] Allow symlink command to work with a source and destination directory rather than a single source diirectory.
|
data/lib/organisir/cli.rb
CHANGED
|
@@ -8,25 +8,6 @@ module Organisir
|
|
|
8
8
|
true
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
COMMANDS = {
|
|
12
|
-
start: %w[
|
|
13
|
-
Move files from a source directory to a destination directory based on the filename of all files inside
|
|
14
|
-
the source directory. Only files present in the source directory will be scanned and moved. The destination
|
|
15
|
-
directory should ideally contain multiple directories where you would want your files to move.
|
|
16
|
-
].join(" "),
|
|
17
|
-
organise: "Alias of start",
|
|
18
|
-
symlink: %w[
|
|
19
|
-
Scan all directories inside a directory and the files contained in each of them (upto one level). Each file
|
|
20
|
-
which matches multiple rules will have a symlink created in each directory where the rule was matched. The
|
|
21
|
-
original file will not be moved and new symlinks will refer to the original file path.
|
|
22
|
-
].join(" "),
|
|
23
|
-
clean: %w[
|
|
24
|
-
Remove all dangling symlinks from a directory by scanning through all the directories inside the given
|
|
25
|
-
source directory
|
|
26
|
-
].join(" "),
|
|
27
|
-
version: "Display installed tmuxinator version"
|
|
28
|
-
}.freeze
|
|
29
|
-
|
|
30
11
|
desc "start source destination", "Move files from source to destination directory"
|
|
31
12
|
option :source, aliases: :s, required: true, type: :string
|
|
32
13
|
option :destination, aliases: :d, required: true, type: :string
|
|
@@ -35,7 +16,7 @@ module Organisir
|
|
|
35
16
|
def start
|
|
36
17
|
if options[:commit]
|
|
37
18
|
say "Preparing to move files in 5 seconds. Cancel the command by pressing Ctrl-C"
|
|
38
|
-
|
|
19
|
+
sleep(5)
|
|
39
20
|
else
|
|
40
21
|
say "Start command always runs in non-commit mode. Use --commit true to permanently move files.", :red
|
|
41
22
|
end
|
|
@@ -45,7 +26,7 @@ module Organisir
|
|
|
45
26
|
say "Exiting organisir...", :green
|
|
46
27
|
end
|
|
47
28
|
|
|
48
|
-
desc "
|
|
29
|
+
desc "symlink", "Symlink files in nested directories to matching sub-directories within the given directory"
|
|
49
30
|
option :source, aliases: :s, required: true, type: :string
|
|
50
31
|
option :commit, type: :boolean, default: false
|
|
51
32
|
def symlink
|
data/lib/organisir/client.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Organisir
|
|
|
9
9
|
|
|
10
10
|
@verbose = !commit
|
|
11
11
|
@pwd = pwd
|
|
12
|
-
@file_op = FileOp.new(
|
|
12
|
+
@file_op = FileOp.new(pwd, source_dir)
|
|
13
13
|
execute_start
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ module Organisir
|
|
|
17
17
|
@abs_source_dir = File.join(pwd, source_dir)
|
|
18
18
|
@verbose = !commit
|
|
19
19
|
@pwd = pwd
|
|
20
|
-
@file_op = FileOp.new(
|
|
20
|
+
@file_op = FileOp.new(pwd, source_dir)
|
|
21
21
|
|
|
22
22
|
execute_symlink
|
|
23
23
|
end
|
|
@@ -38,6 +38,7 @@ module Organisir
|
|
|
38
38
|
|
|
39
39
|
move_file(f, match_dir)
|
|
40
40
|
end
|
|
41
|
+
print "Process completed\n"
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def execute_symlink
|
|
@@ -53,17 +54,18 @@ module Organisir
|
|
|
53
54
|
|
|
54
55
|
symlink_file(f, match_dirs)
|
|
55
56
|
end
|
|
57
|
+
print "Process completed\n"
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def move_file(filename, dirname)
|
|
59
|
-
print "Rule matched file #{filename.to_s.colorize(:red)} to
|
|
61
|
+
print "Rule matched file #{filename.to_s.colorize(:red)} moved to directory #{dirname.to_s.colorize(:red)}\n"
|
|
60
62
|
return if @verbose
|
|
61
63
|
|
|
62
64
|
@file_op.move(filename, @abs_source_dir, File.join(@abs_dest_dir, dirname))
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def symlink_file(file, match_dirs)
|
|
66
|
-
print "Rule matched file #{file.to_s.colorize(:red)}
|
|
68
|
+
print "Rule matched file #{file.to_s.colorize(:red)} symlinked to directories #{match_dirs.join(", ").to_s.colorize(:red)}\n"
|
|
67
69
|
return if @verbose
|
|
68
70
|
|
|
69
71
|
@file_op.symlink(file, match_dirs)
|
data/lib/organisir/file_op.rb
CHANGED
|
@@ -4,25 +4,28 @@ require "fileutils"
|
|
|
4
4
|
|
|
5
5
|
module Organisir
|
|
6
6
|
class FileOp
|
|
7
|
-
def initialize(root_dir)
|
|
7
|
+
def initialize(root_dir, source_dir)
|
|
8
8
|
@root_dir = root_dir
|
|
9
|
+
@source_dir = source_dir
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def move(filename, source_path, destination_path)
|
|
12
13
|
src = File.join(source_path, filename)
|
|
13
14
|
dest = File.join(destination_path, filename)
|
|
14
|
-
# print "mv#{false ? ' -f' : ''} #{[src,dest].flatten.join ' '}\n".colorize(:green)
|
|
15
15
|
FileUtils.move(src, dest, force: false, verbose: false)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def symlink(src_file, destination_dirs)
|
|
19
|
-
filename =
|
|
19
|
+
filename = File.basename(src_file)
|
|
20
20
|
destns = destination_dirs.map do |p|
|
|
21
|
-
File.join(@root_dir, p, filename)
|
|
21
|
+
File.join(@root_dir, @source_dir, p, filename)
|
|
22
22
|
end
|
|
23
|
-
|
|
24
23
|
destns.each do |d|
|
|
25
|
-
|
|
24
|
+
begin
|
|
25
|
+
FileUtils.ln_s(src_file,d , force: false, verbose: false)
|
|
26
|
+
rescue Errno::EEXIST
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
end
|
|
28
31
|
|
data/lib/organisir/version.rb
CHANGED