fundler 0.2.2 → 0.2.3

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: 6bd396afe86ce80e1f88e81b56a12f30b81e07aa
4
- data.tar.gz: 4d2eb9f303f0d4e6bae095e603e6d3d98339b2ae
3
+ metadata.gz: bfbaef5181cc209495603196eb1bb6970cf630b8
4
+ data.tar.gz: 15497ddc1d211b92cdffc27ea2c710c943c32db3
5
5
  SHA512:
6
- metadata.gz: 1f1b195a5f4b970646708c0fd9d03e96a42252b60522a72544c67a053edcf0bf38cc2769be88d338ab3787eda00d00f8dbb79fe4fa9a5925d71cff83487dbe83
7
- data.tar.gz: 0360ce610247f9e54ad3c2a2a955ba08e3e1f911739ad2382002f87d576550e31ea6c286c210bfe436ded229e8b09175d2e81ccdfaa214e3a1eb55c5e7d8f0f8
6
+ metadata.gz: daf98e3b3b63085f0b322eed6fbc1ea3ef5aacfa8c09cc654d2849fb8ef1f63958fc01337b729964e5cd379b481e9f2014931d000171632b3e2b8d21aab1e97e
7
+ data.tar.gz: 76d0b5f55c5b51a6347ed61aeacff401727de1903550c3ac4f2780b3048ed944d02861ae61b9f82f4b6225d59142e5548ce1af8750e9a7a3336d861df137559d
data/README.md CHANGED
@@ -6,7 +6,7 @@ TODO: Write a gem description
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'findler'
9
+ gem 'fundler'
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,12 +14,21 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install findler
17
+ $ gem install fundler
18
18
 
19
19
  ## Usage
20
20
 
21
21
  TODO: Write usage instructions here
22
22
 
23
+ ```
24
+
25
+ $ fundler -h
26
+ $ fundler -c
27
+ $ fundler -b
28
+
29
+
30
+ ```
31
+
23
32
  ## Contributing
24
33
 
25
34
  1. Fork it
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+
3
+ module BookmarksReader
4
+
5
+ =begin rdoc
6
+
7
+ == Schema
8
+ http://people.mozilla.org/~dietrich/places-erd.png
9
+
10
+ == References
11
+ http://stackoverflow.com/questions/464516/firefox-bookmarks-sqlite-structure
12
+ https://developer.mozilla.org/en-US/docs/Places
13
+ https://developer.mozilla.org/en-US/docs/Retrieving_part_of_the_bookmarks_tree
14
+ https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavBookmarksService
15
+ http://davidkoepi.wordpress.com/2010/11/27/firefoxforensics/
16
+
17
+ == Queries
18
+ sqlite> select moz_places.url, moz_bookmarks.title from moz_places,moz_bookmarks where moz_places.id = moz_bookmarks.fk and moz_bookmarks.title != '';
19
+ sqlite> select keyword,url from moz_keywords left join moz_bookmarks on (moz_keywords.id = keyword_id) left join moz_places on (fk = moz_places.id);
20
+ sqlite> select moz_places.url, datetime((moz_historyvisits.visit_date/1000000), ‘unixepoch’, ‘localtime’), moz_historyvisits.visit_type from moz_places, moz_historyvisits where moz_historyvisits.place_id = moz_places.id order by moz_historyvisits.visit_date desc;
21
+ =end
22
+
23
+ MOZILLA_FIREFOX_CONF_DIR = File.expand_path('~') + '/.mozilla/firefox/'
24
+ # BOOKMARKS_QUERY = %q{select moz_places.url, moz_bookmarks.title from moz_places, moz_bookmarks where moz_places.id = moz_bookmarks.fk and moz_bookmarks.title != '';}
25
+ BOOKMARKS_QUERY = <<-SQL
26
+ SELECT DISTINCT
27
+ moz_places.url AS url,
28
+ moz_bookmarks.title AS title,
29
+ moz_items_annos.content AS description
30
+
31
+ FROM
32
+ moz_places,
33
+ moz_bookmarks,
34
+ moz_items_annos,
35
+ moz_anno_attributes
36
+
37
+ WHERE
38
+ moz_anno_attributes.name = 'bookmarkProperties/description'
39
+ AND moz_items_annos.anno_attribute_id = moz_anno_attributes.id
40
+ AND moz_items_annos.item_id = moz_bookmarks.id
41
+ AND moz_places.id = moz_bookmarks.fk
42
+ AND moz_places.id IN (
43
+ SELECT DISTINCT fk FROM moz_bookmarks
44
+ WHERE parent IN (
45
+ SELECT moz_bookmarks.id
46
+ FROM moz_bookmarks, moz_bookmarks_roots
47
+ WHERE moz_bookmarks_roots.root_name = 'tags'
48
+ AND moz_bookmarks.parent = moz_bookmarks_roots.folder_id
49
+ )
50
+ )
51
+
52
+ ORDER BY UPPER(moz_bookmarks.title) ASC
53
+ SQL
54
+
55
+ # +drop_bookmarks+ browse the home directory of the current user,
56
+ # locate the +places.sqlite+ db_file generated by Firefox and
57
+ # retrieve all the bookmarks stored.
58
+ def drop_bookmarks(format = :plain)
59
+ require 'sqlite3'
60
+ db = SQLite3::Database.new(locate_places)
61
+ db.execute(BOOKMARKS_QUERY) do |row|
62
+ case format
63
+ when :plain
64
+ puts row
65
+ puts '---'
66
+ when :html
67
+ puts "TODO"
68
+ when :markdown
69
+ puts "TODO"
70
+ end
71
+ end
72
+ end
73
+
74
+ def locate_places
75
+ begin
76
+ dot_firefox = Dir.open(MOZILLA_FIREFOX_CONF_DIR)
77
+ profile_dir = dot_firefox.select {|dir| dir =~ /.*default/}
78
+ db_file = MOZILLA_FIREFOX_CONF_DIR + profile_dir.join + '/places.sqlite'
79
+ rescue Errno::ENOENT
80
+ puts "no db_bookmarks found"
81
+ exit 1
82
+ end
83
+ end
84
+
85
+ def dump_places
86
+ FileUtils.cp(locate_places, pwd)
87
+ end
88
+
89
+ end # BookmarksReader
90
+
@@ -52,68 +52,6 @@ module FindAndClean
52
52
  end
