ascii_binder 0.1.11 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53fd1820d7812317c08e7b9f6546b218a6e4f446
4
- data.tar.gz: 43dc2c310ecaadd51d3ff32b63b07a6c63eba03f
3
+ metadata.gz: 9a1c17e7e823c6e76b3bfd18786cc3a4c4d097a2
4
+ data.tar.gz: b667bd45eb3b75101bfceaf998ad90df7980dfa2
5
5
  SHA512:
6
- metadata.gz: 26b8c93816f4b5b0a5b80862448dd18cdc9acb79e464ee7c5655e5cc14c506e5c53c32356bd2e87344d0e390433148ec0f7458733711868d31a9dbce8439a78c
7
- data.tar.gz: a1ea94b2f4dd024146b9809fdb040d7c681bc7ed93bdc22e7a33f9a0c8b056ef4aad254e15e6452398bc8e8abdc1d9ff48e90eb1ad945da28b56f88c8aaa39be
6
+ metadata.gz: 31c88dba1a43101330cab85e0acac0fe26fe50e60d2d8aa814e1ba3cd0e8707180c1259be0ebdc047ea0765c78416c7b9d4236288bb9e664ea2febf3c091b79d
7
+ data.tar.gz: 800c57816abf2fa0d9fb106f9789ed84f6142ef9b52b66d97713bf4c9fc2ffcc4dae5c1c2eaebe394da97f3af18d9c62ea1c79e598e5ff904ee06512e0281c09
@@ -131,6 +131,7 @@ EOF
131
131
  opt :all_branches, "Instead of building only the current working branch, build all branches", :default => false
132
132
  opt :distro, "Instead of building all distros, build branches only for the specified distro.", :default => ''
133
133
  opt :page, "Build only the specified page for all distros and only the current working branch.", :default => ''
134
+ opt :log_level, "Set the logging output level for this operation.", :default => 'warn'
134
135
  conflicts :distro, :page
135
136
  end
136
137
  when "create"
@@ -159,6 +160,7 @@ Options:
159
160
  EOF
160
161
  opt :branches, "Create tracking branches after cloning.", :default => true
161
162
  opt :dir, "Specify the pathname of the local directory for cloning.", :default => ''
163
+ opt :log_level, "Set the logging output level for this operation.", :default => 'warn'
162
164
  end
163
165
  when "watch"
164
166
  Trollop::options do
@@ -185,6 +187,7 @@ Description:
185
187
  new version of the .adoc file, the new HTML is automatically
186
188
  regenerated and your page view is automatically refreshed.
187
189
  EOF
190
+ opt :log_level, "Set the logging output level for this operation.", :default => 'warn'
188
191
  end
189
192
  when "package"
190
193
  Trollop::options do
@@ -202,6 +205,7 @@ Description:
202
205
  Options:
203
206
  EOF
204
207
  opt :site, "Instead of packaging every docs site, package the specified site only.", :default => ''
208
+ opt :log_level, "Set the logging output level for this operation.", :default => 'warn'
205
209
  end
206
210
  when "help"
207
211
  Trollop::educate
@@ -259,6 +263,17 @@ end
259
263
  # Set the repo root
260
264
  set_docs_root_dir(File.expand_path(docs_basedir))
261
265
 
266
+ # Set the log level
267
+ user_log_level = :warn
268
+ unless cmd_opts.nil? or cmd_opts[:log_level].nil?
269
+ user_log_level = cmd_opts[:log_level].to_sym
270
+ unless log_levels.has_key?(user_log_level)
271
+ Trollop::die "log_level value '#{cmd_opts[:log_level]}' is not recognized. Legal values are " + log_levels.keys.map{ |lvl| "'#{lvl.to_s}'" }.join(', ')
272
+ end
273
+ end
274
+ set_log_level(user_log_level)
275
+
276
+
262
277
  # Cloning? Time to try it.
263
278
  if cmd == 'clone'
264
279
  puts "Cloning #{cmd_opts[:giturl]} to #{docs_basedir}"
@@ -10,7 +10,6 @@ require 'asciidoctor-diagram'
10
10
  require 'fileutils'
11
11
  require 'find'
12
12
  require 'git'
13
- require 'logger'
14
13
  require 'pandoc-ruby'
15
14
  require 'pathname'
16
15
  require 'sitemap_generator'
@@ -26,22 +25,6 @@ module AsciiBinder
26
25
  Time.now.utc
27
26
  end
28
27
 
29
- def notice(hey,message,newline = false)
30
- # TODO: (maybe) redirect everything to stderr
31
- if newline
32
- puts "\n"
33
- end
34
- puts "#{hey}: #{message}"
35
- end
36
-
37
- def warning(message,newline = false)
38
- notice("WARNING",message,newline)
39
- end
40
-
41
- def nl_warning(message)
42
- warning(message,true)
43
- end
44
-
45
28
  def git
