taggata 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/taggata/cli.rb +22 -89
- data/lib/taggata/cli/cleanup.rb +25 -0
- data/lib/taggata/cli/list.rb +23 -0
- data/lib/taggata/cli/main.rb +8 -0
- data/lib/taggata/cli/remove.rb +17 -0
- data/lib/taggata/cli/scan.rb +15 -0
- data/lib/taggata/cli/search.rb +25 -0
- data/lib/taggata/cli/tag.rb +21 -0
- data/lib/taggata/db.rb +4 -0
- data/lib/taggata/db_adapters/abstract.rb +4 -0
- data/lib/taggata/db_adapters/sequel.rb +7 -0
- data/lib/taggata/persistent/file.rb +1 -1
- data/lib/taggata/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e853c0f197780d48d8bcda7ffb436a893b1aeac1
|
4
|
+
data.tar.gz: 78aeedd7b18c30966e0cf107b4959456952b4556
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a4de1718710bfeb5dc3515132499a46f4ac7dd817b575b32ef35f5e2b49a45bca2712ba8a238e0bd7f18862b8f0dde18e02e87c42d945c77d5420795ef9a5d
|
7
|
+
data.tar.gz: 00acf36ba798372a80b61a94358cd1a51151e4e165dbf5014fdc9e62483a2ff7ddef299c186db54bd90b8f63084a3727a0f070186986bcb89ca9b93c4415e167
|
data/lib/taggata/cli.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
require 'clamp'
|
2
|
-
require 'taggata'
|
3
|
-
|
4
1
|
module Taggata
|
5
2
|
module Cli
|
3
|
+
|
4
|
+
require 'clamp'
|
5
|
+
require 'taggata'
|
6
|
+
require 'taggata/cli/scan'
|
7
|
+
require 'taggata/cli/tag'
|
8
|
+
require 'taggata/cli/search'
|
9
|
+
require 'taggata/cli/remove'
|
10
|
+
require 'taggata/cli/list'
|
11
|
+
require 'taggata/cli/cleanup'
|
12
|
+
|
6
13
|
Clamp do
|
7
14
|
|
8
15
|
option "--db-path", "DB_PATH", "path to the DB", :attribute_name => :db, :required => true do |db_path|
|
@@ -11,92 +18,18 @@ module Taggata
|
|
11
18
|
option ['-v', '--verbose'], :flag, 'be verbose', :default => false
|
12
19
|
option ['-q', '--quiet'], :flag, 'be quite', :default => false
|
13
20
|
|
14
|
-
subcommand
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
subcommand 'tag', 'tag a file matching query' do
|
27
|
-
|
28
|
-
parameter 'TAG_QUERY', 'the tag query', :attribute_name => :tag_query, :required => true
|
29
|
-
parameter 'SEARCH_QUERY', 'the query to search', :attribute_name => :search_query, :required => true
|
30
|
-
|
31
|
-
def execute
|
32
|
-
tags = ::Taggata::Parser::Tag.new(db).parse(tag_query)
|
33
|
-
files = ::Taggata::Parser::Query.new(db).parse(search_query)
|
34
|
-
db.transaction do
|
35
|
-
files.each do |file|
|
36
|
-
file.add_tags *tags[:add]
|
37
|
-
file.remove_tags *tags[:del]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
subcommand 'search', "search the database" do
|
45
|
-
|
46
|
-
option "-c", :flag, 'show only matched count', :attribute_name => :count, :default => false
|
47
|
-
option "-n", :flag, 'show only names without paths', :attribute_name => :names, :default => false
|
48
|
-
parameter "QUERY", 'the query to perform', :attribute_name => :query, :required => true
|
49
|
-
|
50
|
-
def execute
|
51
|
-
results = ::Taggata::Parser::Query.new(db).parse(query)
|
52
|
-
if count?
|
53
|
-
puts results.count
|
54
|
-
else
|
55
|
-
if results.empty?
|
56
|
-
puts "No results matching the query."
|
57
|
-
else
|
58
|
-
method = names? ? :name : :path
|
59
|
-
results.each { |file| puts file.send(method) }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
subcommand 'remove', 'remove files matching query' do
|
67
|
-
|
68
|
-
parameter "QUERY", 'the query to perform', :attribute_name => :query, :required => true
|
69
|
-
|
70
|
-
def execute
|
71
|
-
parser = ::Taggata::Parser::Query.new db
|
72
|
-
results = parser.parse query
|
73
|
-
db.transaction do
|
74
|
-
results.each(&:destroy)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
subcommand 'list', 'list things in database' do
|
81
|
-
|
82
|
-
parameter 'TYPE', 'type of records to list, can be one of file, directory, tag', :attribute_name => :type, :required => true do |type|
|
83
|
-
signal_usage_error 'TYPE must be one of file, directory, tag' unless %(file directory tag).include? type
|
84
|
-
type.to_sym
|
85
|
-
end
|
86
|
-
|
87
|
-
def execute
|
88
|
-
case type
|
89
|
-
when :file
|
90
|
-
db.find(Taggata::Persistent::File, {}).each { |file| puts file.path }
|
91
|
-
when :directory
|
92
|
-
db.find(Taggata::Persistent::Directory, {}).each { |dir| puts dir.path }
|
93
|
-
when :tag
|
94
|
-
db.find(Taggata::Persistent::Tag, {}).each { |tag| puts tag.name }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
21
|
+
subcommand 'scan', 'Scan the system', ScanCommand
|
22
|
+
|
23
|
+
subcommand 'tag', 'Tag a file matching query', TagCommand
|
24
|
+
|
25
|
+
subcommand 'search', "Search the database", SearchCommand
|
26
|
+
|
27
|
+
subcommand 'remove', 'Remove files matching query', RemoveCommand
|
28
|
+
|
29
|
+
subcommand 'list', 'List things in database', ListCommand
|
30
|
+
|
31
|
+
subcommand 'cleanup', 'Remove stale entries from the database', CleanupCommand
|
32
|
+
|
100
33
|
end
|
101
34
|
end
|
102
35
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Taggata
|
2
|
+
module Cli
|
3
|
+
class CleanupCommand < Clamp::Command
|
4
|
+
|
5
|
+
option %w(-t --tags), :flag, 'remove unused tags', :default => true, :attribute_name => :tags
|
6
|
+
|
7
|
+
def execute
|
8
|
+
remove_tags if tags?
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def remove_tags
|
14
|
+
tags = @db.find_tags_without_files
|
15
|
+
count = @db.destroy(Taggata::Persistent::Tag, tags.map(&:to_hash)) unless tags.empty?
|
16
|
+
puts "Removed tags: #{format_count count}" unless @quiet
|
17
|
+
end
|
18
|
+
|
19
|
+
def format_count(count)
|
20
|
+
count.nil? ? 0 : count
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Taggata
|
2
|
+
module Cli
|
3
|
+
class ListCommand < Clamp::Command
|
4
|
+
|
5
|
+
parameter 'TYPE', 'type of records to list, can be one of file, directory, tag', :attribute_name => :type, :required => true do |type|
|
6
|
+
signal_usage_error 'TYPE must be one of file, directory, tag' unless %(file directory tag).include? type
|
7
|
+
type.to_sym
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
case type
|
12
|
+
when :file
|
13
|
+
@db.find(Taggata::Persistent::File, {}).each { |file| puts file.path }
|
14
|
+
when :directory
|
15
|
+
@db.find(Taggata::Persistent::Directory, {}).each { |dir| puts dir.path }
|
16
|
+
when :tag
|
17
|
+
@db.find(Taggata::Persistent::Tag, {}).each { |tag| puts tag.name }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Taggata
|
2
|
+
module Cli
|
3
|
+
class RemoveCommand < Clamp::Command
|
4
|
+
|
5
|
+
parameter "QUERY", 'the query to perform', :attribute_name => :query, :required => true
|
6
|
+
|
7
|
+
def execute
|
8
|
+
parser = ::Taggata::Parser::Query.new @db
|
9
|
+
results = parser.parse query
|
10
|
+
@db.transaction do
|
11
|
+
results.each(&:destroy)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Taggata
|
2
|
+
module Cli
|
3
|
+
class ScanCommand < Clamp::Command
|
4
|
+
|
5
|
+
parameter "[ROOT]", "the root of the scanned tree", :attribute_name => :root_path, :default => './'
|
6
|
+
|
7
|
+
def execute
|
8
|
+
scanner = Taggata::Scanner.new @db
|
9
|
+
root = Taggata::Persistent::Directory.find_or_create @db, :name => root_path
|
10
|
+
scanner.process(root)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Taggata
|
2
|
+
module Cli
|
3
|
+
class SearchCommand < Clamp::Command
|
4
|
+
|
5
|
+
option "-c", :flag, 'show only matched count', :attribute_name => :count, :default => false
|
6
|
+
option "-n", :flag, 'show only names without paths', :attribute_name => :names, :default => false
|
7
|
+
parameter "QUERY", 'the query to perform', :attribute_name => :query, :required => true
|
8
|
+
|
9
|
+
def execute
|
10
|
+
results = ::Taggata::Parser::Query.new(@db).parse(query)
|
11
|
+
if count?
|
12
|
+
puts results.count
|
13
|
+
else
|
14
|
+
if results.empty?
|
15
|
+
puts "No results matching the query."
|
16
|
+
else
|
17
|
+
method = names? ? :name : :path
|
18
|
+
results.each { |file| puts file.send(method) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Taggata
|
2
|
+
module Cli
|
3
|
+
class TagCommand < Clamp::Command
|
4
|
+
|
5
|
+
parameter 'TAG_QUERY', 'the tag query', :attribute_name => :tag_query, :required => true
|
6
|
+
parameter 'SEARCH_QUERY', 'the query to search', :attribute_name => :search_query, :required => true
|
7
|
+
|
8
|
+
def execute
|
9
|
+
tags = ::Taggata::Parser::Tag.new(@db).parse(tag_query)
|
10
|
+
files = ::Taggata::Parser::Query.new(@db).parse(search_query)
|
11
|
+
@db.transaction do
|
12
|
+
files.each do |file|
|
13
|
+
file.add_tags *tags[:add]
|
14
|
+
file.remove_tags *tags[:del]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/taggata/db.rb
CHANGED
@@ -21,6 +21,10 @@ module Taggata
|
|
21
21
|
adapter.find_untagged_files.map { |hash| Persistent::File.new_from_hash self, hash }
|
22
22
|
end
|
23
23
|
|
24
|
+
def find_tags_without_files
|
25
|
+
adapter.find_tags_without_files.map { |hash| Persistent::Tag.new_from_hash self, hash }
|
26
|
+
end
|
27
|
+
|
24
28
|
def destroy(klass, options)
|
25
29
|
adapter.destroy(klass, options)
|
26
30
|
end
|
@@ -22,6 +22,13 @@ module Taggata
|
|
22
22
|
find(Taggata::Persistent::File, :id => untagged_ids)
|
23
23
|
end
|
24
24
|
|
25
|
+
def find_tags_without_files
|
26
|
+
file_tags = db[Persistent::FileTag.table].select(:tag_id).map { |hash| hash[:tag_id] }
|
27
|
+
tag_ids = db[Persistent::Tag.table].select(:id).map { |hash| hash[:id] }
|
28
|
+
untagged_ids = tag_ids.reject { |id| file_tags.include? id }
|
29
|
+
find(Persistent::Tag, :id => untagged_ids)
|
30
|
+
end
|
31
|
+
|
25
32
|
def destroy(klass, options)
|
26
33
|
db[klass.table].where(options).delete
|
27
34
|
end
|
@@ -32,7 +32,7 @@ module Taggata
|
|
32
32
|
def remove_tags(*to_remove)
|
33
33
|
return if to_remove.empty?
|
34
34
|
current_tag_ids = tags.map(&:id)
|
35
|
-
to_remove_ids = current_tag_ids
|
35
|
+
to_remove_ids = current_tag_ids & to_remove.map(&:id)
|
36
36
|
options = to_remove_ids.map { |tag_id| { :file_id => id, :tag_id => tag_id } }
|
37
37
|
db.destroy(FileTag, options)
|
38
38
|
end
|
data/lib/taggata/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taggata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Ruzicka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -216,6 +216,13 @@ files:
|
|
216
216
|
- bin/taggata
|
217
217
|
- lib/taggata.rb
|
218
218
|
- lib/taggata/cli.rb
|
219
|
+
- lib/taggata/cli/cleanup.rb
|
220
|
+
- lib/taggata/cli/list.rb
|
221
|
+
- lib/taggata/cli/main.rb
|
222
|
+
- lib/taggata/cli/remove.rb
|
223
|
+
- lib/taggata/cli/scan.rb
|
224
|
+
- lib/taggata/cli/search.rb
|
225
|
+
- lib/taggata/cli/tag.rb
|
219
226
|
- lib/taggata/constants.rb
|
220
227
|
- lib/taggata/db.rb
|
221
228
|
- lib/taggata/db_adapters.rb
|