53
53
  puts out
54
54
  end
55
-
56
- =begin rdoc
57
-
58
- == Schema
59
- http://people.mozilla.org/~dietrich/places-erd.png
60
-
61
- == References
62
- http://stackoverflow.com/questions/464516/firefox-bookmarks-sqlite-structure
63
- https://developer.mozilla.org/en-US/docs/Places
64
- https://developer.mozilla.org/en-US/docs/Retrieving_part_of_the_bookmarks_tree
65
- https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavBookmarksService
66
- http://davidkoepi.wordpress.com/2010/11/27/firefoxforensics/
67
-
68
- == Queries
69
- sqlite> select moz_places.url, moz_bookmarks.title from moz_places,moz_bookmarks where moz_places.id = moz_bookmarks.fk and moz_bookmarks.title != '';
70
- sqlite> select keyword,url from moz_keywords left join moz_bookmarks on (moz_keywords.id = keyword_id) left join moz_places on (fk = moz_places.id);
71
- sqlite> select moz_places.url, datetime((moz_historyvisits.visit_date/1000000), ‘unixepoch’, ‘localtime’), moz_historyvisits.visit_type from moz_places, moz_historyvisits where moz_historyvisits.place_id = moz_places.id order by moz_historyvisits.visit_date desc;
72
- =end
73
-
74
- MOZILLA_FIREFOX_CONF_DIR = File.expand_path('~') + '/.mozilla/firefox/'
75
- # BOOKMARKS_QUERY = %q{select moz_places.url, moz_bookmarks.title from moz_places, moz_bookmarks where moz_places.id = moz_bookmarks.fk and moz_bookmarks.title != '';}
76
- BOOKMARKS_QUERY = <<-SQL
77
- SELECT DISTINCT
78
- moz_places.url AS url,
79
- moz_bookmarks.title AS title,
80
- moz_items_annos.content AS description
81
-
82
- FROM
83
- moz_places,
84
- moz_bookmarks,
85
- moz_items_annos,
86
- moz_anno_attributes
87
-
88
- WHERE
89
- moz_anno_attributes.name = 'bookmarkProperties/description'
90
- AND moz_items_annos.anno_attribute_id = moz_anno_attributes.id
91
- AND moz_items_annos.item_id = moz_bookmarks.id
92
- AND moz_places.id = moz_bookmarks.fk
93
- AND moz_places.id IN (
94
- SELECT DISTINCT fk FROM moz_bookmarks
95
- WHERE parent IN (
96
- SELECT moz_bookmarks.id
97
- FROM moz_bookmarks, moz_bookmarks_roots
98
- WHERE moz_bookmarks_roots.root_name = 'tags'
99
- AND moz_bookmarks.parent = moz_bookmarks_roots.folder_id
100
- )
101
- )
102
-
103
- ORDER BY UPPER(moz_bookmarks.title) ASC
104
- SQL
105
- def drop_bookmarks
106
- dot_firefox = Dir.open(MOZILLA_FIREFOX_CONF_DIR)
107
- profile_dir = dot_firefox.select {|dir| dir =~ /.*default/}
108
- db_file = MOZILLA_FIREFOX_CONF_DIR + profile_dir.join + '/places.sqlite'
109
- require 'sqlite3'
110
- db = SQLite3::Database.new(db_file)
111
- db.execute(BOOKMARKS_QUERY) do |row|
112
- puts row
113
- puts '---'
114
- end
115
- FileUtils.cp(db_file, pwd)
116
- end
117
55
 