46
29
  @git ||= Git.open(git_root_dir)
47
30
  end
@@ -57,18 +40,18 @@ module AsciiBinder
57
40
  # See if there are any changes in need of stashing
58
41
  @stash_needed = `cd #{git_root_dir} && git status --porcelain` !~ /^\s*$/
59
42
  if @stash_needed
60
- puts "\nNOTICE: Stashing uncommited changes and files in working branch."
43
+ log_unknown("Stashing uncommited changes and files in working branch.")
61
44
  `cd #{docs_root_dir} && git stash -u`
62
45
  end
63
46
  end
64
47
 
65
48
  def git_apply_and_drop
66
49
  return unless @stash_needed
67
- puts "\nNOTE: Re-applying uncommitted changes and files to working branch."
50
+ log_unknown("Re-applying uncommitted changes and files to working branch.")
68
51
  if system("cd #{docs_root_dir} && git stash pop")
69
- puts "NOTE: Stash application successful."
52
+ log_unknown("Stash application successful.")
70
53
  else
71
- puts "ERROR: Could not apply stashed code. Run `git stash apply` manually."
54
+ log_error("Could not apply stashed code. Run `git stash apply` manually.")
72
55
  end
73
56
  @stash_needed = false
74
57
  end
@@ -105,7 +88,7 @@ module AsciiBinder
105
88
  # Critical error - no topic map file at all.
106
89
  Trollop::die "Could not find any topic map file ('#{TOPIC_MAP_FILENAME}' or '#{BUILD_FILENAME}') at #{docs_root_dir} in branch '#{git.branch}'"
107
90
  end
108
- warning "'#{BUILD_FILENAME}' is a deprecated filename. Rename this to '#{TOPIC_MAP_FILENAME}'."
91
+ log_warn("'#{BUILD_FILENAME}' is a deprecated filename. Rename this to '#{TOPIC_MAP_FILENAME}'.")
109
92
  end
110
93
  topic_file
111
94
  end
@@ -151,10 +134,7 @@ module AsciiBinder
151
134
  next if src_path.split('/').length < 3
152
135
  file_list << src_path
153
136
  end
154
- file_list.map{ |path|
155
- parts = path.split('/').slice(1..-1);
156
- parts.slice(0..-2).join('/') + '/' + parts[-1].split('.')[0]
157
- }
137
+ file_list.map{ |path| File.join(File.dirname(path),File.basename(path,'.adoc')) }
158
138
  end
159
139
 
160
140
  def remove_found_topic_files(branch,branch_topic_map,branch_topic_files)
@@ -166,7 +146,11 @@ module AsciiBinder
166
146
  end
167
147
  end
168
148
  if nonexistent_topics.length > 0
169
- nl_warning "The #{topic_map_file} file on branch '#{branch}' references nonexistent topics:\n" + nonexistent_topics.map{ |topic| "- #{topic}" }.join("\n")
149
+ if AsciiBinder::LOG_LEVEL > log_levels[:debug]
150
+ log_warn("The #{topic_map_file} file on branch '#{branch}' references #{nonexistent_topics.length} nonexistent topics. Set logging to 'debug' for details.")
151
+ else
152
+ log_warn("The #{topic_map_file} file on branch '#{branch}' references nonexistent topics:\n" + nonexistent_topics.map{ |topic| "- #{topic}" }.join("\n"))
153
+ end
170
154
  end
171
155
  end
172
156
 
@@ -277,17 +261,17 @@ module AsciiBinder
277
261
  if not single_page.nil?
278
262
  single_page_path = single_page.split(':')[0].split('/')
279
263
  single_page_path << single_page.split(':')[1]
280
- puts "Rebuilding '#{single_page_path.join('/')}' on branch '#{working_branch}'."
264
+ log_unknown("Rebuilding '#{single_page_path.join('/')}' on branch '#{working_branch}'.")
281
265
  end
282
266
 
283
267
  if not build_distro == ''
284
268
  if not distro_map.include_distro_key?(build_distro)
285
269
  exit
286
270
  else
287
- puts "Building only the #{distro_map.get_distro(build_distro).name} distribution."
271
+ log_unknown("Building only the #{distro_map.get_distro(build_distro).name} distribution.")
288
272
  end
289
273
  elsif single_page.nil?
290
- puts "Building all distributions."
274
+ log_unknown("Building all distributions.")
291
275
  end
292
276
 
293
277
  # Notify the user of missing local branches
@@ -297,11 +281,12 @@ module AsciiBinder
297
281
  missing_branches << dbranch
298
282
  end
299
283
  if missing_branches.length > 0 and single_page.nil?
300
- puts "\nNOTE: The following branches do not exist in your local git repo:"
284
+ message = "The following branches do not exist in your local git repo:\n"
301
285
  missing_branches.each do |mbranch|
