deb_version 0.1.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/Gemfile.lock +6 -1
- data/HACKING.md +37 -0
- data/README.md +11 -7
- data/Rakefile +1 -1
- data/deb_version.gemspec +4 -3
- data/lib/deb_version/compare.rb +84 -64
- data/lib/deb_version/version.rb +2 -2
- data/lib/deb_version.rb +8 -5
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 888af66ba17b645ae1ef3a98bbadf772a7486c59ccb2c6fb4eb7ca8b4a18449c
|
4
|
+
data.tar.gz: 7a656c657e4189e79f06ea9712d1be5584d42526931efc72d912bc5e36d9938d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 223bab3293c88121f74f3aa95c5fb489d955131c63548c9d140faabcce94ab1ebcadca37203648da562d21ff5c72992a8aa4a575fbb39f4dded6039303f73220
|
7
|
+
data.tar.gz: b5a4960c5205ae620092a5523c04a4f0ae8ac1e2b96ceba7225632d9d05e262d624ff98d5d7583b6147b2fcc554cd7aa2780ff0dbed25cc91c3e3f0d8e47c8d6
|
data/.rubocop.yml
CHANGED
@@ -12,7 +12,11 @@ Style/StringLiteralsInInterpolation:
|
|
12
12
|
|
13
13
|
Layout/LineLength:
|
14
14
|
Max: 120
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 20
|
15
17
|
|
16
18
|
AllCops:
|
17
19
|
NewCops: enable
|
18
|
-
TargetRubyVersion: 3.0
|
20
|
+
TargetRubyVersion: 3.0
|
21
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
22
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
deb_version (
|
4
|
+
deb_version (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
10
|
json (2.6.3)
|
11
|
+
json (2.6.3-java)
|
11
12
|
minitest (5.18.0)
|
12
13
|
parallel (1.23.0)
|
13
14
|
parser (3.2.2.1)
|
@@ -36,6 +37,10 @@ GEM
|
|
36
37
|
unicode-display_width (2.4.2)
|
37
38
|
|
38
39
|
PLATFORMS
|
40
|
+
universal-java-1.8
|
41
|
+
universal-java-11
|
42
|
+
x86_64-darwin
|
43
|
+
x86_64-darwin-20
|
39
44
|
x86_64-linux
|
40
45
|
|
41
46
|
DEPENDENCIES
|
data/HACKING.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Development
|
2
|
+
|
3
|
+
The all-debian-versions.lst file is a sorted version of the file
|
4
|
+
from https://github.com/FauxFaux/deb-version/blob/42c0e61f62b6776fa1bd77b0da3327fa31dcc1c4/all-debian-versions.lst. The sorting was done using the following script:
|
5
|
+
|
6
|
+
```
|
7
|
+
import sys
|
8
|
+
from functools import cmp_to_key
|
9
|
+
import apt_pkg
|
10
|
+
apt_pkg.init_system()
|
11
|
+
def compare_versions(version1, version2):
|
12
|
+
# Implement your comparison logic here
|
13
|
+
# Return -1 if version1 < version2
|
14
|
+
# Return 0 if version1 == version2
|
15
|
+
# Return 1 if version1 > version2
|
16
|
+
# You can use apt_pkg.version_compare or any other comparison logic
|
17
|
+
|
18
|
+
# Example comparison logic using apt_pkg.version_compare
|
19
|
+
return apt_pkg.version_compare(version1, version2)
|
20
|
+
|
21
|
+
def sort_debian_package_numbers(package_numbers):
|
22
|
+
# Sort the package numbers using cmp_to_key and compare_versions
|
23
|
+
return sorted(package_numbers, key=cmp_to_key(compare_versions))
|
24
|
+
|
25
|
+
if __name__ == "__main__":
|
26
|
+
# Read package numbers from stdin
|
27
|
+
package_numbers = [line.strip() for line in sys.stdin]
|
28
|
+
|
29
|
+
# Sort the package numbers
|
30
|
+
sorted_package_numbers = sort_debian_package_numbers(package_numbers)
|
31
|
+
|
32
|
+
# Write the sorted list to stdout
|
33
|
+
for package_number in sorted_package_numbers:
|
34
|
+
sys.stdout.write(package_number + '\n')
|
35
|
+
```
|
36
|
+
|
37
|
+
Keeping a sorted version in the repository lets us avoid the libapt dependency.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Debian Version
|
1
|
+
# Debian Version (Ruby)
|
2
2
|
|
3
3
|
A port of "Debian Version" comparison function to Ruby. This is based on
|
4
4
|
[Debian Policy Manual v4.6.20, Section 5.6.12](https://www.debian.org/doc/debian-policy/ch-controlfields.html#version).
|
@@ -7,22 +7,20 @@ It adapts some of the code from https://github.com/FauxFaux/deb-version and http
|
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
11
|
-
|
12
10
|
Install the gem and add to the application's Gemfile by executing:
|
13
11
|
|
14
|
-
$ bundle add
|
12
|
+
$ bundle add deb_version
|
15
13
|
|
16
14
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
17
15
|
|
18
|
-
$ gem install
|
16
|
+
$ gem install deb_version
|
19
17
|
|
20
18
|
## Usage
|
21
19
|
|
22
20
|
```ruby
|
23
21
|
require 'deb_version'
|
24
|
-
v1 = DebVersion
|
25
|
-
v2 = DebVersion
|
22
|
+
v1 = DebVersion.new("1.3~rc2")
|
23
|
+
v2 = DebVersion.new("1.3")
|
26
24
|
v1 < v2 # true
|
27
25
|
```
|
28
26
|
|
@@ -32,6 +30,12 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
|
|
32
30
|
|
33
31
|
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).
|
34
32
|
|
33
|
+
Run `bundle exec rake rubocop` to check for style violations.
|
34
|
+
|
35
|
+
Run `bundle exec rake test` to run tests.
|
36
|
+
|
37
|
+
See [HACKING.md](HACKING.md) for further details.
|
38
|
+
|
35
39
|
## Contributing
|
36
40
|
|
37
41
|
Bug reports and pull requests are welcome on GitHub at https://github.com/captn3m0/ruby-deb-version. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/captn3m0/ruby-deb-version/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/deb_version.gemspec
CHANGED
@@ -21,15 +21,16 @@ Gem::Specification.new do |spec|
|
|
21
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
22
|
spec.files = Dir.chdir(__dir__) do
|
23
23
|
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
-
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git all-debian-versions.lst
|
24
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git all-debian-versions.lst
|
25
|
+
test.rb])
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
spec.require_paths = ["lib"]
|
29
30
|
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.18"
|
30
32
|
spec.add_development_dependency "rake", "~> 13.0"
|
31
33
|
spec.add_development_dependency "rubocop", "~> 1.21"
|
32
|
-
spec.add_development_dependency "minitest", "~> 5.18"
|
33
34
|
spec.add_development_dependency "rubocop-minitest", "~> 0.31.0"
|
34
35
|
spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
|
35
36
|
|
data/lib/deb_version/compare.rb
CHANGED
@@ -1,86 +1,106 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# Debian Version comparison class
|
4
|
+
# This is based on the Python deb-pkg-tools implementation
|
5
|
+
# https://github.com/xolox/python-deb-pkg-tools
|
6
|
+
class DebVersion
|
7
|
+
attr_reader :epoch, :upstream_version, :debian_revision
|
6
8
|
|
7
|
-
|
9
|
+
include Comparable
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def initialize(version)
|
12
|
+
@version = version
|
13
|
+
@epoch = 0
|
14
|
+
@debian_revision = ""
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
if @version.include? "-"
|
20
|
-
@upstream_version, _, @debian_revision = @version.rpartition("-")
|
21
|
-
else
|
22
|
-
@upstream_version = @version
|
23
|
-
end
|
16
|
+
if @version.include? ":"
|
17
|
+
@epoch, @version = @version.split(":")
|
18
|
+
@epoch = @epoch.to_i
|
24
19
|
end
|
25
20
|
|
26
|
-
|
27
|
-
|
21
|
+
if @version.include? "-"
|
22
|
+
@upstream_version, _, @debian_revision = @version.rpartition("-")
|
23
|
+
else
|
24
|
+
@upstream_version = @version
|
28
25
|
end
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
# Convert to an array of [epoch, upstream_version, debian_revision]
|
29
|
+
# Helpful for printing and debugging
|
30
|
+
def to_a
|
31
|
+
[@epoch, @upstream_version, @debian_revision]
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
def to_s
|
35
|
+
result = ""
|
36
|
+
result << "#{@epoch}:" if @epoch != 0
|
37
|
+
result << @upstream_version
|
38
|
+
result << "-#{@debian_revision}" unless @debian_revision.empty?
|
39
|
+
result
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
42
|
+
# Internal method to get the largest digit prefix
|
43
|
+
def get_digit_prefix(characters)
|
44
|
+
value = 0
|
45
|
+
value = (value * 10) + characters.shift.to_i while characters && DebVersion::DIGITS.include?(characters[0])
|
46
|
+
value
|
47
|
+
end
|
48
|
+
|
49
|
+
# Internal method to get the largest non-digit prefix
|
50
|
+
def get_non_digit_prefix(characters)
|
51
|
+
prefix = []
|
52
|
+
prefix << characters.shift while characters.size.positive? && !DebVersion::DIGITS.include?(characters[0])
|
53
|
+
prefix
|
54
|
+
end
|
55
|
+
|
56
|
+
# Compare strings as per https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
|
57
|
+
# Section 5.6.12
|
58
|
+
# This is used to compare upstream_version as well as debian_revision
|
59
|
+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
|
60
|
+
def compare_strings(version1, version2)
|
61
|
+
v1 = version1.chars
|
62
|
+
v2 = version2.chars
|
63
|
+
while !v1.empty? || !v2.empty?
|
64
|
+
p1 = get_non_digit_prefix(v1)
|
65
|
+
p2 = get_non_digit_prefix(v2)
|
66
|
+
if p1 != p2
|
67
|
+
loop do
|
68
|
+
c1 = p1.shift
|
69
|
+
c2 = p2.shift
|
70
|
+
break if c1.nil? && c2.nil?
|
71
|
+
|
72
|
+
o1 = DebVersion::ORDER_MAPPING.fetch(c1 || "")
|
73
|
+
o2 = DebVersion::ORDER_MAPPING.fetch(c2 || "")
|
74
|
+
if o1 < o2
|
75
|
+
return -1
|
76
|
+
elsif o1 > o2
|
77
|
+
return 1
|
61
78
|
end
|
62
79
|
end
|
63
|
-
d1 = get_digit_prefix(v1)
|
64
|
-
d2 = get_digit_prefix(v2)
|
65
|
-
if d1 < d2
|
66
|
-
return -1
|
67
|
-
elsif d1 > d2
|
68
|
-
return 1
|
69
|
-
end
|
70
80
|
end
|
71
|
-
|
81
|
+
d1 = get_digit_prefix(v1)
|
82
|
+
d2 = get_digit_prefix(v2)
|
83
|
+
if d1 < d2
|
84
|
+
return -1
|
85
|
+
elsif d1 > d2
|
86
|
+
return 1
|
87
|
+
end
|
72
88
|
end
|
89
|
+
0
|
90
|
+
end
|
91
|
+
# rubocop:enable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
|
73
92
|
|
74
|
-
|
75
|
-
|
93
|
+
# Compare two versions
|
94
|
+
# using all 3 parts
|
95
|
+
def <=>(other)
|
96
|
+
return epoch <=> other.epoch if epoch != other.epoch
|
76
97
|
|
77
|
-
|
98
|
+
result = compare_strings(upstream_version, other.upstream_version)
|
78
99
|
|
79
|
-
|
100
|
+
return result if result != 0
|
80
101
|
|
81
|
-
|
102
|
+
return compare_strings(debian_revision, other.debian_revision) if debian_revision || other.debian_revision
|
82
103
|
|
83
|
-
|
84
|
-
end
|
104
|
+
0
|
85
105
|
end
|
86
106
|
end
|
data/lib/deb_version/version.rb
CHANGED
data/lib/deb_version.rb
CHANGED
@@ -3,20 +3,23 @@
|
|
3
3
|
require_relative "deb_version/version"
|
4
4
|
require_relative "deb_version/compare"
|
5
5
|
|
6
|
-
#
|
7
|
-
|
6
|
+
# Constants for the DebVersion class
|
7
|
+
class DebVersion
|
8
8
|
class Error < StandardError; end
|
9
9
|
# String of ASCII characters which are considered punctuation characters in the C locale:
|
10
10
|
# Except for ~
|
11
11
|
# Already sorted
|
12
12
|
PUNCTUATION = "!\"\#$%&'()*+,-./:;<=>?@[]^_`{|}".chars
|
13
|
-
|
13
|
+
DIGITS = ("0".."9").to_a
|
14
|
+
|
15
|
+
# Sorted list of characters used by Debian Version sort.
|
16
|
+
# see https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
|
17
|
+
SORT_LIST = ["~", ""] + ("A".."Z").to_a + ("a".."z").to_a + PUNCTUATION
|
14
18
|
|
15
19
|
mapping = {}
|
16
20
|
SORT_LIST.each_with_index do |char, index|
|
17
21
|
mapping[char] = index
|
18
22
|
end
|
23
|
+
# Set it to a constant
|
19
24
|
ORDER_MAPPING = mapping
|
20
|
-
|
21
|
-
DIGITS = ("0".."9").to_a
|
22
25
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deb_version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nemo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.18'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.18'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.21'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.21'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- CODE_OF_CONDUCT.md
|
93
93
|
- Gemfile
|
94
94
|
- Gemfile.lock
|
95
|
+
- HACKING.md
|
95
96
|
- LICENSE.txt
|
96
97
|
- README.md
|
97
98
|
- Rakefile
|