118
56
  end #FindAndClean
119
57
 
@@ -3,6 +3,28 @@
3
3
  require 'fileutils'
4
4
  require 'rspec'
5
5
 
6
+ class String
7
+
8
+ def squish
9
+ dup.squish!
10
+ end
11
+
12
+ def squish!
13
+ strip!
14
+ gsub!(/\s+/, ' ')
15
+ self
16
+ end
17
+
18
+ end
19
+
20
+ module FundlerUtils
21
+
22
+ def self.included(base)
23
+ # ...
24
+ end
25
+
26
+ end
27
+
6
28
  module ExitCodeMatchers
7
29
  RSpec::Matchers.define :exit_with_code do |code|
8
30
  actual = nil
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
  class Fundler
3
3
  # The version of the Fundler Utility.
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/fundler.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require 'fundler/find_and_clean'
2
- require 'fileutils'
2
+ require 'fundler/bookmarks_reader'
3
+ require 'fundler/fundler_utils'
4
+ require 'fundler/version'
3
5
 
4
6
  class Fundler
5
7
  include FindAndClean
8
+ include BookmarksReader
9
+ include FundlerUtils
6
10
  def clean
7
11
  clean_all_filenames
8
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - zeroed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-29 00:00:00.000000000 Z
11
+ date: 2013-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,12 +54,12 @@ files:
54
54
  - bin/fundler
55
55
  - fundler.gemspec
56
56
  - lib/fundler.rb
57
+ - lib/fundler/bookmarks_reader.rb
57
58
  - lib/fundler/find_and_clean.rb
58
59
  - lib/fundler/fundler_utils.rb
59
60
  - lib/fundler/version.rb
60
61
  - places.sqlite
61
62
  - spec/fundler_spec.rb
62
- - spec/fundler_spec.rb~
63
63
  homepage: https://github.com/zeroed/fundler
64
64
  licenses:
65
65
  - GPL3
@@ -86,5 +86,4 @@ specification_version: 4
86
86
  summary: find rename utility
87
87
  test_files:
88
88
  - spec/fundler_spec.rb
89
- - spec/fundler_spec.rb~
90
89
  has_rdoc:
@@ -1,70 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
-
4
- require 'fundler'
5
- require 'fundler/findler_utils'
6
-
7
- RSpec.configure do |config|
8
- config.filter_run_excluding ruby: ->(v) { !RUBY_VERSION.start_with?(v.to_s) }
9
- config.color_enabled = true
10
- config.formatter = 'documentation'
11
- # https://github.com/rspec/rspec-expectations
12
- config.expect_with :rspec do |c|
13
- c.syntax = :expect # disables `should`
14
- end
15
-
16
- config.include(ExitCodeMatchers)
17
- end
18
-
19
- class TestFundler
20
- describe Fundler do
21
- let(:finder) { Fundler.new }
22
- before(:each) do
23
- FileUtils::mkdir 'test'
24
- File.open('test/example', 'w') do |f|
25
- f.puts '#!/usr/bin/env ruby'
26
- f.puts '# encoding: utf-8'
27
- f.puts 'x = 0'
28
- f.puts 'puts x'
29
- end
30
- File.open('test/example_rb.rb', 'w') do |f|
31
- f.puts 'x = :foo'
32
- f.puts 'puts x'
33
- end
34
- File.open('test/list.txt', 'w') do |f|
35
- f.puts 'grocery list'
36
- f.puts '- chunky bacon'
37
- end
38
- File.open('test/SpAcE cAmEl.txt', 'w') do |f|
39
- f.puts 'foo!'
40
- end
41
- end
42
- after(:each) do
43
- FileUtils::rm_rf 'test'
44
- end
45
-
46
- it 'finds all files' do
47
- FileUtils::cd './test' do
48
- expect(finder.all_files()).to eq(['example', 'example_rb.rb', 'list.txt', 'SpAcE cAmEl.txt'].sort)
49
- end
50
- end
51
- it 'finds a file with no .rb extension but has a shebang line' do
52
- FileUtils::cd './test' do
53
- expect(finder.ruby_files()).to eq(['example', 'example_rb.rb'])
54
- end
55
- end
56
- it 'clean all filenames' do
57
- FileUtils::cd './test' do
58
- expect(finder.clean_all_filenames()).to eq(4)
59
- expect(finder.all_files()).to eq(['example', 'example_rb.rb', 'list.txt', 'space_camel.txt'].sort)
60
- end
61
- end
62
- it 'show the pwd (last dir in this spec)' do
63
- FileUtils::cd './test' do
64
- expect(finder.get_pwd.split('/').last).to eq('test')
65
- end
66
- end
67
-
68
- end # describe
69
-
70
- end #TestFundler