302
- puts "- #{mbranch}"
286
+ message << "- #{mbranch}\n"
303
287
  end
304
- puts "The build will proceed but these branches will not be generated."
288
+ message << "The build will proceed but these branches will not be generated."
289
+ log_warn(message)
305
290
  end
306
291
 
307
292
  # Generate all distros for all branches in the indicated branch group
@@ -313,7 +298,7 @@ module AsciiBinder
313
298
  if not local_branch == working_branch
314
299
  if single_page.nil?
315
300
  # Checkout the branch
316
- puts "\nCHANGING TO BRANCH '#{local_branch}'"
301
+ log_unknown("CHANGING TO BRANCH '#{local_branch}'")
317
302
  git_checkout(local_branch)
318
303
  else
319
304
  next
@@ -337,7 +322,11 @@ module AsciiBinder
337
322
  remove_found_topic_files(local_branch,branch_topic_map,branch_orphan_files)
338
323
 
339
324
  if branch_orphan_files.length > 0 and single_page.nil?
340
- nl_warning "Branch '#{local_branch}' includes the following .adoc files that are not referenced in the #{topic_map_file} file:\n" + branch_orphan_files.map{ |file| "- #{file}" }.join("\n")
325
+ if AsciiBinder::LOG_LEVEL > log_levels[:debug]
326
+ log_warn("Branch #{local_branch} includes #{branch_orphan_files.length} files that are not referenced in the #{topic_map_file} file. Set logging to 'debug' for details.")
327
+ else
328
+ log_warn("Branch '#{local_branch}' includes the following .adoc files that are not referenced in the #{topic_map_file} file:\n" + branch_orphan_files.map{ |file| "- #{file}" }.join("\n"))
329
+ end
341
330
  end
342
331
 
343
332
  # Run all distros.
@@ -368,7 +357,7 @@ module AsciiBinder
368
357
  end
369
358
 
370
359
  if first_branch
371
- puts "\nBuilding #{distro.name} for branch '#{local_branch}'"
360
+ log_unknown("Building #{distro.name} for branch '#{local_branch}'")
372
361
  first_branch = false
373
362
  end
374
363
 
@@ -401,7 +390,7 @@ module AsciiBinder
401
390
  # Remove DITAA-generated images
402
391
  ditaa_image_files = Find.find(docs_root_dir).select{ |path| not path.nil? and not (path =~ /_preview/ or path =~ /_package/) and (path =~ /.*\.png$/ or path =~ /.*\.png\.cache$/) and not branch_image_files.include?(path) }
403
392
  if not ditaa_image_files.empty?
404
- puts "\nRemoving ditaa-generated files from repo before changing branches."
393
+ log_unknown("Removing ditaa-generated files from repo before changing branches.")
405
394
  ditaa_image_files.each do |dfile|
406
395
  File.unlink(dfile)
407
396
  end
@@ -419,7 +408,7 @@ module AsciiBinder
419
408
  # If necessary, restore temporarily stashed files
420
409
  git_apply_and_drop
421
410
 
422
- puts "\nAll builds completed."
411
+ log_unknown("All builds completed.")
423
412
  end
424
413
 
425
414
  def process_topic_entity_list(branch_config,single_page_path,navigation,topic_entity_list,preview_path='')
@@ -434,13 +423,17 @@ module AsciiBinder
434
423
  preview_path = topic_entity.preview_path(branch_config.distro.id,branch_config.dir)
435
424
  process_topic_entity_list(branch_config,single_page_path,navigation,topic_entity.subitems,preview_path)
436
425
  elsif topic_entity.is_topic?
437
- if single_page_path.length == 0
438
- puts " - #{topic_entity.repo_path}"
439
- end
440
426
  if topic_entity.is_alias?
441
427
  configure_and_generate_alias(topic_entity,branch_config)
442
428
  else
443
- configure_and_generate_page(topic_entity,branch_config,navigation)
429
+ if File.exists?(topic_entity.source_path)
430
+ if single_page_path.length == 0
431
+ log_info(" - #{topic_entity.repo_path}")
432
+ end
433
+ configure_and_generate_page(topic_entity,branch_config,navigation)
434
+ else
435
+ log_warn(" - #{topic_entity.repo_path} <= Skipping nonexistent file")
436
+ end
444
437
  end
445
438
  end
446
439
  end
@@ -470,7 +463,7 @@ module AsciiBinder
470
463
  "repo_path=#{topic.repo_path}"
471
464
  ])
472
465
 
473
- doc = Asciidoctor.load topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs
466
+ doc = without_warnings { Asciidoctor.load topic_adoc, :header_footer => false, :safe => :unsafe, :attributes => page_attrs }
474
467
  article_title = doc.doctitle || topic.name
475
468
 
