norminette 1.0.0.alpha
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.
- checksums.yaml +7 -0
- data/bin/norminette +178 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 591e822ef03b01510e5ed398d8c4aa7604f91878
|
4
|
+
data.tar.gz: da9e80fc570574b3d10b9bafc59e029f059e7513
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70a80c29ed581915cb2fe4b6371c6f880e235a038ba18907a87c8176cdaf791762d56da74cf3fd1d6dc394906513463390d01fc6de1215784628f2605a52b3dd
|
7
|
+
data.tar.gz: 3218a45741f7305e7b6f17beb15e811c9a53935aba0d110ade8dccab2b862753fade6d748c0d31ec2b5794c17ead8b2d6a31fa5e1b1d8a2a666b4707df04d83b
|
data/bin/norminette
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
$current_path = Dir.pwd
|
7
|
+
|
8
|
+
if File.symlink?(__FILE__)
|
9
|
+
dir = File.expand_path(File.dirname(File.expand_path(__FILE__)) + "/" + File.dirname(File.readlink(__FILE__)))
|
10
|
+
Dir.chdir dir
|
11
|
+
else
|
12
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
13
|
+
Dir.chdir dir
|
14
|
+
end
|
15
|
+
|
16
|
+
Bundler.require
|
17
|
+
require 'bunny'
|
18
|
+
require 'facter'
|
19
|
+
require 'json'
|
20
|
+
|
21
|
+
class Sender
|
22
|
+
def initialize &block
|
23
|
+
@conn = Bunny.new hostname: "norminette.42.fr",
|
24
|
+
vhost: "/",
|
25
|
+
user: "guest",
|
26
|
+
password: "guest"
|
27
|
+
|
28
|
+
@conn.start
|
29
|
+
@ch = @conn.create_channel
|
30
|
+
@x = @ch.default_exchange
|
31
|
+
@reply_queue = @ch.queue("", exclusive: true)
|
32
|
+
@lock = Mutex.new
|
33
|
+
@condition = ConditionVariable.new
|
34
|
+
@routing_key = "norminette"
|
35
|
+
@counter = 0
|
36
|
+
|
37
|
+
@reply_queue.subscribe do |delivery_info, properties, payload|
|
38
|
+
@counter -= 1
|
39
|
+
block.call delivery_info, properties, payload
|
40
|
+
@lock.synchronize { @condition.signal }
|
41
|
+
end
|
42
|
+
|
43
|
+
at_exit { desinitialize }
|
44
|
+
end
|
45
|
+
|
46
|
+
def desinitialize
|
47
|
+
@ch.close if @ch
|
48
|
+
@conn.close if @conn
|
49
|
+
end
|
50
|
+
|
51
|
+
def publish content
|
52
|
+
@counter += 1
|
53
|
+
@x.publish content, routing_key: @routing_key,
|
54
|
+
reply_to: @reply_queue.name
|
55
|
+
end
|
56
|
+
|
57
|
+
def sync_if_needed max = Facter.value('processors')['count']
|
58
|
+
@lock.synchronize { @condition.wait(@lock) } if @counter >= max
|
59
|
+
end
|
60
|
+
|
61
|
+
def sync
|
62
|
+
sync_if_needed 0 until @counter == 0
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
class Norminette
|
69
|
+
def initialize
|
70
|
+
@files = []
|
71
|
+
@sender = Sender.new do |delivery_info, properties, payload|
|
72
|
+
manage_result JSON.parse(payload)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def check files_or_directories, options
|
77
|
+
if options.version
|
78
|
+
version
|
79
|
+
else
|
80
|
+
populate_recursive files_or_directories.any? ? files_or_directories : ["."]
|
81
|
+
send_files options
|
82
|
+
end
|
83
|
+
|
84
|
+
@sender.sync
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def populate_recursive objects
|
90
|
+
objects.each do |object|
|
91
|
+
if File.directory? object
|
92
|
+
populate_recursive Dir["#{object}/*"]
|
93
|
+
else
|
94
|
+
populate_file object
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def version
|
100
|
+
puts "Local version:\n1.0.0.alpha"
|
101
|
+
puts "Norminette version:"
|
102
|
+
send_content({action: "version"}.to_json)
|
103
|
+
end
|
104
|
+
|
105
|
+
def file_description file, opts = {}
|
106
|
+
({filename: file, content: File.read(file)}.merge(opts)).to_json
|
107
|
+
end
|
108
|
+
|
109
|
+
def is_a_valid_file? file
|
110
|
+
File.file? file and File.exists? file and file =~ /\.[ch]\z/
|
111
|
+
end
|
112
|
+
|
113
|
+
def populate_file file
|
114
|
+
file = (Pathname.new(file).absolute? ? file : File.join($current_path, file))
|
115
|
+
unless is_a_valid_file? file
|
116
|
+
manage_result 'filename' => file, 'display' => "Warning: Not a valid file"
|
117
|
+
return
|
118
|
+
end
|
119
|
+
|
120
|
+
@files << file
|
121
|
+
end
|
122
|
+
|
123
|
+
def send_files options
|
124
|
+
@files.each do |file|
|
125
|
+
send_file file, options.rules
|
126
|
+
@sender.sync_if_needed
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def send_file file, rules
|
131
|
+
send_content file_description(file, rules: rules)
|
132
|
+
end
|
133
|
+
|
134
|
+
def send_content content
|
135
|
+
@sender.publish content
|
136
|
+
end
|
137
|
+
|
138
|
+
def manage_result result
|
139
|
+
puts "Norme: #{result['filename']}" if result['filename']
|
140
|
+
puts result['display'] if result['display']
|
141
|
+
exit 0 if result['stop'] == true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class Parser
|
146
|
+
def self.parse(options)
|
147
|
+
args = OpenStruct.new
|
148
|
+
opt_parser = OptionParser.new do |opts|
|
149
|
+
opts.banner = "Usage: #$0 [options] [files_or_directories]"
|
150
|
+
|
151
|
+
opts.on("-v", "--version", "Print version") do |n|
|
152
|
+
args.version = true
|
153
|
+
end
|
154
|
+
|
155
|
+
opts.on("-R", "--rules Array", Array, "Rule to disable") do |rules|
|
156
|
+
args.rules = rules
|
157
|
+
end
|
158
|
+
|
159
|
+
opts.on("-h", "--help", "Prints this help") do
|
160
|
+
sender = Sender.new do |delivery_info, properties, payload|
|
161
|
+
puts JSON.parse(payload)['display']
|
162
|
+
end
|
163
|
+
|
164
|
+
puts opts
|
165
|
+
puts "Norminette usage:"
|
166
|
+
sender.publish({action: "help"}.to_json)
|
167
|
+
sender.sync
|
168
|
+
exit
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
opt_parser.parse!(options) rescue abort $!.to_s
|
173
|
+
|
174
|
+
return args
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
Norminette.new.check ARGV, Parser.parse(ARGV)
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: norminette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bocal 42
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bunny
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: facter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A command-line tool to check files follow the 42 norme
|
56
|
+
email:
|
57
|
+
executables:
|
58
|
+
- norminette
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/norminette
|
63
|
+
homepage:
|
64
|
+
licenses: []
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.1
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: A command-line tool to check files follow the 42 norme
|
86
|
+
test_files: []
|