zypper-onlinesearch 1.0.0 → 1.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.
data/README.md CHANGED
@@ -6,6 +6,9 @@ directly in your terminal.
6
6
  Basically it is just a command-line frontend to these search engines, it executes a query to them,
7
7
  arrange the results and display them in a table or report view.
8
8
 
9
+ [![Ruby](https://github.com/fabiomux/zypper-onlinesearch/actions/workflows/main.yml/badge.svg)][wf_main]
10
+ [![Gem Version](https://badge.fury.io/rb/zypper-onlinesearch.svg)][gem_version]
11
+
9
12
  ## Installation
10
13
 
11
14
  There are a couple of options to install this application.
@@ -44,108 +47,6 @@ To list the links from that page:
44
47
  $ onlinesearch -l <page>,<link_number>
45
48
  ```
46
49
 
47
- For example looking for *Qmmp*:
48
- ```shell
49
- $ onlinesearch -s qmmp
50
-
51
- ====================================================================================================
52
- Parameters: Engine: packman | Query: qmmp | Cache: On (2023-02-23 16:37)
53
- ====================================================================================================
54
- # | Page | Description
55
- ----------------------------------------------------------------------------------------------------
56
- 1 | qmmp | Qt-based Multimedia Player
57
- ----------------------------------------------------------------------------------------------------
58
- 2 | qmmp-plugin-pack | Extra plugins for Qmmp
59
- ----------------------------------------------------------------------------------------------------
60
-
61
- ====================================================================================================
62
- Parameters: Engine: opensuse | Query: qmmp | Cache: On (2023-02-23 16:37)
63
- ====================================================================================================
64
- # | Page | Description
65
- ----------------------------------------------------------------------------------------------------
66
- 1 | qmmp | Qt-based Multimedia Player
67
- ----------------------------------------------------------------------------------------------------
68
- 2 | libqmmp1 | Qmmp library
69
- ----------------------------------------------------------------------------------------------------
70
- 3 | libqmmp-devel | Development files for libqmmp
71
- ----------------------------------------------------------------------------------------------------
72
- ...
73
- ```
74
-
75
- We get among the results a page called *qmmp* for both engines, so to read that pages:
76
- ```shell
77
- $ onlinesearch -p qmmp
78
-
79
- ====================================================================================================
80
- Parameters: Engine: packman | OS: openSUSE Leap 15.4 | Architecture: 64 Bit | Cache: On (2023-02-07 16:57)
81
- ====================================================================================================
82
- Name: qmmp
83
- Summary:
84
- Description:
85
- Qt-based Multimedia Player
86
- ----------------------------------------------------------------------------------------------------
87
- # | Version | Repo | Distro
88
- ----------------------------------------------------------------------------------------------------
89
- 1 | 2.1.2 | Packman | openSUSE Leap 15.4
90
- ----------------------------------------------------------------------------------------------------
91
-
92
- ====================================================================================================
93
- Parameters: Engine: opensuse | OS: openSUSE Leap 15.4 | Architecture: 64 Bit | Cache: On (2023-02-07 16:57)
94
- ====================================================================================================
95
- Name: qmmp
96
- Summary: Qt-based Multimedia Player
97
- Description: This program is an audio-player, written with help of Qt library.
98
- ----------------------------------------------------------------------------------------------------
99
- # | Version | Repo | Distro
100
- ----------------------------------------------------------------------------------------------------
101
- 1 | 2.1.2 | home:plater | openSUSE Leap 15.4
102
- ----------------------------------------------------------------------------------------------------
103
- 2 | 1.4.4 | home:ykoba:multimedia | openSUSE Leap 15.4
104
- ----------------------------------------------------------------------------------------------------
105
- 3 | 2.1.2 | multimedia:apps | openSUSE Leap 15.4
106
- ----------------------------------------------------------------------------------------------------
107
- ```
108
-
109
- To show the page from one engine only, just append the `--engine <engine_name>` param:
110
- ```shell
111
- $ onlinesearch -p qmmp --engine opensuse
112
- ```
113
-
114
- To list the links in the third repository listed in the *opensuse* engine:
115
- ```shell
116
- $ onlinesearch -l qmmp,3 --engine opensuse
117
-
118
- ====================================================================================================
119
- Parameters: Engine: opensuse | OS: openSUSE Leap 15.4 | Architecture: 64 Bit | Cache: On (2023-02-07 16:57)
120
- ====================================================================================================
121
- Name: qmmp
122
- Summary: Qt-based Multimedia Player
123
- Description: This program is an audio-player, written with help of Qt library.
124
- ----------------------------------------------------------------------------------------------------
125
- # | Format | Link
126
- ----------------------------------------------------------------------------------------------------
127
- 1 | ymp | https://software.opensuse.org/ymp/multimedia:apps/15.4/qmmp.ymp?base=openSUSE%3ALeap%3A15.4&query=qmmp
128
- ----------------------------------------------------------------------------------------------------
129
- 2 | src | https://download.opensuse.org/repositories/multimedia:/apps/15.4/src/qmmp-2.1.2-lp154.182.3.src.rpm
130
- ----------------------------------------------------------------------------------------------------
131
- 3 | x86_64 | https://download.opensuse.org/repositories/multimedia:/apps/15.4/x86_64/qmmp-2.1.2-lp154.182.3.x86_64.rpm
132
- ----------------------------------------------------------------------------------------------------
133
- ```
134
-
135
- To print only the raw URLs:
136
- ```shell
137
- $ onlinesearch -l qmmp,3 --urls
138
- https://software.opensuse.org/ymp/multimedia:apps/15.4/qmmp.ymp?base=openSUSE%3ALeap%3A15.4&query=qmmp
139
- https://download.opensuse.org/repositories/multimedia:/apps/15.4/src/qmmp-2.1.2-lp154.182.3.src.rpm
140
- https://download.opensuse.org/repositories/multimedia:/apps/15.4/x86_64/qmmp-2.1.2-lp154.182.3.x86_64.rpm
141
- ```
142
-
143
- And in case we are interested to a specific format:
144
- ```shell
145
- $ onlinesearch -l qmmp,3 --urls --format ymp
146
- https://software.opensuse.org/ymp/multimedia:apps/15.4/qmmp.ymp?base=openSUSE%3ALeap%3A15.4&query=qmmp
147
- ```
148
-
149
50
  ## Get help
150
51
 
151
52
  Where to start:
@@ -156,7 +57,10 @@ $ onlinesearch --help
156
57
  ## More Help:
157
58
 
158
59
  More info is available at:
159
- - the [Zypper-Onlinesearch Project page][project_page].
60
+ - the [Zypper-Onlinesearch Project page][project_page];
61
+ - the [Zypper-Onlinesearch Github wiki][zypper_onlinesearch_wiki].
160
62
 
161
63
  [project_page]: https://freeaptitude.altervista.org/projects/zypper-onlinesearch.html "Zypper-Onlinesearch project page"
162
-
64
+ [zypper_onlinesearch_wiki]: https://github.com/fabiomux/zypper-onlinesearch/wiki "Zypper-Onlinesearch wiki page on GitHub"
65
+ [wf_main]: https://github.com/fabiomux/zypper-onlinesearch/actions/workflows/main.yml
66
+ [gem_version]: https://badge.fury.io/rb/zypper-onlinesearch
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -1,40 +1,39 @@
1
- require 'fileutils'
2
- require 'uri'
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "uri"
3
5
 
4
6
  module Zypper
5
7
  module Onlinesearch
6
-
8
+ #
9
+ # Handles the cached data.
10
+ #
7
11
  class Cache
8
-
9
12
  def initialize(operation, engine)
10
- @base_folder = File.join(ENV['HOME'], '.cache', 'zypper-onlinesearch', engine, operation)
11
- FileUtils.mkdir_p @base_folder unless Dir.exists? @base_folder
13
+ @base_folder = File.join(Dir.home, ".cache", "zypper-onlinesearch", engine, operation)
14
+ FileUtils.mkdir_p @base_folder
12
15
  end
13
16
 
14
17
  def set(query, response)
15
- File.open(File.join(@base_folder, query_to_filename(query)), 'w+') do |f|
16
- f.write Marshal.dump(response)
17
- end
18
+ File.write(File.join(@base_folder, query_to_filename(query)), Marshal.dump(response))
18
19
  end
19
20
 
20
21
  def get(query)
21
22
  fname = query_to_filename(query)
22
- Marshal.load(File.read(File.join(@base_folder, fname))) if exists? query
23
+ Marshal.load(File.read(File.join(@base_folder, fname))) if exist? query
23
24
  end
24
25
 
25
- def exists?(query)
26
- File.exists?(File.join(@base_folder, query_to_filename(query)))
26
+ def exist?(query)
27
+ File.exist?(File.join(@base_folder, query_to_filename(query)))
27
28
  end
28
29
 
29
30
  def self.reset!
30
- base_folder = File.join(ENV['HOME'], '.cache', 'zypper-onlinesearch')
31
- if Dir.exist? base_folder
32
- size = Dir.glob(File.join(base_folder, '**', '*')).map{ |f| File.size(f) }.inject(:+)
33
- FileUtils.remove_dir base_folder
34
- return size
35
- else
36
- raise EmptyCache
37
- end
31
+ base_folder = File.join(Dir.home, ".cache", "zypper-onlinesearch")
32
+ raise EmptyCache unless Dir.exist? base_folder
33
+
34
+ size = Dir.glob(File.join(base_folder, "**", "*")).map { |f| File.size(f) }.inject(:+)
35
+ FileUtils.remove_dir base_folder
36
+ size
38
37
  end
39
38
 
40
39
  def mtime(query)
@@ -45,10 +44,8 @@ module Zypper
45
44
  private
46
45
 
47
46
  def query_to_filename(query)
48
- URI.encode query.delete('./')
47
+ URI.encode query.delete("./")
49
48
  end
50
49
  end
51
-
52
50
  end
53
51
  end
54
-
@@ -1,162 +1,164 @@
1
- require 'optparse'
2
- require 'ostruct'
3
- require 'zypper/onlinesearch'
4
- require 'zypper/onlinesearch/version'
1
+ # frozen_string_literal: true
5
2
 
6
- module Zypper
3
+ require "optparse"
4
+ require "zypper/onlinesearch"
5
+ require "zypper/onlinesearch/version"
7
6
 
7
+ module Zypper
8
8
  module Onlinesearch
9
-
9
+ #
10
+ # Parsing the input data.
11
+ #
10
12
  class OptParseMain
11
-
12
13
  def self.parse(args)
13
- options = OpenStruct.new
14
+ options = Struct.new(:operation, :query, :refresh, :engine, :timeout, :formats,
15
+ :distributions, :types, :number, :view, :format).new
14
16
  options.operation = :search
15
- options.query = ''
17
+ options.query = ""
16
18
  options.refresh = false
17
19
  options.engine = :all # :opensuse, :packman
18
20
  options.timeout = 20
19
21
  options.formats = :compatible # :all
20
22
  options.distributions = :compatible # :all
21
- options.types = [:supported, :community, :experimental]
23
+ options.types = %i[supported community experimental unsupported]
22
24
  options.number = 0
23
25
  options.view = :table
24
26
  options.format = :all # or single format
25
- #options.preload = nil #used by :links or :page operations
27
+ # options.preload = nil #used by :links or :page operations
26
28
 
27
29
  opt_parser = OptionParser.new do |opt|
30
+ command = ENV["ZYPPER_ONLINESEARCH"] ? "zypper onlinesearch" : "onlinesearch"
31
+ opt.banner = "Usage: #{command} [OPTIONS] [OPERATION]"
28
32
 
29
- if ENV['ZYPPER_ONLINESEARCH']
30
- opt.banner = 'Usage: zypper onlinesearch [OPTIONS] [OPERATION]'
31
- else
32
- opt.banner = 'Usage: onlinesearch [OPTIONS] [OPERATION]'
33
- end
34
-
35
- opt.separator ''
36
- opt.separator 'Operations:'
33
+ opt.separator ""
34
+ opt.separator "Operations:"
37
35
 
38
- opt.on('-s', '--search <STRING>', 'Search for STRING to the online engines available') do |o|
36
+ opt.on("-s", "--search <STRING>", "Search for STRING to the online engines available") do |o|
39
37
  options.operation = :search
40
38
  options.query = o
41
39
  end
42
40
 
43
- opt.on('-p', '--page <PAGE_NAME>', 'Get info about the PAGE_NAME') do |o|
41
+ opt.on("-p", "--page <PAGE_NAME>", "Get info about the PAGE_NAME") do |o|
44
42
  options.operation = :page
45
43
  options.query = o
46
44
  end
47
45
 
48
- opt.on('-l', '--links <PAGE_NAME>,<NTH>', Array, 'Print all the links of the NTH item in the PAGE_NAME') do |o|
46
+ opt.on("-l", "--links <PAGE_NAME>,<NTH>", Array,
47
+ "Print all the links of the NTH item in the PAGE_NAME") do |o|
49
48
  options.operation = :links
50
49
  options.query = o[0]
51
50
  options.number = o[1].to_i
52
- #options.preload = :page
51
+ # options.preload = :page
53
52
  end
54
53
 
55
- opt.on('--clean-cache', 'Clean the whole cache') do |o|
54
+ opt.on("--clean-cache", "Clean the whole cache") do
56
55
  options.operation = :cache_clean
57
56
  end
58
57
 
59
- opt.separator ''
60
- opt.separator 'General Options'
58
+ opt.separator ""
59
+ opt.separator "General Options"
61
60
 
62
- opt.on('--engine <ENGINE>', 'Use only ENGINE to search for (default: ' + options.engine.to_s + ', alternatives: ' + Request::Search.constants.map(&:to_s).map(&:downcase).join(', ') + ')') do |o|
61
+ alt = Request::Search.constants.map(&:to_s).map(&:downcase).join(", ")
62
+ opt.on("--engine <ENGINE>",
63
+ "Use only ENGINE to search for (default: #{options.engine}, alternatives: #{alt})") do |o|
63
64
  options.engine = o.to_sym
64
65
  end
65
66
 
66
- opt.on('--refresh', 'Refresh the cached values.') do |o|
67
+ opt.on("--refresh", "Refresh the cached values.") do
67
68
  options.refresh = true
68
69
  end
69
70
 
70
- opt.on('--timeout <SECONDS>', "Adjust the waiting SECONDS used to catch an HTTP Timeout Error (Default: #{options.timeout})") do |o|
71
+ opt.on("--timeout <SECONDS>", "The SECONDS before an HTTP Timeout Error (Default: #{options.timeout})") do |o|
71
72
  options.timeout = o.to_f
72
73
  end
73
74
 
74
- opt.separator ''
75
- opt.separator 'View options:'
75
+ opt.separator ""
76
+ opt.separator "View options:"
76
77
 
77
- opt.on('--table', 'Show the results as a table [DEFAULT]') do |o|
78
+ opt.on("--table", "Show the results as a table [DEFAULT]") do
78
79
  options.view = :table
79
80
  end
80
81
 
81
- opt.on('--report', 'Show the results as report') do |o|
82
+ opt.on("--report", "Show the results as report") do
82
83
  options.view = :report
83
84
  end
84
85
 
85
- opt.separator ''
86
+ opt.separator ""
86
87
  opt.separator '"Page" and "Links" options:'
87
88
 
88
- opt.on('--all-formats', 'Show all the available formats') do |o|
89
+ opt.on("--all-formats", "Show all the available formats") do
89
90
  options.formats = :all
90
91
  end
91
92
 
92
- opt.on('--all-distributions', 'Show all the available distributions') do |o|
93
+ opt.on("--all-distributions", "Show all the available distributions") do
93
94
  options.distributions = :all
94
95
  end
95
96
 
96
- opt.on('--no-supported', 'Hide supported packages.') do |o|
97
+ opt.on("--no-supported", "Hide supported packages.") do
97
98
  options.types.delete :supported
98
99
  end
99
100
 
100
- opt.on('--no-experimental', 'Hide experimental packages.') do |o|
101
+ opt.on("--no-experimental", "Hide experimental packages.") do
101
102
  options.types.delete :experimental
102
103
  end
103
104
 
104
- opt.on('--no-community', 'Hide community packages.') do |o|
105
+ opt.on("--no-community", "Hide community packages.") do
105
106
  options.types.delete :community
106
107
  end
107
108
 
108
- opt.separator ''
109
+ opt.on("--no-unsupported", "Hide unsupported packages.") do
110
+ options.types.delete :unsupported
111
+ end
112
+
113
+ opt.separator ""
109
114
  opt.separator '"Links" options:'
110
115
 
111
- opt.on('--format FORMAT', 'Filter for packages with the specified FORMAT') do |o|
116
+ opt.on("--format FORMAT", "Filter for packages with the specified FORMAT") do |o|
112
117
  options.format = o.to_sym
113
118
  end
114
119
 
115
- opt.on('--urls', 'Show only the urls without headers') do |o|
120
+ opt.on("--urls", "Show only the urls without headers") do
116
121
  options.view = :urls
117
122
  end
118
123
 
119
- unless ENV['ZYPPER_ONLINESEARCH']
120
- opt.separator ''
121
- opt.separator 'Other:'
124
+ unless ENV["ZYPPER_ONLINESEARCH"]
125
+ opt.separator ""
126
+ opt.separator "Other:"
122
127
 
123
- opt.on_tail('-h', '--help', 'Show this message') do |o|
128
+ opt.on_tail("-h", "--help", "Show this message") do
124
129
  puts opt
125
130
  exit
126
131
  end
127
132
 
128
- opt.on_tail('-v', '--version', 'Show version') do |o|
133
+ opt.on_tail("-v", "--version", "Show version") do
129
134
  puts VERSION
130
135
  exit
131
136
  end
132
137
  end
133
-
134
138
  end
135
139
 
136
-
137
140
  if ARGV.empty?
138
- puts opt_parser; exit
141
+ puts opt_parser
142
+ exit
139
143
  else
140
- opt_parser.parse!(ARGV)
144
+ opt_parser.parse!(args)
141
145
  end
142
146
 
143
147
  options
144
148
  end
145
149
  end
146
150
 
147
-
151
+ #
152
+ # Interface class to run the application.
153
+ #
148
154
  class CLI
149
155
  def self.start
150
- begin
151
- options = OptParseMain.parse(ARGV)
152
- Onlinesearch::Builder.new(options).send(options.operation)
153
- rescue => e
154
- Messages.error e
155
- exit e.error_code
156
- end
156
+ options = OptParseMain.parse(ARGV)
157
+ Onlinesearch::Builder.new(options).send(options.operation)
158
+ rescue StandardError => e
159
+ Messages.error e
160
+ exit e.error_code
157
161
  end
158
162
  end
159
-
160
163
  end
161
164
  end
162
-