upman-daemon 0.0.3

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.
@@ -0,0 +1,28 @@
1
+ require 'colorize'
2
+
3
+ module Upman
4
+
5
+ module Utils
6
+
7
+ module Helper
8
+
9
+ def info(msg)
10
+
11
+ puts "[#{Process.pid}] [#{Time.now}] " + msg.blue
12
+ end
13
+
14
+ def warn(msg)
15
+ puts "[#{Process.pid}] [#{Time.now}] " + msg.yellow
16
+ end
17
+
18
+ def fail(msg)
19
+ puts "[#{Process.pid}] [#{Time.now}] " + msg.red
20
+ end
21
+
22
+ def success(msg)
23
+ puts "[#{Process.pid}] [#{Time.now}] " + msg.green
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,86 @@
1
+ module Upman
2
+ module Utils
3
+ module Parser
4
+ private
5
+
6
+ def _inject_tags(package, _tags)
7
+ _tags.each do |_tag|
8
+ tag = Tag.where(label: _tag.label).first_or_create
9
+ unless Package.joins(:tags).where('id' => package.id).exists?
10
+ package.tags << tag
11
+ end
12
+ end
13
+ package
14
+ end
15
+
16
+ def _inject_maintainer(package, _maintainer)
17
+ maintainer = Maintainer.where(name: _maintainer.name, email: _maintainer.email).first_or_create
18
+ unless Package.joins(:maintainers).where('id' => package.id).exists?
19
+ package.maintainers << maintainer
20
+ end
21
+ package
22
+ end
23
+
24
+ def _parse_release_file(body)
25
+ release_data = _get_hashed_values(body)
26
+ release_data['architectures'] = release_data['architectures'].gsub(/\s+/m, ' ').strip.split(' ')
27
+ if release_data['components'].present?
28
+ release_data['components'] = release_data['components'].gsub(/\s+/m, ' ').strip.split(' ')
29
+ end
30
+ release_data['date'] = DateTime.parse(release_data['date'])
31
+ release_data
32
+ end
33
+
34
+ def _parse_regex_group(body, regex)
35
+ body.split("\n").each do |line|
36
+ return Regexp.last_match(1) if line =~ regex
37
+ end
38
+ nil
39
+ end
40
+
41
+ def _get_hashed_values(body)
42
+ result = {}
43
+ body.scan(/([\w-]+): (.+)/).each do |match|
44
+ key = match[0].downcase.tr('-', '_')
45
+ result[key] = match[1]
46
+ end
47
+ result
48
+ end
49
+
50
+ def _get_hashed_values_simple(body)
51
+ result = {}
52
+ body.each_line do |line|
53
+ p line.split(':', 2)
54
+ end
55
+ result
56
+ end
57
+
58
+ # Parse something like
59
+ # Maintainer: Debian Games Team <pkg-games-devel@lists.alioth.debian.org>
60
+ def _parse_package_maintainer(body)
61
+ body.split("\n").each do |line|
62
+ if line =~ /^Maintainer: (.*) <(.*)>$/i
63
+ return Maintainer.new(name: Regexp.last_match(1), email: Regexp.last_match(2))
64
+ end
65
+ end
66
+ nil
67
+ end
68
+
69
+ # Parse something like
70
+ # Tag: game::strategy, interface::graphical, interface::x11, role::program,
71
+ # uitoolkit::sdl, uitoolkit::wxwidgets, use::gameplaying,
72
+ # x11::application
73
+ def _parse_package_tags(body)
74
+ result = []
75
+ body.split("\n").each do |line|
76
+ next unless line =~ /^Tag: ([a-z0-9:,\s\n]+)$/i
77
+
78
+ Regexp.last_match(1).strip.split(',').each do |tag|
79
+ result.push(Tag.new(label: tag.strip))
80
+ end
81
+ end
82
+ result
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,25 @@
1
+ module SymbolizeHelper
2
+ extend self
3
+
4
+ def symbolize_recursive(hash)
5
+ {}.tap do |h|
6
+ hash.each { |key, value| h[key.to_sym] = transform(value) }
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def transform(thing)
13
+ case thing
14
+ when Hash; symbolize_recursive(thing)
15
+ when Array; thing.map { |v| transform(v) }
16
+ else; thing
17
+ end
18
+ end
19
+
20
+ refine Hash do
21
+ def deep_symbolize_keys
22
+ SymbolizeHelper.symbolize_recursive(self)
23
+ end
24
+ end
25
+ end
data/lib/upman.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+ require_relative 'version'
4
+
5
+ require_relative 'upman/utils/symbolize_helper'
6
+ require_relative 'upman/utils/helper'
7
+ require_relative 'upman/utils/api'
8
+ require_relative 'upman/utils/files'
9
+ require_relative 'upman/utils/parser'
10
+
11
+ require_relative 'upman/core/daemon'
12
+ require_relative 'upman/core/config'
13
+ require_relative 'upman/core/extension_base'
14
+ require_relative 'upman/core/worker'
15
+
16
+ require_relative 'upman/server/socket'
17
+ require_relative 'upman/server/base_servlet'
18
+
19
+ module Upman
20
+ def self.run!(options)
21
+ Core::Config.load!("config.yml")
22
+ Core::Daemon.new(options).run!
23
+ end
24
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Upman
2
+ class Version
3
+ VERSION = '0.0.3'
4
+ end
5
+ end
data/upman.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ require File.expand_path('lib/version', __dir__)
2
+ require 'date'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'upman-daemon'
6
+ s.version = Upman::Version::VERSION
7
+ s.license = 'GPL-3.0'
8
+ s.date = Date.today.to_s
9
+ s.summary = %q{upman client daemon}
10
+ s.authors = ['Tobias Ehrig']
11
+ s.email = ['tobias.ehrig@hermesworld.com']
12
+ s.files = Dir['{lib,ssl}/**/*'] + ['LICENSE', 'Rakefile', 'README.md']
13
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile upman.gemspec}
14
+ s.extra_rdoc_files = %w(README.md LICENSE)
15
+ s.require_paths = ["lib", "bin"]
16
+ s.bindir = 'bin'
17
+ s.homepage = "https://github.com/liKe2k1/upman"
18
+ s.metadata = {"source_code_uri" => "https://github.com/liKe2k1/upman"}
19
+ s.add_runtime_dependency 'coderay', '>= 1.1.2'
20
+ s.add_runtime_dependency 'colorize', '>= 0.8.1'
21
+ s.add_runtime_dependency 'rest-client', '>= 2.0.2'
22
+ s.executables << 'upman'
23
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: upman-daemon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Ehrig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coderay
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.2
55
+ description:
56
+ email:
57
+ - tobias.ehrig@hermesworld.com
58
+ executables:
59
+ - upman
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - README.md
63
+ - LICENSE
64
+ files:
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - bin/upman
69
+ - lib/upman.rb
70
+ - lib/upman/core/config.rb
71
+ - lib/upman/core/daemon.rb
72
+ - lib/upman/core/extension_base.rb
73
+ - lib/upman/core/worker.rb
74
+ - lib/upman/extensions/get_install_history.rb
75
+ - lib/upman/extensions/get_installed_packages.rb
76
+ - lib/upman/extensions/install_package.rb
77
+ - lib/upman/extensions/ping.rb
78
+ - lib/upman/server/base_servlet.rb
79
+ - lib/upman/server/socket.rb
80
+ - lib/upman/utils/api.rb
81
+ - lib/upman/utils/files.rb
82
+ - lib/upman/utils/helper.rb
83
+ - lib/upman/utils/parser.rb
84
+ - lib/upman/utils/symbolize_helper.rb
85
+ - lib/version.rb
86
+ - upman.gemspec
87
+ homepage: https://github.com/liKe2k1/upman
88
+ licenses:
89
+ - GPL-3.0
90
+ metadata:
91
+ source_code_uri: https://github.com/liKe2k1/upman
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ - bin
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: upman client daemon
112
+ test_files: []