476
469
  topic_html = doc.render
@@ -547,7 +540,7 @@ module AsciiBinder
547
540
  end
548
541
  site_dir = File.join(package_dir,site.id)
549
542
  if File.directory?(site_dir)
550
- puts "\nPackaging #{distro_id} for #{site.id} site."
543
+ log_unknown("Packaging #{distro_id} for #{site.id} site.")
551
544
 
552
545
  # Any files in the root of the docs repo with names ending in:
553
546
  # *-#{site}.html
@@ -591,7 +584,7 @@ module AsciiBinder
591
584
 
592
585
  def clean_up
593
586
  if not system("rm -rf #{docs_root_dir}/_preview/* #{docs_root_dir}/_package/*")
594
- puts "Nothing to clean."
587
+ log_unknown("Nothing to clean.")
595
588
  end
596
589
  end
597
590
  end
@@ -1,3 +1,6 @@
1
+ require 'logger'
2
+ require 'stringio'
3
+
1
4
  module AsciiBinder
2
5
  module Helpers
3
6
  BUILD_FILENAME = '_build_cfg.yml'
@@ -51,6 +54,72 @@ module AsciiBinder
51
54
  AsciiBinder::DOCS_ROOT_DIR
52
55
  end
53
56
 
57
+ def set_log_level(user_log_level)
58
+ AsciiBinder.const_set("LOG_LEVEL", log_levels[user_log_level])
59
+ end
60
+
61
+ def log_levels
62
+ @log_levels ||= {
63
+ :debug => Logger::DEBUG.to_i,
64
+ :error => Logger::ERROR.to_i,
65
+ :fatal => Logger::FATAL.to_i,
66
+ :info => Logger::INFO.to_i,
67
+ :warn => Logger::WARN.to_i,
68
+ }
69
+ end
70
+
71
+ def logerr
72
+ @logerr ||= begin
73
+ logger = Logger.new(STDERR, level: AsciiBinder::LOG_LEVEL)
74
+ logger.formatter = proc do |severity, datetime, progname, msg|
75
+ "#{severity}: #{msg}\n"
76
+ end
77
+ logger
78
+ end
79
+ end
80
+
81
+ def logstd
82
+ @logstd ||= begin
83
+ logger = Logger.new(STDOUT, level: AsciiBinder::LOG_LEVEL)
84
+ logger.formatter = proc do |severity, datetime, progname, msg|
85
+ severity == 'ANY' ? "#{msg}\n" : "#{severity}: #{msg}\n"
86
+ end
87
+ logger
88
+ end
89
+ end
90
+
91
+ def log_info(text)
92
+ logstd.info(text)
93
+ end
94
+
95
+ def log_warn(text)
96
+ logstd.warn(text)
97
+ end
98
+
99
+ def log_error(text)
100
+ logerr.error(text)
101
+ end
102
+
103
+ def log_fatal(text)
104
+ logerr.fatal(text)
105
+ end
106
+
107
+ def log_debug(text)
108
+ logstd.debug(text)
109
+ end
110
+
111
+ def log_unknown(text)
112
+ logstd.unknown(text)
113
+ end
114
+
115
+ def without_warnings
116
+ verboseness_level = $VERBOSE
117
+ $VERBOSE = nil
118
+ yield
119
+ ensure
120
+ $VERBOSE = verboseness_level
121
+ end
122
+
54
123
  def template_renderer
55
124
  @template_renderer ||= TemplateRenderer.new(docs_root_dir, template_dir)
56
125
  end
@@ -9,6 +9,7 @@ task :build, :build_distro do |task,args|
9
9
  # Figure out which distros we are building.
10
10
  # A blank value here == all distros
11
11
  set_docs_root_dir(git_root_dir)
12
+ set_log_level(:warn)
12
13
  build_distro = args[:build_distro] || ''
13
14
  generate_docs(:all,build_distro,nil)
14
15
  end
@@ -16,6 +17,7 @@ end
16
17
  desc "Package the documentation"
17
18
  task :package, :package_site do |task,args|
18
19
  set_docs_root_dir(git_root_dir)
20
+ set_log_level(:warn)
19
21
  package_site = args[:package_site] || ''
20
22
  Rake::Task["clean"].invoke
21
23
  Rake::Task["build"].invoke
@@ -25,6 +27,7 @@ end
25
27
  desc "Build the documentation and refresh the page"
26
28
  task :refresh_page, :single_page do |task,args|
27
29
  set_docs_root_dir(git_root_dir)
30
+ set_log_level(:warn)
28
31
  generate_docs(:working_only,'',args[:single_page])
29
32
  end
30
33
 
@@ -1,3 +1,3 @@
1
1
  module AsciiBinder
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ascii_binder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - N. Harrison Ripps
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-26 00:00:00.000000000 Z
12
+ date: 2017-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler