opensecret 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/README.md +2 -2
- data/bin/opensecret +3 -6
- data/lib/opensecret-domain.ini +23 -0
- data/lib/opensecret.rb +30 -2
- data/lib/opensecret/additions/array.rb +117 -0
- data/lib/opensecret/additions/dir.rb +35 -0
- data/lib/opensecret/additions/string.rb +312 -0
- data/lib/opensecret/commons/eco.cmdline.rb +446 -0
- data/lib/opensecret/commons/eco.faculty.rb +364 -0
- data/lib/opensecret/commons/eco.system.rb +437 -0
- data/lib/opensecret/commons/eco.systems.rb +98 -0
- data/lib/opensecret/{safe.rb → delegate.rb} +4 -2
- data/lib/opensecret/eco.do.rb +46 -0
- data/lib/opensecret/executors/crypt.keys/crypt.keys.ini +79 -0
- data/lib/opensecret/executors/crypt.keys/crypt.keys.rb +68 -0
- data/lib/opensecret/executors/decrypt/decrypt.ini +64 -0
- data/lib/opensecret/executors/decrypt/decrypt.rb +49 -0
- data/lib/opensecret/executors/encrypt/encrypt.ini +55 -0
- data/lib/opensecret/executors/encrypt/encrypt.rb +82 -0
- data/lib/opensecret/factbase/hub-runtime.ini +123 -0
- data/lib/opensecret/factbase/known-hosts.ini +75 -0
- data/lib/opensecret/factbase/published.facts/blobbolicious-facts.ini +553 -0
- data/lib/opensecret/factbase/published.facts/credential-facts.ini +40 -0
- data/lib/opensecret/factbase/published.facts/infrastructure-facts.ini +63 -0
- data/lib/opensecret/factbase/readme.md +24 -0
- data/lib/opensecret/factbase/retired.facts/maven.database.ide.facts.ini +127 -0
- data/lib/opensecret/factbase/retired.facts/s3-upload-block-facts.ini +17 -0
- data/lib/opensecret/plugins.io/cipher/crypto.rb +174 -0
- data/lib/opensecret/plugins.io/error/eco.exceptions.rb +24 -0
- data/lib/opensecret/plugins.io/facts/fact.chars.rb +66 -0
- data/lib/opensecret/plugins.io/facts/fact.factor.rb +156 -0
- data/lib/opensecret/plugins.io/facts/fact.locator.rb +105 -0
- data/lib/opensecret/plugins.io/facts/fact.reader.rb +137 -0
- data/lib/opensecret/plugins.io/facts/fact.tree.rb +661 -0
- data/lib/opensecret/plugins.io/file/file.rb +483 -0
- data/lib/opensecret/plugins.io/git/git.flow.rb +388 -0
- data/lib/opensecret/plugins.io/logs/log.object.rb +89 -0
- data/lib/opensecret/plugins.io/logs/logging.rb +203 -0
- data/lib/opensecret/plugins.io/time/time.stamp.rb +425 -0
- data/lib/opensecret/version.rb +2 -2
- data/opensecret.gemspec +8 -13
- metadata +68 -18
@@ -0,0 +1,388 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# -- ------------------------------------------------------------------- -- #
|
4
|
+
# -- Provision the git branch involved in our present working directory. -- #
|
5
|
+
# -- The [present directory] may not relate to version control at all or -- #
|
6
|
+
# -- it may relate to the master or other branch in the source mgt tool. -- #
|
7
|
+
# -- ------------------------------------------------------------------- -- #
|
8
|
+
class GitFlow
|
9
|
+
|
10
|
+
@@url_postfix = ".git/"
|
11
|
+
|
12
|
+
# --
|
13
|
+
# -- Check in whatever has changed in the local repository
|
14
|
+
# -- at the path stated in the first parameter.
|
15
|
+
# --
|
16
|
+
# -- The text in the second parameter helps to distinguish
|
17
|
+
# -- what was to be pushed up and forms part of the git
|
18
|
+
# -- commit message.
|
19
|
+
# --
|
20
|
+
def self.push repo_root_dir, what_changed_string, time_stamp
|
21
|
+
|
22
|
+
dot_git_path = File.join repo_root_dir, ".git"
|
23
|
+
Throw.if_not_exists dot_git_path
|
24
|
+
|
25
|
+
Dir.chdir repo_root_dir
|
26
|
+
|
27
|
+
git_diff_cmd = "git status -vv; echo;"
|
28
|
+
git_diff_output = %x[#{git_diff_cmd}]
|
29
|
+
git_diff_output.log_lines
|
30
|
+
|
31
|
+
git_add_cmd = "git add -A; echo;"
|
32
|
+
git_add_output = %x[#{git_add_cmd}]
|
33
|
+
git_add_output.log_lines
|
34
|
+
|
35
|
+
git_commit_cmd = "git commit -m \"Writing #{what_changed_string} at #{time_stamp}.\";"
|
36
|
+
git_commit_output = %x[#{git_commit_cmd}]
|
37
|
+
git_commit_output.log_lines
|
38
|
+
|
39
|
+
# --
|
40
|
+
# -- This command may require input (username/password) from the
|
41
|
+
# -- user hence we don't wrap inside output trapping executors.
|
42
|
+
# --
|
43
|
+
system "git push origin master"
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# -- ------------------------------------------------- -- #
|
49
|
+
# -- Return the branch name of a local git repository. -- #
|
50
|
+
# -- ------------------------------------------------- -- #
|
51
|
+
# -- Parameter -- #
|
52
|
+
# -- path_to_dot_git : local path to the .git folder -- #
|
53
|
+
# -- -- #
|
54
|
+
# -- Dependencies and Assumptions -- #
|
55
|
+
# -- git is installed on the machine -- #
|
56
|
+
# -- ------------------------------------------------- -- #
|
57
|
+
def self.wc_branch_name path_to_dot_git
|
58
|
+
|
59
|
+
cmd = "git --git-dir=#{path_to_dot_git} branch";
|
60
|
+
branch_names = %x[#{cmd}];
|
61
|
+
branch_names.each_line do |line|
|
62
|
+
return line[2, line.length].strip if line.start_with?('*')
|
63
|
+
end
|
64
|
+
raise ArgumentError.new "No branch name starts with asterix.\n#{cmd}\n#{branch_names}\n"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# -- ------------------------------------------------- -- #
|
70
|
+
# -- Get the remote origin url of a git working copy. -- #
|
71
|
+
# -- ------------------------------------------------- -- #
|
72
|
+
# -- Parameter -- #
|
73
|
+
# -- path_to_dot_git : local path to .git folder -- #
|
74
|
+
# -- -- #
|
75
|
+
# -- Dependencies and Assumptions -- #
|
76
|
+
# -- git is installed on the machine -- #
|
77
|
+
# -- working copy exists and has remote origin -- #
|
78
|
+
# -- ------------------------------------------------- -- #
|
79
|
+
def self.wc_origin_url path_to_dot_git
|
80
|
+
|
81
|
+
cmd = "git --git-dir=#{path_to_dot_git} config --get remote.origin.url"
|
82
|
+
url = %x[#{cmd}];
|
83
|
+
raise ArgumentError.new "No remote origin url.\n#{cmd}\n" if url.nil?
|
84
|
+
|
85
|
+
return url.strip
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# -- -------------------------------------------------- -- #
|
91
|
+
# -- Get the uncut revision of a git repo working copy. -- #
|
92
|
+
# -- -------------------------------------------------- -- #
|
93
|
+
# -- Parameter -- #
|
94
|
+
# -- path_to_dot_git : local path to .git folder -- #
|
95
|
+
# -- -- #
|
96
|
+
# -- Dependencies and Assumptions -- #
|
97
|
+
# -- git is installed on the machine -- #
|
98
|
+
# -- working copy exists and has remote origin -- #
|
99
|
+
# -- -------------------------------------------------- -- #
|
100
|
+
def self.wc_revision_uncut path_to_dot_git
|
101
|
+
|
102
|
+
log.info(ere) { "##### GitFlow path to dot git is => #{path_to_dot_git}" }
|
103
|
+
repo_url = wc_origin_url path_to_dot_git
|
104
|
+
log.info(ere) { "##### The GitFlow repo url is => #{repo_url}" }
|
105
|
+
|
106
|
+
## Bug HERE - On Ubuntu the branch name is like => (HEAD detached at 067f9a3)
|
107
|
+
## Bug HERE - This creates a failure of => sh: 1: Syntax error: "(" unexpected
|
108
|
+
## Bug HERE - The unexpected failure occurs in the ls-remote command below
|
109
|
+
## Bug HERE - So hardcoding this to "master" for now
|
110
|
+
# branch_name = wc_branch_name path_to_dot_git
|
111
|
+
branch_name = "master"
|
112
|
+
|
113
|
+
log.info(ere) { "##### The GitFlow branch name is => #{branch_name}" }
|
114
|
+
cmd = "git ls-remote #{repo_url} ls-remote -b #{branch_name}"
|
115
|
+
log.info(ere) { "##### The GitFlow get dirty rev command is => #{cmd}" }
|
116
|
+
dirty_revision = %x[#{cmd}];
|
117
|
+
log.info(ere) { "##### The dirty revision is => #{dirty_revision}" }
|
118
|
+
return dirty_revision.partition("refs/heads").first.strip;
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
# -- -------------------------------------------------- -- #
|
124
|
+
# -- Get brief revision of repo from working copy path. -- #
|
125
|
+
# -- -------------------------------------------------- -- #
|
126
|
+
# -- Parameter -- #
|
127
|
+
# -- path_to_dot_git : local path to .git folder -- #
|
128
|
+
# -- -- #
|
129
|
+
# -- Dependencies and Assumptions -- #
|
130
|
+
# -- we return the first 7 revision chars -- #
|
131
|
+
# -- git is installed on the machine -- #
|
132
|
+
# -- working copy exists and has remote origin -- #
|
133
|
+
# -- -------------------------------------------------- -- #
|
134
|
+
def self.wc_revision path_to_dot_git
|
135
|
+
|
136
|
+
log.info(ere) { "GitFlow path to dot git is => #{path_to_dot_git}" }
|
137
|
+
Throw.if_not_exists path_to_dot_git
|
138
|
+
|
139
|
+
uncut_revision = wc_revision_uncut path_to_dot_git
|
140
|
+
log.info(ere) { "GitFlow uncut full revision is => #{uncut_revision}" }
|
141
|
+
|
142
|
+
# -- --------------------------------------------------------------------- -- #
|
143
|
+
# -- Gits [short revision] hash has 7 chars. Note 4 is the usable minimum. -- #
|
144
|
+
# -- For usage in stamps where space comes at a premium - 6 chars will do. -- #
|
145
|
+
# -- --------------------------------------------------------------------- -- #
|
146
|
+
ref_length = 7
|
147
|
+
return "r" + uncut_revision[0..(ref_length - 1)];
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# -- -------------------------------------------------- -- #
|
153
|
+
# -- Clone the branch of a local git repo working copy. -- #
|
154
|
+
# -- -------------------------------------------------- -- #
|
155
|
+
# -- Parameter -- #
|
156
|
+
# -- src_gitpath : local path to .git folder -- #
|
157
|
+
# -- new_wc_path : path to new non-existent dir -- #
|
158
|
+
# -- -- #
|
159
|
+
# -- Dependencies and Assumptions -- #
|
160
|
+
# -- git is installed on the machine -- #
|
161
|
+
# -- working copy exists and has remote origin -- #
|
162
|
+
# -- -------------------------------------------------- -- #
|
163
|
+
def self.do_clone_wc path_to_dot_git, path_to_new_dir
|
164
|
+
|
165
|
+
# -- ----------------------------------------------------------- -- #
|
166
|
+
# -- Why clone from a working copy (instead of a remote url). -- #
|
167
|
+
# -- ----------------------------------------------------------- -- #
|
168
|
+
# -- -- #
|
169
|
+
# -- When actively [DEVELOPING] an eco plugin and you want to -- #
|
170
|
+
# -- -- #
|
171
|
+
# -- 1 - [test] the behaviour without a git commit/git push -- #
|
172
|
+
# -- 2 - test whatever [branch] the working copy is now at -- #
|
173
|
+
# -- -- #
|
174
|
+
# -- This use case requires us to clone from a working copy. -- #
|
175
|
+
# -- -- #
|
176
|
+
# -- ----------------------------------------------------------- -- #
|
177
|
+
|
178
|
+
### Bug here - see getting branch name issue
|
179
|
+
### Bug here - see getting branch name issue
|
180
|
+
### Bug here - see getting branch name issue
|
181
|
+
### Bug here - see getting branch name issue
|
182
|
+
### branch_name = wc_branch_name path_to_dot_git
|
183
|
+
branch_name = "master"
|
184
|
+
##### cmd = "git clone #{path_to_dot_git} -b #{branch_name} #{path_to_new_dir}"
|
185
|
+
##### cmd = "git clone #{path_to_dot_git} -b #{branch_name} #{path_to_new_dir}"
|
186
|
+
##### cmd = "git clone #{path_to_dot_git} -b #{branch_name} #{path_to_new_dir}"
|
187
|
+
cmd = "git clone #{path_to_dot_git} #{path_to_new_dir}"
|
188
|
+
clone_output = %x[#{cmd}];
|
189
|
+
|
190
|
+
log.info(ere) { "[gitflow] cloning working copy" }
|
191
|
+
log.info(ere) { "[gitflow] repo branch name : #{branch_name}" }
|
192
|
+
log.info(ere) { "[gitflow] src dot git path : #{path_to_dot_git}" }
|
193
|
+
log.info(ere) { "[gitflow] new wc dir path : #{path_to_new_dir}" }
|
194
|
+
log.info(ere) { "[gitflow] git clone command : #{cmd}" }
|
195
|
+
log.info(ere) { "[gitflow] git clone output : #{clone_output}" }
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
# --
|
201
|
+
# -- Clone a remote repository at the specified [url] into
|
202
|
+
# -- a [NON-EXISTENT] folder path.
|
203
|
+
# --
|
204
|
+
# -- ---------------------------------
|
205
|
+
# -- What is a Non Existent Dir Path?
|
206
|
+
# -- ---------------------------------
|
207
|
+
# --
|
208
|
+
# -- The parent directory of a non existent folder path
|
209
|
+
# -- must [exist] whilst the full path itself does not.
|
210
|
+
# -- The clone operation will create the final folder in
|
211
|
+
# -- the path and then it [puts] the repository contents
|
212
|
+
# -- within it.
|
213
|
+
# --
|
214
|
+
# -- -----------
|
215
|
+
# -- Parameters
|
216
|
+
# -- -----------
|
217
|
+
# --
|
218
|
+
# -- repo_url : url ends in dot git f-slash
|
219
|
+
# -- clone_dir : path to new non-existent dir
|
220
|
+
# --
|
221
|
+
# -- -----------------------------
|
222
|
+
# -- Dependencies and Assumptions
|
223
|
+
# -- -----------------------------
|
224
|
+
# --
|
225
|
+
# -- git is installed on the machine
|
226
|
+
# -- repo exists and is publicly readable
|
227
|
+
# -- the master branch is he one to clone
|
228
|
+
# -- the current Dir.pwd() is writeable
|
229
|
+
# --
|
230
|
+
def self.do_clone_repo repo_url, non_existent_path
|
231
|
+
|
232
|
+
cmd = "git clone #{repo_url} #{non_existent_path}"
|
233
|
+
clone_output = %x[#{cmd}];
|
234
|
+
|
235
|
+
log.info(ere) { "[gitflow] cloning remote repository" }
|
236
|
+
log.info(ere) { "[gitflow] git repository url : #{repo_url}" }
|
237
|
+
log.info(ere) { "[gitflow] git clone dir path : #{nickname non_existent_path}" }
|
238
|
+
log.info(ere) { "[gitflow] git clone command : #{cmd}" }
|
239
|
+
log.info(ere) { "[gitflow] git clone output : #{clone_output}" }
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
# -- ----------------------------------------------------- -- #
|
245
|
+
# -- Clone [many] git repositories given an array of urls -- #
|
246
|
+
# -- along with a corresponding array of the working copy -- #
|
247
|
+
# -- folder names and a [parental] base (offset) folder. -- #
|
248
|
+
# -- ----------------------------------------------------- -- #
|
249
|
+
# -- Parameter -- #
|
250
|
+
# -- repo_urls : array of git repository urls -- #
|
251
|
+
# -- base_names : array of cloned repo base names -- #
|
252
|
+
# -- parent_dir : path to local [parent] folder -- #
|
253
|
+
# -- -- #
|
254
|
+
# -- Dependencies and Assumptions -- #
|
255
|
+
# -- arrays have equiv corresponding entries -- #
|
256
|
+
# -- parent dir is created if not exists -- #
|
257
|
+
# -- repos exist and are publicly readable -- #
|
258
|
+
# -- master branches are the ones to clone -- #
|
259
|
+
# -- ----------------------------------------------------- -- #
|
260
|
+
def self.do_clone_repos repo_urls, base_names, parent_dir
|
261
|
+
|
262
|
+
Dir.mkdir parent_dir unless File.exists? parent_dir
|
263
|
+
Throw.if_not_found parent_dir, "clone repos"
|
264
|
+
|
265
|
+
repo_urls.each_with_index do | repo_url, repo_index |
|
266
|
+
|
267
|
+
git_url = repo_url if repo_url.end_with? @@url_postfix
|
268
|
+
git_url = "#{repo_url}#{@@url_postfix}" unless repo_url.end_with? @@url_postfix
|
269
|
+
|
270
|
+
proj_folder = File.join parent_dir, base_names[repo_index]
|
271
|
+
|
272
|
+
log.info(ere) { "[clone repos] proj [index] => #{repo_index}" }
|
273
|
+
log.info(ere) { "[clone repos] repo url 1st => #{repo_url}" }
|
274
|
+
log.info(ere) { "[clone repos] repo url 2nd => #{git_url}" }
|
275
|
+
log.info(ere) { "[clone repos] project name => #{base_names[repo_index]}" }
|
276
|
+
log.info(ere) { "[clone repos] project path => #{proj_folder}" }
|
277
|
+
|
278
|
+
GitFlow.do_clone_repo git_url, proj_folder
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
# -- ------------------------------------------------ -- #
|
286
|
+
# -- Move assets from a git repo to a local zip file. -- #
|
287
|
+
# -- ------------------------------------------------ -- #
|
288
|
+
# -- -- #
|
289
|
+
# -- Parameter -- #
|
290
|
+
# -- repo_url : the url of the git repository -- #
|
291
|
+
# -- path_offset : FWD-SLASH ENDED PATH in repo -- #
|
292
|
+
# -- target_dir : the target folder for new zip -- #
|
293
|
+
# -- zip_filename : extensionless name of the zip -- #
|
294
|
+
# -- -- #
|
295
|
+
# -- Return -- #
|
296
|
+
# -- path to the zip file created in a tmp folder -- #
|
297
|
+
# -- -- #
|
298
|
+
# -- ------------------------------------------------ -- #
|
299
|
+
# -- Dependencies and Assumptions -- #
|
300
|
+
# -- ------------------------------------------------ -- #
|
301
|
+
# -- -- #
|
302
|
+
# -- END PATH OFFSET WITH A FORWARD SLASH -- #
|
303
|
+
# -- IF NO OFFSET SEND "/" for path_offset -- #
|
304
|
+
# -- git is installed on the machine -- #
|
305
|
+
# -- the repo exists with path offset -- #
|
306
|
+
# -- the master branch is archived -- #
|
307
|
+
# -- name is unique as used to create a dir -- #
|
308
|
+
# -- -- #
|
309
|
+
# -- ------------------------------------------------ -- #
|
310
|
+
def self.git2zip repo_url, path_offset, target_dir, zip_basename
|
311
|
+
|
312
|
+
log.info(ere) { "[git2zip] ------------------------------------------- -- #" }
|
313
|
+
log.info(ere) { "[git2zip] archiving repo assets at path offset -- #" }
|
314
|
+
log.info(ere) { "[git2zip] ------------------------------------------- -- #" }
|
315
|
+
log.info(ere) { "[git2zip] git repository url : #{repo_url}" }
|
316
|
+
log.info(ere) { "[git2zip] slash tail dir offset : #{path_offset}" }
|
317
|
+
log.info(ere) { "[git2zip] target zip directory : #{target_dir}" }
|
318
|
+
log.info(ere) { "[git2zip] zip file [base] name : #{zip_basename}" }
|
319
|
+
|
320
|
+
clone_dir = File.join Dir.tmpdir(), zip_basename
|
321
|
+
do_clone_repo repo_url, clone_dir
|
322
|
+
dot_git_path = File.join clone_dir, ".git"
|
323
|
+
dst_zip_path = File.join target_dir, "#{zip_basename}.zip"
|
324
|
+
|
325
|
+
the_offset = path_offset
|
326
|
+
the_offset = "" if path_offset.length == 1
|
327
|
+
cmd = "git --git-dir=#{dot_git_path} archive -o #{dst_zip_path} HEAD:#{the_offset}"
|
328
|
+
clone_output = %x[#{cmd}];
|
329
|
+
|
330
|
+
log.info(ere) { "[git2zip] tmp clone src folder : #{clone_dir}" }
|
331
|
+
log.info(ere) { "[git2zip] cloned dot git path : #{dot_git_path}" }
|
332
|
+
log.info(ere) { "[git2zip] target zip full path : #{dst_zip_path}" }
|
333
|
+
log.info(ere) { "[git2zip] git archive command : #{cmd}" }
|
334
|
+
log.info(ere) { "[git2zip] ------------------------------------------- -- #" }
|
335
|
+
log.info(ere) { "#{clone_output}" }
|
336
|
+
log.info(ere) { "[git2zip] ------------------------------------------- -- #" }
|
337
|
+
|
338
|
+
return dst_zip_path
|
339
|
+
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
# -- ------------------------------------------------- -- #
|
344
|
+
# -- Return an array of simple file names in the repo. -- #
|
345
|
+
# -- ------------------------------------------------- -- #
|
346
|
+
# -- Parameter -- #
|
347
|
+
# -- repo_url : the url of the repository to read -- #
|
348
|
+
# -- -- #
|
349
|
+
# -- Dependencies and Assumptions -- #
|
350
|
+
# -- we are not interested in folders -- #
|
351
|
+
# -- trawl is recursive (infinite depth) -- #
|
352
|
+
# -- git is installed on the machine -- #
|
353
|
+
# -- ------------------------------------------------- -- #
|
354
|
+
def self.file_names repo_url
|
355
|
+
|
356
|
+
random_text = SecureRandom.urlsafe_base64(12).delete("-_").downcase
|
357
|
+
cloned_name = "eco.repo.clone.#{random_text}"
|
358
|
+
cloned_path = File.join Dir.tmpdir(), cloned_name
|
359
|
+
|
360
|
+
do_clone_repo repo_url, cloned_path
|
361
|
+
dot_git_path = File.join cloned_path, ".git"
|
362
|
+
|
363
|
+
cmd = "git --git-dir=#{dot_git_path} ls-tree -r master --name-only"
|
364
|
+
filename_lines = %x[#{cmd}];
|
365
|
+
names_list = Array.new
|
366
|
+
filename_lines.each_line do |line|
|
367
|
+
names_list.push line.strip
|
368
|
+
end
|
369
|
+
|
370
|
+
log.info(ere) { "[git2files] ----------------------------------------------" }
|
371
|
+
log.info(ere) { "[git2files] [#{names_list.length}] files in [#{repo_url}]" }
|
372
|
+
log.info(ere) { "[git2files] ----------------------------------------------" }
|
373
|
+
log.info(ere) { "[git2files] Random Text : #{random_text}" }
|
374
|
+
log.info(ere) { "[git2files] Cloned Name : #{cloned_name}" }
|
375
|
+
log.info(ere) { "[git2files] Cloned Path : #{cloned_path}" }
|
376
|
+
log.info(ere) { "[git2files] Repo Folder : #{dot_git_path}" }
|
377
|
+
log.info(ere) { "[git2files] Reading Cmd : #{cmd}" }
|
378
|
+
log.info(ere) { "[git2files] ----------------------------------------------" }
|
379
|
+
pp names_list
|
380
|
+
log.info(ere) { "[git2files] ----------------------------------------------" }
|
381
|
+
|
382
|
+
return names_list
|
383
|
+
|
384
|
+
end
|
385
|
+
|
386
|
+
|
387
|
+
end
|
388
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# --
|
4
|
+
# -- Log common objects such as
|
5
|
+
# --
|
6
|
+
# -- - files
|
7
|
+
# -- - maps
|
8
|
+
# --
|
9
|
+
# --
|
10
|
+
class LogObject
|
11
|
+
|
12
|
+
# --
|
13
|
+
# -- Log the file whose full path is given in the 1st parameter.
|
14
|
+
# -- The string context is included in the logs which should explain
|
15
|
+
# -- the whys and wherefores of the file.
|
16
|
+
# --
|
17
|
+
# -- An exception is thrown if the file is not found.
|
18
|
+
# --
|
19
|
+
def self.file file_path, file_context
|
20
|
+
|
21
|
+
Throw.if_not_exists file_path
|
22
|
+
|
23
|
+
log.debug(ere) { "# -- ------------------------------------------------------------------------ #" }
|
24
|
+
log.debug(ere) { "# -- ------------------------------------------------------------------------ #" }
|
25
|
+
log.debug(ere) { "# -- The File Path to Log => #{file_path}" }
|
26
|
+
|
27
|
+
hr_file_size = PrettyPrint.byte_size( File.size(file_path) )
|
28
|
+
dotless_extension = File.extname( file_path )[1..-1]
|
29
|
+
parent_dir_name = File.basename( File.dirname( file_path ) )
|
30
|
+
file_name = File.basename file_path
|
31
|
+
is_zip = dotless_extension.eql? "zip"
|
32
|
+
|
33
|
+
log.debug(ere) { "# -- ------------------------------------------------------------------------ #" }
|
34
|
+
log.debug(ere) { "# -- File Name => #{file_name}" }
|
35
|
+
log.debug(ere) { "# -- File Size => #{hr_file_size}" }
|
36
|
+
log.debug(ere) { "# -- File Type => #{file_context}" }
|
37
|
+
log.debug(ere) { "# -- In Folder => #{parent_dir_name}" }
|
38
|
+
log.debug(ere) { "# -- ------------------------------------------------------------------------ #" }
|
39
|
+
|
40
|
+
log.debug(ere) { "File #{file_name} is a zip (binary) file." } if is_zip
|
41
|
+
return if is_zip
|
42
|
+
|
43
|
+
File.open( file_path, "r") do | file_obj |
|
44
|
+
line_no = 1
|
45
|
+
file_obj.each_line do | file_line |
|
46
|
+
line_num = sprintf '%03d', line_no
|
47
|
+
clean_line = file_line.chomp.strip
|
48
|
+
log.debug(ere) { "# -- [#{line_num}] - #{clean_line}" }
|
49
|
+
line_no += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
log.debug(ere) { "# -- ------------------------------------------------------------------------ #" }
|
54
|
+
log.debug(ere) { "# -- [#{file_context}] End of File [ #{File.basename(file_path)} ]" }
|
55
|
+
log.debug(ere) { "# -- ------------------------------------------------------------------------ #" }
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# --
|
61
|
+
# -- Log map with a key-value pair on each line.
|
62
|
+
# --
|
63
|
+
# -- Parameter
|
64
|
+
# -- the_map : the map to log
|
65
|
+
# --
|
66
|
+
# -- Dependencies and Assumptions
|
67
|
+
# -- the map has been instantiated (not nil)
|
68
|
+
# --
|
69
|
+
def self.map the_map
|
70
|
+
|
71
|
+
return if the_map.nil?
|
72
|
+
|
73
|
+
log.debug(ere) { "# --- ----------------------------------------------" }
|
74
|
+
log.debug(ere) { "# --- Map has [#{the_map.length}] key/value pairs." }
|
75
|
+
log.debug(ere) { "# --- ----------------------------------------------" }
|
76
|
+
|
77
|
+
the_map.each do |the_key, the_value|
|
78
|
+
|
79
|
+
padded_key = sprintf '%-33s', the_key
|
80
|
+
log.debug(ere) { "# --- #{padded_key} => #{the_value}" }
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
log.debug(ere) { "# --- ----------------------------------------------" }
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
end
|