otrs-sopm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78bda8a22d27837f5706a037bc78689de95df4ce
4
+ data.tar.gz: 1029dfe6aeeb0365b907d1d8e718e09e4c096647
5
+ SHA512:
6
+ metadata.gz: d894536784216d54aed4390ba707de4b768c574f28b4e8a5e3679bee93e542b835e8bb9d9a168da19e421f763ecd4e34e1cdc6748f2b71816d5dea669b2a5cdb
7
+ data.tar.gz: bb44d77729b3e1d0d56e4646244f662fe09efcc4eaa8b4062c0f98601de76179685e3244c59173b002d608050ae398cda2f75387736bbfc08dc157b18c19701d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,179 @@
1
+ # Default enabled cops
2
+ # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
3
+
4
+ Metrics/LineLength:
5
+ Description: 'Limit lines to 80 characters.'
6
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
7
+ Enabled: false
8
+
9
+ Style/NegatedIf:
10
+ Description: >-
11
+ Favor unless over if for negative conditions
12
+ (or control flow or).
13
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives'
14
+ Enabled: false
15
+
16
+ Style/IfUnlessModifier:
17
+ Description: >-
18
+ Favor modifier if/unless usage when you have a
19
+ single-line body.
20
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
21
+ Enabled: false
22
+
23
+ Style/TrailingComma:
24
+ Description: 'Checks for trailing comma in parameter lists and literals.'
25
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
26
+ Enabled: false
27
+
28
+ Style/SpaceInsideParens:
29
+ Description: 'No spaces after ( or before ).'
30
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
31
+ Enabled: false
32
+
33
+ Style/SpaceAfterMethodName:
34
+ Description: >-
35
+ Do not put a space between a method name and the opening
36
+ parenthesis in a method definition.
37
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
38
+ Enabled: false
39
+
40
+ Style/SingleSpaceBeforeFirstArg:
41
+ Description: >-
42
+ Checks that exactly one space is used between a method name
43
+ and the first argument for method calls without parentheses.
44
+ Enabled: false
45
+
46
+ Style/LeadingCommentSpace:
47
+ Description: 'Comments should start with a space.'
48
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'
49
+ Enabled: false
50
+
51
+ Style/MethodCallParentheses:
52
+ Description: 'Do not use parentheses for method calls with no arguments.'
53
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
54
+ Enabled: false
55
+
56
+ Style/SpaceInsideBrackets:
57
+ Description: 'No spaces after [ or before ].'
58
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces'
59
+ Enabled: false
60
+
61
+ Style/DefWithParentheses:
62
+ Description: 'Use def with parentheses when there are arguments.'
63
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
64
+ Enabled: false
65
+ Style/MethodDefParentheses:
66
+ Description: >-
67
+ Checks if the method definitions have or don't have
68
+ parentheses.
69
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
70
+ Enabled: false
71
+
72
+ Style/EmptyLinesAroundClassBody:
73
+ Description: "Keeps track of empty lines around class bodies."
74
+ Enabled: false
75
+
76
+ Style/EmptyLinesAroundMethodBody:
77
+ Description: "Keeps track of empty lines around method bodies."
78
+ Enabled: false
79
+
80
+ Style/EmptyLinesAroundBlockBody:
81
+ Description: "Keeps track of empty lines around block bodies."
82
+ Enabled: false
83
+
84
+ Style/EmptyLinesAroundModuleBody:
85
+ Description: "Keeps track of empty lines around module bodies."
86
+ Enabled: false
87
+
88
+ Style/BlockDelimiters:
89
+ Description: >-
90
+ Avoid using {...} for multi-line blocks (multiline chaining is
91
+ always ugly).
92
+ Prefer {...} over do...end for single-line blocks.
93
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
94
+ Enabled: false
95
+
96
+ Style/MultilineBlockChain:
97
+ Description: 'Avoid multi-line chains of blocks.'
98
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
99
+ Enabled: false
100
+
101
+ Metrics/ClassLength:
102
+ Description: 'Avoid classes longer than 100 lines of code.'
103
+ Enabled: false
104
+
105
+ Metrics/MethodLength:
106
+ Description: 'Avoid methods longer than 10 lines of code.'
107
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
108
+ Enabled: false
109
+
110
+ Style/BlockComments:
111
+ Description: 'Do not use block comments.'
112
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-block-comments'
113
+ Enabled: false
114
+
115
+ Style/PerlBackrefs:
116
+ Description: 'Avoid Perl-style regex back references.'
117
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers'
118
+ Enabled: false
119
+
120
+ Style/SelfAssignment:
121
+ Description: >-
122
+ Checks for places where self-assignment shorthand should have
123
+ been used.
124
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment'
125
+ Enabled: false
126
+
127
+ Style/BracesAroundHashParameters:
128
+ Description: 'Enforce braces style around hash parameters.'
129
+ Enabled: false
130
+
131
+ Rails/FindEach:
132
+ Description: 'Prefer all.find_each over all.find.'
133
+ Enabled: false
134
+
135
+ Rails/HasAndBelongsToMany:
136
+ Description: 'Prefer has_many :through to has_and_belongs_to_many.'
137
+ # StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through'
138
+ Enabled: false
139
+
140
+ Style/ClassAndModuleChildren:
141
+ Description: 'Checks style of children classes and modules.'
142
+ Enabled: false
143
+
144
+ Style/FileName:
145
+ Description: 'Use snake_case for source file names.'
146
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
147
+ Enabled: true
148
+ Exclude:
149
+ - 'script/websocket-server.rb'
150
+
151
+
152
+ # 2.0 - feel free :)
153
+
154
+ Metrics/PerceivedComplexity:
155
+ Description: >-
156
+ A complexity metric geared towards measuring complexity for a
157
+ human reader.
158
+ Enabled: false
159
+
160
+ Metrics/AbcSize:
161
+ Description: >-
162
+ A calculated magnitude based on number of assignments,
163
+ branches, and conditions.
164
+ Enabled: false
165
+
166
+ Metrics/CyclomaticComplexity:
167
+ Description: >-
168
+ A complexity metric that is strongly correlated to the number
169
+ of test cases needed to validate a method.
170
+ Enabled: false
171
+
172
+ Metrics/BlockNesting:
173
+ Description: 'Avoid excessive block nesting'
174
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
175
+ Enabled: false
176
+
177
+ Metrics/ModuleLength:
178
+ Description: 'Avoid modules longer than 100 lines of code.'
179
+ Enabled: false
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at te@znuny.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in otrs-sopm.gemspec
4
+ gemspec
5
+
6
+ gem 'nokogiri'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Thorsten Eckel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # OTRS::SOPM
2
+
3
+ This gem provides a class to parse, manipulate and store SOPM files and create OPM strings from them.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'otrs-sopm'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install otrs-sopm
20
+
21
+ ## Usage
22
+
23
+ First create an instance via passing the location to the .sopm file.
24
+
25
+ ```ruby
26
+ sopm = OTRS::SOPM.new 'path/to/Znuny4OTRS-Package.sopm'
27
+ ```
28
+
29
+ ### Create version
30
+
31
+ A new version can be created via passing the wanted version number and a changelog:
32
+
33
+ ```ruby
34
+ sopm_hash_structure = sopm.version('1.0.1', 'Created first bug fix.')
35
+ ```
36
+
37
+ ### Add build information
38
+
39
+ It's recommended to add the build host and build date to the OPM file. Give the build host as a parameter with to add the build information via:
40
+
41
+ ```ruby
42
+ sopm_hash_structure = sopm.add_build_information('http://build.host.tld')
43
+ ```
44
+
45
+ ### Add file
46
+
47
+ To add additional files to the "FileList" structure of the (S)OPM file call this method with the path and an optional permission integer (default is 644):
48
+
49
+ ```ruby
50
+ sopm_hash_structure = sopm.add_file('path/to/File.pm')
51
+
52
+ # equals
53
+
54
+ sopm_hash_structure = sopm.add_file('path/to/File.pm', 664)
55
+ ```
56
+
57
+ ### Store changes
58
+
59
+ In case you want to store the changes you have made to the original SOPM file call this method:
60
+
61
+ ```ruby
62
+ sopm_hash_structure = sopm.store
63
+ ```
64
+
65
+ ### Parse SOPM file
66
+
67
+ In limited cases it might necessary to re-parse the SOPM file again. Do this with:
68
+
69
+ ```ruby
70
+ sopm_hash_structure = sopm.parse
71
+ ```
72
+
73
+ ### Get OPM string
74
+
75
+ After all changes are made you might want to create a OPM file. To receive the OPM XML string with Base64 encoded files call this method:
76
+
77
+ ```ruby
78
+ opm_xml_string = sopm.opm
79
+ ```
80
+
81
+ ## Planned and wanted features
82
+
83
+ Feel free to implement one of those or any other:
84
+
85
+ * Accept filehandle as constructor parameter.
86
+ * Accept SOPM content string as constructor parameter.
87
+ * Write OPM file instead of only returning the string.
88
+ * Manipulate all the other attributes.
89
+ * Create SOPM file from a Hash structure.
90
+
91
+ ## Development
92
+
93
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
94
+
95
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
96
+
97
+ ## Tests
98
+
99
+ The tests are currently in an external project since there is business logic in them. In future releases this tests will be added to this gem repository as it should be.
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/znuny/otrs-sopm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'otrs/sopm'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/otrs/sopm.rb ADDED
@@ -0,0 +1,379 @@
1
+ require 'nokogiri'
2
+ require 'base64'
3
+ require 'otrs/sopm/version'
4
+
5
+ # General OTRS class, for later/other purposes maybe. Should handle more OTRS related stuff
6
+ class OTRS
7
+ # Handles all SOPM and OPM related stuff
8
+ class SOPM
9
+
10
+ attr_reader :sopm
11
+ attr_reader :structure
12
+
13
+ # Creates an instance based on a given SOPM file path.
14
+ #
15
+ # @param sopm_file [String] the path to the SOPM file.
16
+ # @return (see #parse)
17
+ def initialize(sopm_file)
18
+
19
+ @sopm_file = sopm_file
20
+
21
+ sopm_read_handle = File.open(@sopm_file)
22
+ @sopm = Nokogiri::XML(sopm_read_handle)
23
+ sopm_read_handle.close
24
+
25
+ parse
26
+ end
27
+
28
+ # Adds a new version and the changelog to the SOPM file.
29
+ #
30
+ # @param version [String] the version number.
31
+ # @param change_log [String] the changelog.
32
+ # @return (see #parse)
33
+ def version(version, change_log)
34
+
35
+ # change Version
36
+ @sopm.xpath('/otrs_package/Version').children[0].content = version
37
+
38
+ # append ChangeLog
39
+ change_log_nodes = @sopm.xpath('/otrs_package/ChangeLog')
40
+ if change_log_nodes.length == 0
41
+ change_log_nodes = @sopm.xpath('/otrs_package/Framework')
42
+ end
43
+
44
+ # remove tabs from ChangeLog
45
+ change_log.gsub!(/\t/, ' ')
46
+
47
+ # strip whitespaces
48
+ change_log.strip!
49
+
50
+ new_change_log_entry = Nokogiri::XML::Node.new 'ChangeLog', sopm
51
+ new_change_log_entry['Version'] = version
52
+ new_change_log_entry['Date'] = Time.zone.now
53
+ new_change_log_entry.content = change_log
54
+
55
+ change_log_nodes.first.previous = new_change_log_entry.to_xml + "\n "
56
+
57
+ store
58
+ end
59
+
60
+ # Adds the buildhost and builddate to the SOPM file.
61
+ #
62
+ # @param build_host [String] build host on which the OPM file was created.
63
+ # @return (see #parse)
64
+ def add_build_information(build_host)
65
+
66
+ # add BuildHost
67
+ if @sopm.xpath('/otrs_package/BuildHost').children.length == 0
68
+
69
+ new_build_host_entry = Nokogiri::XML::Node.new 'BuildHost', sopm
70
+ new_build_host_entry.content = build_host
71
+ @sopm.xpath('/otrs_package/Filelist').first.previous = new_build_host_entry.to_xml + "\n "
72
+ else
73
+ @sopm.xpath('/otrs_package/BuildHost').children[0].content = build_host
74
+ end
75
+
76
+ # add BuildDate
77
+ if @sopm.xpath('/otrs_package/BuildDate').children.length == 0
78
+
79
+ new_build_date_entry = Nokogiri::XML::Node.new 'BuildDate', sopm
80
+ new_build_date_entry.content = Time.zone.now
81
+ @sopm.xpath('/otrs_package/Filelist').first.previous = new_build_date_entry.to_xml + "\n "
82
+ else
83
+ @sopm.xpath('/otrs_package/BuildDate').children[0].content = Time.zone.now
84
+ end
85
+
86
+ store
87
+ end
88
+
89
+ # Adds a new file to the filelist of the SOPM file.
90
+ #
91
+ # @param location [String] the file location.
92
+ # @param permission [Integer] the permissions with which the files should get created.
93
+ # @return (see #parse)
94
+ def add_file( location, permission = 644 )
95
+
96
+ files_nodes = @sopm.xpath('/otrs_package/Filelist/File')
97
+
98
+ update = true
99
+ files_nodes.each { |files_node|
100
+
101
+ next if files_node['Location'] != location
102
+ next if files_node['Permission'] != permission
103
+
104
+ update = false
105
+
106
+ break
107
+ }
108
+
109
+ return if !update
110
+
111
+ # append Filelist/File
112
+ new_file_entry = Nokogiri::XML::Node.new 'File', sopm
113
+ new_file_entry['Permission'] = permission
114
+ new_file_entry['Location'] = location
115
+
116
+ files_nodes.last.next = "\n " + new_file_entry.to_xml
117
+
118
+ store
119
+ end
120
+
121
+ # Stores the changes to the SOPM file.
122
+ #
123
+ # @return (see #parse)
124
+ def store
125
+
126
+ File.open(@sopm_file, 'w') { |file|
127
+ file.write( @sopm.to_xml )
128
+ }
129
+
130
+ parse
131
+ end
132
+
133
+ # Parses the given SOPM file.
134
+ #
135
+ # @return [Hash] the parsed SOPM structure.
136
+ def parse
137
+
138
+ @structure = {}
139
+
140
+ # Name
141
+ @structure['name'] = @sopm.xpath('/otrs_package/Name').children[0].content
142
+
143
+ # Version
144
+ @structure['version'] = @sopm.xpath('/otrs_package/Version').children[0].content
145
+
146
+ # Vendor
147
+ @structure['vendor'] = @sopm.xpath('/otrs_package/Vendor').children[0].content
148
+
149
+ # License
150
+ @structure['license'] = @sopm.xpath('/otrs_package/License').children[0].content
151
+
152
+ # URL
153
+ # TODO: Remove! URL should be required
154
+ if @sopm.xpath('/otrs_package/URL').children.length > 0
155
+ @structure['url'] = @sopm.xpath('/otrs_package/URL').children[0].content
156
+ end
157
+
158
+ # BuildDate
159
+ if @sopm.xpath('/otrs_package/BuildDate').children.length > 0
160
+ @structure['build_date'] = @sopm.xpath('/otrs_package/BuildDate').children[0].content
161
+ end
162
+
163
+ # BuildHost
164
+ if @sopm.xpath('/otrs_package/BuildHost').children.length > 0
165
+ @structure['build_host'] = @sopm.xpath('/otrs_package/BuildHost').children[0].content
166
+ end
167
+
168
+ # PackageIs* blocks (optional)
169
+ %w(Visible Downloadable Removable).each { |is_type|
170
+
171
+ next if @sopm.xpath('/otrs_package/PackageIs' + is_type).children.length == 0
172
+
173
+ flag = @sopm.xpath('/otrs_package/PackageIs' + is_type).children[0].content
174
+
175
+ is_type.downcase!
176
+
177
+ @structure['package_is_' + is_type] = flag == '1' ? true : false
178
+ }
179
+
180
+ # ChangeLog (optional)
181
+ change_log_nodes = @sopm.xpath('/otrs_package/ChangeLog')
182
+ if change_log_nodes.length > 0
183
+ @structure['change_log'] = []
184
+ change_log_nodes.each { |change_log_node|
185
+
186
+ change_log_entry = {}
187
+ change_log_entry['version'] = change_log_node['Version']
188
+ change_log_entry['date'] = change_log_node['Date']
189
+ change_log_entry['log'] = change_log_node.children[0].content
190
+
191
+ @structure['change_log'].push change_log_entry
192
+ }
193
+ end
194
+
195
+ # OS (optional)
196
+ os_nodes = @sopm.xpath('/otrs_package/OS')
197
+ if os_nodes.length > 0
198
+ @structure['os'] = []
199
+ os_nodes.each { |os_node|
200
+
201
+ @structure['os'].push os_node.children[0].content
202
+ }
203
+ end
204
+
205
+ # Framework
206
+ @structure['framework'] = []
207
+ framework_nodes = @sopm.xpath('/otrs_package/Framework')
208
+ framework_nodes.each { |framework_node|
209
+ @structure['framework'].push framework_node.children[0].content
210
+ }
211
+
212
+ # PackageRequired (optional)
213
+ package_required_nodes = @sopm.xpath('/otrs_package/PackageRequired')
214
+ if package_required_nodes.length > 0
215
+ @structure['package_required'] = []
216
+ package_required_nodes.each { |package_required_node|
217
+
218
+ package_required_entry = {}
219
+ package_required_entry['version'] = package_required_node['Version']
220
+ package_required_entry['name'] = package_required_node.children[0].content
221
+
222
+ @structure['package_required'].push package_required_entry
223
+ }
224
+ end
225
+
226
+ # ModuleRequired (optional)
227
+ module_required_nodes = @sopm.xpath('/otrs_package/ModuleRequired')
228
+ if module_required_nodes.length > 0
229
+ @structure['module_required'] = []
230
+ module_required_nodes.each { |module_required_node|
231
+
232
+ module_required_entry = {}
233
+ module_required_entry['version'] = module_required_node['Version']
234
+ module_required_entry['name'] = module_required_node.children[0].content
235
+
236
+ @structure['module_required'].push module_required_entry
237
+ }
238
+ end
239
+
240
+ # Description
241
+ @structure['description'] = []
242
+ description_nodes = @sopm.xpath('/otrs_package/Description')
243
+ description_nodes.each { |description_node|
244
+
245
+ description_entry = {}
246
+ description_entry['language'] = description_node['Lang']
247
+ description_entry['text'] = description_node.children[0].content
248
+
249
+ @structure['description'].push description_entry
250
+ }
251
+
252
+ # Filelist/File
253
+ @structure['files'] = []
254
+ files_nodes = @sopm.xpath('/otrs_package/Filelist/File')
255
+ files_nodes.each { |files_node|
256
+
257
+ files_entry = {}
258
+ files_entry['permission'] = files_node['Permission']
259
+ files_entry['location'] = files_node['Location']
260
+
261
+ if files_node['Encode'] == 'Base64'
262
+ files_entry['content'] = Base64.decode64( files_node.children[0].content )
263
+ end
264
+
265
+ @structure['files'].push files_entry
266
+ }
267
+
268
+ # Code blocks (optional)
269
+ %w(Install Upgrade Reinstall Uninstall).each { |block_type|
270
+
271
+ code_block_nodes = @sopm.xpath('/otrs_package/Code' + block_type)
272
+
273
+ next if code_block_nodes.length == 0
274
+
275
+ # convert to lowercase
276
+ block_type.downcase!
277
+
278
+ @structure[ 'code_' + block_type ] = []
279
+ code_block_nodes.each { |code_block_node|
280
+
281
+ code_block_entry = {}
282
+ code_block_entry['type'] = code_block_node['Type']
283
+ code_block_entry['code'] = code_block_node.children[0].content
284
+
285
+ # optional
286
+ if code_block_node['Version']
287
+ code_block_entry['version'] = code_block_node['Version']
288
+ end
289
+ if code_block_node['IfPackage']
290
+ code_block_entry['if_package'] = code_block_node['IfPackage']
291
+ end
292
+ if code_block_node['IfNotPackage']
293
+ code_block_entry['if_not_package'] = code_block_node['IfNotPackage']
294
+ end
295
+
296
+ @structure[ 'code_' + block_type ].push code_block_entry
297
+ }
298
+ }
299
+
300
+ # Intro blocks (optional)
301
+ %w(Install Upgrade Reinstall Uninstall).each { |block_type|
302
+
303
+ intro_block_nodes = @sopm.xpath('/otrs_package/Intro' + block_type)
304
+
305
+ next if intro_block_nodes.length == 0
306
+
307
+ # convert to lowercase
308
+ block_type.downcase!
309
+
310
+ @structure[ 'code_' + block_type ] = []
311
+ intro_block_nodes.each { |intro_block_node|
312
+
313
+ intro_block_entry = {}
314
+ intro_block_entry['type'] = intro_block_node['Type']
315
+ intro_block_entry['intro'] = intro_block_node.children[0].content
316
+
317
+ # optional
318
+ if intro_block_node['Version']
319
+ intro_block_entry['version'] = intro_block_node['Version']
320
+ end
321
+ if intro_block_node['Lang']
322
+ intro_block_entry['language'] = intro_block_node['Lang']
323
+ end
324
+ if intro_block_node['Title']
325
+ intro_block_entry['title'] = intro_block_node['Title']
326
+ end
327
+ if intro_block_node['Format']
328
+ intro_block_entry['format'] = intro_block_node['Format']
329
+ end
330
+
331
+ @structure[ 'code_' + block_type ].push intro_block_entry
332
+ }
333
+ }
334
+
335
+ # Database blocks (optional)
336
+ %w(Install Upgrade Reinstall Uninstall).each { |block_type|
337
+
338
+ intro_block_nodes = @sopm.xpath('/otrs_package/Database' + block_type)
339
+
340
+ next if intro_block_nodes.length == 0
341
+
342
+ # convert to lowercase
343
+ block_type.downcase!
344
+
345
+ @structure[ 'database_' + block_type ] = []
346
+ intro_block_nodes.each { |intro_block_node|
347
+
348
+ @structure[ 'database_' + block_type ].push intro_block_node.children[0].content
349
+ }
350
+ }
351
+
352
+ @structure
353
+ end
354
+
355
+ # Creates an OPM string out of the SOPM file.
356
+ #
357
+ # @return [String] OPM XML content with Base64 encoded files.
358
+ def opm
359
+
360
+ opm = @sopm
361
+
362
+ folder = File.dirname(@sopm_file)
363
+
364
+ files_nodes = opm.xpath('/otrs_package/Filelist/File')
365
+ files_nodes.each { |files_node|
366
+
367
+ file_location = files_node['Location']
368
+ file = File.open("#{folder}/#{file_location}", 'r')
369
+ file_content = file.read
370
+ file.close
371
+
372
+ files_node['Encode'] = 'Base64'
373
+ files_node.content = Base64.strict_encode64( file_content )
374
+ }
375
+
376
+ opm.to_xml
377
+ end
378
+ end
379
+ end
@@ -0,0 +1,7 @@
1
+ # General OTRS class, for later/other purposes maybe. Should handle more OTRS related stuff
2
+ class OTRS
3
+ # Contains just the version number, bundler / gem default design
4
+ class SOPM
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
data/otrs-sopm.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'otrs/sopm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'otrs-sopm'
8
+ spec.version = OTRS::SOPM::VERSION
9
+ spec.authors = ['Thorsten Eckel']
10
+ spec.email = ['thorsten.eckel@znuny.com']
11
+
12
+ spec.summary = 'This gem provides a class to parse, manipulate and store SOPM files and create OPM strings from them.'
13
+ spec.homepage = 'https://github.com/znuny/otrs-sopm'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.11'
20
+ spec.add_development_dependency 'rake', '~> 10.0'
21
+ spec.add_development_dependency 'rubocop'
22
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: otrs-sopm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thorsten Eckel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - thorsten.eckel@znuny.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/otrs/sopm.rb
72
+ - lib/otrs/sopm/version.rb
73
+ - otrs-sopm.gemspec
74
+ homepage: https://github.com/znuny/otrs-sopm
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.8
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This gem provides a class to parse, manipulate and store SOPM files and create
98
+ OPM strings from them.
99
+ test_files: []