firebrew 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +127 -0
- data/Rakefile +6 -0
- data/bin/firebrew +5 -0
- data/firebrew.gemspec +29 -0
- data/lib/firebrew.rb +20 -0
- data/lib/firebrew/amo_api/search.rb +50 -0
- data/lib/firebrew/command_line.rb +140 -0
- data/lib/firebrew/entity.rb +39 -0
- data/lib/firebrew/firefox/basic_extension.rb +10 -0
- data/lib/firebrew/firefox/command.rb +27 -0
- data/lib/firebrew/firefox/extension.rb +104 -0
- data/lib/firebrew/firefox/profile.rb +56 -0
- data/lib/firebrew/runner.rb +83 -0
- data/lib/firebrew/version.rb +3 -0
- data/spec/double/firefox.rb +2 -0
- data/spec/firebrew/amo_api/search_spec.rb +69 -0
- data/spec/firebrew/command_line_spec.rb +150 -0
- data/spec/firebrew/entity_spec.rb +79 -0
- data/spec/firebrew/firefox/command_spec.rb +39 -0
- data/spec/firebrew/firefox/extension_spec.rb +159 -0
- data/spec/firebrew/firefox/profile_spec.rb +69 -0
- data/spec/firebrew/runner_spec.rb +142 -0
- data/spec/firebrew_spec.rb +7 -0
- data/spec/fixtures/amo_api/search/base.xml +28 -0
- data/spec/fixtures/amo_api/search/empty.xml +4 -0
- data/spec/fixtures/amo_api/search/single.xml +12 -0
- data/spec/fixtures/firefox/extension/extensions.v16.json +227 -0
- data/spec/fixtures/firefox/extension/extensions_added_hoge.v16.json +235 -0
- data/spec/fixtures/firefox/profile/base.ini +18 -0
- data/spec/fixtures/firefox/profile/empty.ini +2 -0
- data/spec/spec_helper.rb +13 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee0908cafa9dc7f91a605e060ed0e023b63cb9a4
|
4
|
+
data.tar.gz: 88e3a156dfba8e25ed0f3dab12e6a6418a6a5f93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9258b7043880fe71cf3259f7b4d065694e8936d3a69f88bf63705d2d98cd77223dfdbeb3ca0de5bca35768e605c9e6d0e7562494818d06eab1247839eddb95d3
|
7
|
+
data.tar.gz: 5b7b4e143d90517b87eeb16938b51171356970b91d105f8be5d5f62874ae8caf118c9f7a8cf3dfccf1b841b2f5401669ae67631535617f9610858940a5661e12
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yuichi Murata
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Firebrew
|
2
|
+
|
3
|
+
Firefox add-ons manager for CUI.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'firebrew'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install firebrew
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The structure of the command line is shown below:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ firebrew [--help] [--version]
|
25
|
+
[--base-dir=<path>] [--profile=<name>] [--firefox=<path>]
|
26
|
+
<command> [<args>]
|
27
|
+
```
|
28
|
+
|
29
|
+
### commands
|
30
|
+
|
31
|
+
#### install
|
32
|
+
|
33
|
+
Install the extension which is designated by the `extension-name` argument:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
$ firebrew install <extension-name>
|
37
|
+
```
|
38
|
+
|
39
|
+
#### uninstall
|
40
|
+
|
41
|
+
Uninstall the extension which is designated by the `extension-name` argument:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
$ firebrew uninstall <extension-name>
|
45
|
+
```
|
46
|
+
|
47
|
+
#### info
|
48
|
+
|
49
|
+
Show detail information of the extension which is designated by the `extension-name` argument:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
$ firebrew info <extension-name>
|
53
|
+
```
|
54
|
+
|
55
|
+
#### search
|
56
|
+
|
57
|
+
Enumerate the remote extensions whose name is matched the `term` argument:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
$ firebrew search <term>
|
61
|
+
```
|
62
|
+
|
63
|
+
#### list
|
64
|
+
|
65
|
+
Enumerate the installed extensions:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
$ firebrew list
|
69
|
+
```
|
70
|
+
|
71
|
+
### options
|
72
|
+
|
73
|
+
#### --base-dir
|
74
|
+
|
75
|
+
The Firefox profiles.ini directory:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
-d <path>, --base-dir=<path>
|
79
|
+
```
|
80
|
+
|
81
|
+
The default value is listed below:
|
82
|
+
|
83
|
+
| platform | path |
|
84
|
+
| -------- | ---- |
|
85
|
+
| Mac OS X | ~/Library/Application Support/Firefox |
|
86
|
+
| Linux | ~/.mozilla/firefox |
|
87
|
+
| Windows 7 x86\_64 | %UserProfile%\AppData\Roming\Mozilla\Firefox |
|
88
|
+
|
89
|
+
It's able to overridden by the `FIREBREW_FIREFOX_PROFILE_BASE_DIR` environment variable.
|
90
|
+
|
91
|
+
#### --profile-name
|
92
|
+
|
93
|
+
The Firefox profile name:
|
94
|
+
|
95
|
+
```bash
|
96
|
+
-p <name>, --profile=<name>
|
97
|
+
```
|
98
|
+
|
99
|
+
The default value is `default`, and it's able to overridden by the `FIREBREW_FIREFOX_PROFILE` environment variable.
|
100
|
+
|
101
|
+
#### --firefox
|
102
|
+
|
103
|
+
The Firefox command path:
|
104
|
+
|
105
|
+
```bash
|
106
|
+
-f <path>, --firefox=<path>
|
107
|
+
```
|
108
|
+
|
109
|
+
The default value is listed below:
|
110
|
+
|
111
|
+
| platform | path |
|
112
|
+
| -------- | ---- |
|
113
|
+
| Mac OS X | /Applications/Firefox.app/Contents/MacOS/firefox-bin |
|
114
|
+
| Linux | /usr/bin/firefox |
|
115
|
+
| Windows 7 x86\_64 | C:\Program Files (x86)\Mozilla Firefox\firefox.exe |
|
116
|
+
|
117
|
+
It's able to overridden by the `FIREBREW_FIREFOX` environment variable.
|
118
|
+
|
119
|
+
|
120
|
+
## Contributing
|
121
|
+
|
122
|
+
1. Fork it ( http://github.com/mrk21/firebrew/fork )
|
123
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
124
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
125
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
126
|
+
5. Create new Pull Request
|
127
|
+
|
data/Rakefile
ADDED
data/bin/firebrew
ADDED
data/firebrew.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'firebrew/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "firebrew"
|
8
|
+
spec.version = Firebrew::VERSION
|
9
|
+
spec.authors = ["Yuichi Murata"]
|
10
|
+
spec.email = ["mrk21info+rubygems@gmail.com"]
|
11
|
+
spec.summary = %q{Firefox add-ons manager for CUI.}
|
12
|
+
spec.description = %q{Firefox add-ons manager for CUI.}
|
13
|
+
spec.homepage = "https://github.com/mrk21/firebrew"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
|
25
|
+
spec.add_dependency "activesupport", "~> 4.1"
|
26
|
+
spec.add_dependency "activeresource", "~> 4.0"
|
27
|
+
spec.add_dependency "activemodel", "~> 4.1"
|
28
|
+
spec.add_dependency "inifile", "~> 2.0"
|
29
|
+
end
|
data/lib/firebrew.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "firebrew/version"
|
2
|
+
|
3
|
+
module Firebrew
|
4
|
+
class Error < StandardError; def status; 1 end end
|
5
|
+
class ProfilesFileNotFoundError < Error; def status; 2 end end
|
6
|
+
class ProfileNotFoundError < Error; def status; 3 end end
|
7
|
+
class ExtensionsFileNotFoundError < Error; def status; 4 end end
|
8
|
+
class ExtensionNotFoundError < Error; def status; 5 end end
|
9
|
+
class FirefoxCommandError < Error; def status; 6 end end
|
10
|
+
class CommandLineError < Error; def status; 7 end end
|
11
|
+
class OperationAlreadyCompletedError < Error; def status; 8 end end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'firebrew/entity'
|
15
|
+
require 'firebrew/amo_api/search'
|
16
|
+
require 'firebrew/firefox/profile'
|
17
|
+
require 'firebrew/firefox/extension'
|
18
|
+
require 'firebrew/firefox/command'
|
19
|
+
require 'firebrew/runner'
|
20
|
+
require 'firebrew/command_line'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
require 'uri'
|
3
|
+
require 'firebrew/firefox/basic_extension'
|
4
|
+
|
5
|
+
module Firebrew::AmoApi
|
6
|
+
class Search < ActiveResource::Base
|
7
|
+
class Format
|
8
|
+
include ActiveResource::Formats::XmlFormat
|
9
|
+
|
10
|
+
def decode(xml)
|
11
|
+
results = super(xml)['addon'] || []
|
12
|
+
results.instance_of?(Array) ? results : [results]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
self.site = 'https://services.addons.mozilla.org'
|
17
|
+
self.format = Format.new
|
18
|
+
|
19
|
+
def self.path(params={})
|
20
|
+
path_source = '/ja/firefox/api/%{api_version}/search/%{term}/%{type}/%{max}/%{os}/%{version}'
|
21
|
+
default_params = {
|
22
|
+
api_version: 1.5,
|
23
|
+
type: 'all',
|
24
|
+
max: 30,
|
25
|
+
os: 'all',
|
26
|
+
version: '',
|
27
|
+
}
|
28
|
+
URI.encode(path_source % default_params.merge(params))
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.fetch(params={})
|
32
|
+
self.find(:all, from: self.path(params)).to_a
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.fetch!(params={})
|
36
|
+
results = self.fetch(params)
|
37
|
+
raise Firebrew::ExtensionNotFoundError if results.empty?
|
38
|
+
results
|
39
|
+
end
|
40
|
+
|
41
|
+
def extension
|
42
|
+
Firebrew::Firefox::BasicExtension.new(
|
43
|
+
name: self.name,
|
44
|
+
guid: self.guid,
|
45
|
+
uri: self.install,
|
46
|
+
version: self.version
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Firebrew
|
4
|
+
class CommandLine
|
5
|
+
attr_accessor :arguments
|
6
|
+
|
7
|
+
def self.execute
|
8
|
+
begin
|
9
|
+
if block_given? then
|
10
|
+
yield
|
11
|
+
else
|
12
|
+
self.new(ARGV).execute
|
13
|
+
end
|
14
|
+
rescue Firebrew::Error => e
|
15
|
+
$stderr.puts e.message
|
16
|
+
exit e.status
|
17
|
+
rescue SystemExit => e
|
18
|
+
exit 1
|
19
|
+
rescue Exception => e
|
20
|
+
$stderr.puts e.inspect
|
21
|
+
$stderr.puts e.backtrace
|
22
|
+
exit 255
|
23
|
+
else
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(args=[])
|
29
|
+
opt = OptionParser.new
|
30
|
+
opt.version = Firebrew::VERSION
|
31
|
+
opt.banner = <<-USAGE.split(/\n/).map{|v| v.gsub(/^( ){4}/,'')}.join("\n")
|
32
|
+
Usage: firebrew [--help] [--version]
|
33
|
+
[--base-dir=<path>] [--profile=<name>] [--firefox=<path>]
|
34
|
+
<command> [<args>]
|
35
|
+
|
36
|
+
commands:
|
37
|
+
install:
|
38
|
+
firebrew install <extension-name>
|
39
|
+
|
40
|
+
uninstall:
|
41
|
+
firebrew uninstall <extension-name>
|
42
|
+
|
43
|
+
info:
|
44
|
+
firebrew info <extension-name>
|
45
|
+
|
46
|
+
search:
|
47
|
+
firebrew search <term>
|
48
|
+
|
49
|
+
list:
|
50
|
+
firebrew list
|
51
|
+
|
52
|
+
options:
|
53
|
+
USAGE
|
54
|
+
|
55
|
+
self.arguments = {
|
56
|
+
command: nil,
|
57
|
+
params: {},
|
58
|
+
config: {}
|
59
|
+
}
|
60
|
+
|
61
|
+
self.register_global_options(opt)
|
62
|
+
self.class.opt_operation(opt, :order!, args)
|
63
|
+
|
64
|
+
case args.shift
|
65
|
+
when 'install' then
|
66
|
+
self.class.opt_operation(opt, :permute!, args)
|
67
|
+
self.arguments[:command] = :install
|
68
|
+
self.arguments[:params][:term] = args[0]
|
69
|
+
|
70
|
+
when 'uninstall' then
|
71
|
+
self.class.opt_operation(opt, :permute!, args)
|
72
|
+
self.arguments[:command] = :uninstall
|
73
|
+
self.arguments[:params][:term] = args[0]
|
74
|
+
|
75
|
+
when 'info' then
|
76
|
+
self.class.opt_operation(opt, :permute!, args)
|
77
|
+
self.arguments[:command] = :info
|
78
|
+
self.arguments[:params][:term] = args[0]
|
79
|
+
|
80
|
+
when 'search' then
|
81
|
+
self.class.opt_operation(opt, :permute!, args)
|
82
|
+
self.arguments[:command] = :search
|
83
|
+
self.arguments[:params][:term] = args[0]
|
84
|
+
|
85
|
+
when 'list' then
|
86
|
+
self.class.opt_operation(opt, :permute!, args)
|
87
|
+
self.arguments[:command] = :list
|
88
|
+
|
89
|
+
when nil then
|
90
|
+
self.class.opt_operation(opt, :permute, ['--help'])
|
91
|
+
|
92
|
+
else
|
93
|
+
raise Firebrew::CommandLineError
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def execute
|
98
|
+
runner = Runner.new(self.arguments[:config])
|
99
|
+
|
100
|
+
case self.arguments[:command]
|
101
|
+
when :search, :list then
|
102
|
+
results = runner.send(self.arguments[:command], self.arguments[:params])
|
103
|
+
results.each do |result|
|
104
|
+
puts result.name
|
105
|
+
end
|
106
|
+
|
107
|
+
when :info then
|
108
|
+
result = runner.send(self.arguments[:command], self.arguments[:params])
|
109
|
+
puts result.to_xml
|
110
|
+
|
111
|
+
else
|
112
|
+
runner.send(self.arguments[:command], self.arguments[:params])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
|
118
|
+
def self.opt_operation(opt, operation, args)
|
119
|
+
begin
|
120
|
+
opt.send(operation, args)
|
121
|
+
rescue OptionParser::InvalidOption
|
122
|
+
raise Firebrew::CommandLineError
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def register_global_options(opt)
|
127
|
+
opt.on('-d <path>','--base-dir=<path>','Firefox profiles.ini directory') do |v|
|
128
|
+
self.arguments[:config][:base_dir] = v
|
129
|
+
end
|
130
|
+
|
131
|
+
opt.on('-p <name>','--profile=<name>','Firefox profile name') do |v|
|
132
|
+
self.arguments[:config][:profile] = v
|
133
|
+
end
|
134
|
+
|
135
|
+
opt.on('-f <path>','--firefox=<path>','Firefox command path') do |v|
|
136
|
+
self.arguments[:config][:firefox] = v
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|