stepmod-utils 0.1.7 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +42 -0
  3. data/.github/workflows/release.yml +23 -20
  4. data/Gemfile +2 -0
  5. data/Makefile +5 -0
  6. data/README.adoc +136 -2
  7. data/exe/stepmod-annotate-all +39 -0
  8. data/exe/stepmod-build-resource-docs-cache +19 -0
  9. data/exe/stepmod-convert-express-description +33 -0
  10. data/exe/stepmod-convert-express-resource +33 -0
  11. data/exe/stepmod-extract-terms +56 -13
  12. data/exe/stepmod-find-express-files +23 -0
  13. data/lib/stepmod/utils/cleaner.rb +11 -0
  14. data/lib/stepmod/utils/concept.rb +16 -3
  15. data/lib/stepmod/utils/converters/a.rb +47 -0
  16. data/lib/stepmod/utils/converters/blockquote.rb +22 -0
  17. data/lib/stepmod/utils/converters/br.rb +15 -0
  18. data/lib/stepmod/utils/converters/bypass.rb +81 -0
  19. data/lib/stepmod/utils/converters/code.rb +19 -0
  20. data/lib/stepmod/utils/converters/comment.rb +16 -0
  21. data/lib/stepmod/utils/converters/dd.rb +15 -0
  22. data/lib/stepmod/utils/converters/def.rb +11 -4
  23. data/lib/stepmod/utils/converters/dl.rb +31 -0
  24. data/lib/stepmod/utils/converters/drop.rb +22 -0
  25. data/lib/stepmod/utils/converters/dt.rb +17 -0
  26. data/lib/stepmod/utils/converters/em_express_description.rb +22 -0
  27. data/lib/stepmod/utils/converters/eqn.rb +97 -0
  28. data/lib/stepmod/utils/converters/example.rb +1 -6
  29. data/lib/stepmod/utils/converters/express_g.rb +49 -0
  30. data/lib/stepmod/utils/converters/express_ref_express_description.rb +13 -0
  31. data/lib/stepmod/utils/converters/ext_description.rb +17 -0
  32. data/lib/stepmod/utils/converters/ext_descriptions.rb +14 -0
  33. data/lib/stepmod/utils/converters/fund_cons.rb +21 -0
  34. data/lib/stepmod/utils/converters/head.rb +22 -0
  35. data/lib/stepmod/utils/converters/hr.rb +15 -0
  36. data/lib/stepmod/utils/converters/ignore.rb +16 -0
  37. data/lib/stepmod/utils/converters/introduction.rb +15 -0
  38. data/lib/stepmod/utils/converters/note.rb +1 -6
  39. data/lib/stepmod/utils/converters/ol.rb +3 -2
  40. data/lib/stepmod/utils/converters/p.rb +21 -0
  41. data/lib/stepmod/utils/converters/pass_through.rb +13 -0
  42. data/lib/stepmod/utils/converters/q.rb +16 -0
  43. data/lib/stepmod/utils/converters/resource.rb +14 -0
  44. data/lib/stepmod/utils/converters/schema.rb +19 -0
  45. data/lib/stepmod/utils/converters/schema_diag.rb +14 -0
  46. data/lib/stepmod/utils/converters/strong.rb +41 -0
  47. data/lib/stepmod/utils/converters/sub.rb +24 -0
  48. data/lib/stepmod/utils/converters/sup.rb +22 -0
  49. data/lib/stepmod/utils/converters/table.rb +62 -0
  50. data/lib/stepmod/utils/converters/text.rb +68 -0
  51. data/lib/stepmod/utils/html_to_asciimath.rb +157 -0
  52. data/lib/stepmod/utils/smrl_description_converter.rb +49 -0
  53. data/lib/stepmod/utils/smrl_resource_converter.rb +67 -0
  54. data/lib/stepmod/utils/stepmod_file_annotator.rb +78 -0
  55. data/lib/stepmod/utils/version.rb +1 -1
  56. data/migrating_from_cvs.adoc +190 -0
  57. data/stepmod-utils.gemspec +2 -0
  58. metadata +84 -9
  59. data/.github/workflows/macos.yml +0 -39
  60. data/.github/workflows/ubuntu.yml +0 -53
  61. data/.github/workflows/windows.yml +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0234a977f2b4fe70773fb53f5a213858c45b217a127ac34d6497adee7bbc1324
4
- data.tar.gz: 8d9c942f9c36ddca312712fcf4eae5f25b9c3080685d8d559bc19ac059e7c7a9
3
+ metadata.gz: 7d3544c6e6b2eca6cab5ab08050b9985b80f62d597604d6961cbb388a712160a
4
+ data.tar.gz: 6afde6fbd52b996a37a6d8bc88607adf97b760c0835d7eae5cee849a8911d8cb
5
5
  SHA512:
6
- metadata.gz: bacc43cbc1ae0631ddac9e06c08f9ad61e5447acbeb4d55ee46a91203a363073efc96bf207c3c64ea04b4f0108726ff064a8a1e093620c40cd4f5da85d255624
7
- data.tar.gz: 6bc94140c41c77370ba94048539fe2eae93cfa760272a3b36af97c40cfac233ec32d55425102ea75a92693a8058e0224e9fdebbe4eee910b45d33e6cfc295860
6
+ metadata.gz: c5631d5e7587e4d26d62425f623433147ad372f4f53ebc5d9f2e0c1414d0b84599b6655d242028fbc4df872637b2db2a23df31b905ddd48136a9add7de4d0a9b
7
+ data.tar.gz: d48868104b0fd44e74ec8459f9d45e1ed51b835b749bc3986c185c376d798ecb28da0d2a1813ebeb9faacc9e1432a0117adaa5101ade901e965424a101903bcc
@@ -0,0 +1,42 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
+ runs-on: ${{ matrix.os }}
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.7', '2.6', '2.5', '2.4' ]
20
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
21
+ experimental: [ false ]
22
+ include:
23
+ - ruby: '3.0'
24
+ os: 'ubuntu-latest'
25
+ experimental: true
26
+ - ruby: '3.0'
27
+ os: 'windows-latest'
28
+ experimental: true
29
+ - ruby: '3.0'
30
+ os: 'macos-latest'
31
+ experimental: true
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ with:
35
+ submodules: true
36
+
37
+ - uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ bundler-cache: true
41
+
42
+ - run: bundle exec rake
@@ -1,41 +1,44 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  name: release
2
4
 
3
5
  on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'patch'
4
13
  push:
5
- tags:
6
- - '*'
14
+ tags: [ v* ]
7
15
 
8
16
  jobs:
9
17
  release:
10
- runs-on: ubuntu-18.04
18
+ runs-on: ubuntu-latest
11
19
  steps:
12
- - uses: actions/checkout@v1
13
- - name: Use Ruby
14
- uses: actions/setup-ruby@v1
20
+ - uses: actions/checkout@v2
21
+
22
+ - uses: ruby/setup-ruby@v1
15
23
  with:
16
24
  ruby-version: '2.6'
17
- architecture: 'x64'
18
- - name: Update gems
19
- run: |
20
- gem install bundler
21
- bundle install --jobs 4 --retry 3
22
- - name: Update stepmod-utils.jar
23
- run: |
24
- rm -f bin/stepmod-utils.jar
25
- rake bin/stepmod-utils.jar
26
- - name: Run specs
25
+
26
+ - run: gem install gem-release
27
+
28
+ - if: ${{ github.event_name == 'workflow_dispatch' }}
27
29
  run: |
28
- bundle exec rake
29
- - name: Publish to rubygems.org
30
+ git config user.name github-actions
31
+ git config user.email github-actions@github.com
32
+ gem bump --version ${{ github.event.inputs.next_version }} --tag --push
33
+
34
+ - name: publish to rubygems.org
30
35
  env:
31
36
  RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
32
37
  run: |
33
38
  gem install gem-release
34
- touch ~/.gem/credentials
35
39
  cat > ~/.gem/credentials << EOF
36
40
  ---
37
41
  :rubygems_api_key: ${RUBYGEMS_API_KEY}
38
42
  EOF
39
43
  chmod 0600 ~/.gem/credentials
40
- git status
41
44
  gem release
data/Gemfile CHANGED
@@ -7,3 +7,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
7
 
8
8
  gem "rake", "~> 12.0"
9
9
  gem "rspec", "~> 3.0"
10
+ gem "pry"
11
+ gem "concurrent-ruby", "~> 1.1"
data/Makefile ADDED
@@ -0,0 +1,5 @@
1
+ convert_stepmod_repo:
2
+ bundle exec ./exe/stepmod-annotate-all $(10303_stepmod_path)
3
+
4
+ create_svgs:
5
+ java -jar $(stepmod2mn_jar_path) $(10303_stepmod_path) -svg
data/README.adoc CHANGED
@@ -1,4 +1,4 @@
1
- = stepmod-utils Ruby gem
1
+ = STEPmod utilities
2
2
 
3
3
  image:https://img.shields.io/gem/v/metanorma.svg["Gem Version", link="https://rubygems.org/gems/metanorma"]
4
4
  image:https://github.com/metanorma/stepmod-utils/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/metanorma/stepmod-utils/actions?query=workflow%3Aubuntu"]
@@ -10,7 +10,13 @@ image:https://img.shields.io/github/commits-since/metanorma/stepmod-utils/latest
10
10
 
11
11
  == Purpose
12
12
 
13
- The stepmod-utils Ruby gem provides a number of tools to work with the STEPmod repository/
13
+ The `stepmod-utils` Ruby gem provides a number of tools to work with the STEPmod repository.
14
+
15
+
16
+ == CVS to Git migration procedures
17
+
18
+ include::migrating_from_cvs.adoc[]
19
+
14
20
 
15
21
  == Installation
16
22
 
@@ -37,4 +43,132 @@ Then these files will be created:
37
43
  * `031-generated-terms.adoc` all terms extracted
38
44
  * `991-generated-bibliography.adoc` all bibliographic sources where the terms come from
39
45
 
46
+ == Conversion of STEPmod descriptions.xml into adoc
47
+
48
+ [source,sh]
49
+ ----
50
+ $ stepmod-convert-express-description /path/to/the/stepmod/descriptions.xml
51
+ ----
52
+
53
+ Example output:
54
+ [source,adoc]
55
+ -----
56
+ (*"application_context_schema"
57
+
58
+ *)
59
+ (*"application_context_schema.exchange_identification_context_select"
60
+ The *exchange\_identification\_context\_select* type allows for the designation of the data types express_ref:[management_resources_schema:ir_express:management_resources_schema.identification_assignment] and express_ref:[person_organization_schema:ir_express:person_organization_schema.organization] .
61
+ *)
62
+ (*"application_context_schema.application_context"
63
+ An *application\_context*, as defined in ISO 10303-1, is a context in which product data is defined and has meaning. An *application\_context* represents various types of information that relate to product data and may affect the meaning and usage of that data.
64
+ *)
65
+ (*"application_context_schema.application_context.application"
66
+
67
+ the express_ref:[support_resource_schema:ir_express:support_resource_schema.label] by which the *application\_context* is known.
68
+
69
+ [NOTE]
70
+ --
71
+ The meaning of this attribute can be defined in the annotated EXPRESS schemas that use or specialize this entity, or in an agreement of common understanding between the partners sharing this information.
72
+ --
73
+
74
+ *)
75
+ -----
76
+
77
+
78
+ == Conversion of STEPmod resource.xml into adoc
79
+
80
+ Given resource.xml file contents:
81
+
82
+ [source,xml]
83
+ ----
84
+ <schema name="contract_schema" number="8369" version="3">
85
+ <introduction>
86
+ The subject of the <b>contract_schema</b> is the description of contract agreements.
87
+ </introduction>
88
+ <fund_cons>
89
+ Contract information may be attached to any aspect of a product data.
90
+ </fund_cons>
91
+ <express-g>
92
+ <imgfile file="contract_schemaexpg1.xml"/>
93
+ <imgfile file="contract_schemaexpg2.xml"/>
94
+ </express-g>
95
+ </schema>
96
+ ----
97
+
98
+ Command:
99
+
100
+ [source,sh]
101
+ ----
102
+ $ stepmod-convert-express-resource resource.xml
103
+ ----
104
+
105
+ Will give output:
106
+
107
+ [source,adoc]
108
+ ----
109
+ == Introduction
110
+
111
+ The subject of the *contract_schema* is the description of contract agreements.
112
+
113
+ == Fundamental concerns
114
+
115
+ Contract information may be attached to any aspect of a product data.
116
+
117
+ expg_image:contract_schemaexpg1.xml[]
118
+ expg_image:contract_schemaexpg2.xml[]
119
+ ----
120
+
121
+
122
+ == CVS revision detection
123
+
124
+ If the STEPmod repository is a CVS repository, it will display the
125
+ working and repository revisions as comments.
126
+
127
+ WARNING: CVS revision detection can be *slow*! Be patient.
128
+
129
+ Sample output:
130
+
131
+ [source,sh]
132
+ ----
133
+ [stepmod-utils] INFO: STEPmod directory set to ../x/stepmod/.
134
+ [stepmod-utils] INFO: STEPmod directory is a CVS repository and will detect revisions.
135
+ [stepmod-utils] INFO: [CVS] Detecting file revisions can be slow, please be patient!
136
+ [stepmod-utils] INFO: Detecting paths...
137
+ [stepmod-utils] INFO: Processing XML file data/business_object_models/managed_model_based_3d_engineering/business_object_model.xml
138
+ [stepmod-utils] INFO: Detecting CVS revision...
139
+ [stepmod-utils] INFO: CVS working rev (1.148), repo rev (1.148)
140
+ [stepmod-utils] INFO: Completed processing XML file data/business_object_models/managed_model_based_3d_engineering/business_object_model.xml
141
+ [stepmod-utils] INFO: Processing XML file data/business_object_models/managed_model_based_3d_engineering_domain/business_object_model.xml
142
+ [stepmod-utils] INFO: Detecting CVS revision...
143
+ [stepmod-utils] INFO: CVS working rev (1.31), repo rev (1.31)
144
+ [stepmod-utils] INFO: Completed processing XML file data/business_object_models/managed_model_based_3d_engineering_domain/business_object_model.xml
145
+ ...
146
+ stepmod/data/business_object_models/managed_model_based_3d_engineering_domain/business_object_model.xml
147
+ [stepmod-utils] INFO: written to: 031-generated-terms.adoc
148
+ [stepmod-utils] INFO: written to: 991-generated-bibliography.adoc
149
+ ----
150
+
151
+
152
+ == Non-CVS repository
153
+
154
+ If the STEPmod repository is not a CVS repository, or if the `cvs` executable
155
+ cannot be found, term extract will still work.
156
+
157
+ Sample output:
158
+
159
+ [source,sh]
160
+ ----
161
+ [stepmod-utils] INFO: STEPmod directory set to ../iso-10303-stepmod.
162
+ [stepmod-utils] INFO: STEPmod directory is not a CVS repository, skipping revision detection.
163
+ [stepmod-utils] INFO: Detecting paths...
164
+ [stepmod-utils] INFO: Processing XML file data/application_protocols/boundary_representation_for_iso_14306_open_jt/application_protocol.xml
165
+ [stepmod-utils] INFO: skipped ISO/CD 10303-243 as it is not IS, DIS or TS
166
+ [stepmod-utils] INFO: Processing XML file data/application_protocols/configuration_control_3d_design_ed2/application_protocol.xml
167
+ [stepmod-utils] INFO: Completed processing XML file data/application_protocols/configuration_control_3d_design_ed2/application_protocol.xml
168
+ [stepmod-utils] INFO: Processing XML file data/application_protocols/electronic_assembly_interconnect_and_packaging_design/application_protocol.xml
169
+ [stepmod-utils] INFO: skipped ISO/CD 10303-210:2019 as it is not IS, DIS or TS
170
+ [stepmod-utils] INFO: Processing XML file data/application_protocols/functional_data_and_their_schematic_representation_for_process_plant/application_protocol.xml
171
+ [stepmod-utils] INFO: Completed processing XML file data/application_protocols/functional_data_and_their_schematic_representation_for_process_plant/application_protocol.xml
172
+ ...
173
+ ----
40
174
 
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'concurrent'
4
+ require 'stepmod/utils/stepmod_file_annotator'
5
+
6
+ stepmod_dir = ARGV.first || Dir.pwd
7
+
8
+ # build resource_docs cache
9
+ resource_docs_cache_file = `mktemp`
10
+ `"#{File.join(__dir__, 'stepmod-build-resource-docs-cache')}" "#{stepmod_dir}" > "#{resource_docs_cache_file}"`
11
+
12
+ # annotate each file
13
+ files = `"#{File.join(__dir__, 'stepmod-find-express-files')}" "#{stepmod_dir}"`.strip.split("\n")
14
+ MAX_THREADS = [2, Concurrent.processor_count].max * 2
15
+ MAX_QUEUE_SIZE = MAX_THREADS * 4
16
+ # https://github.com/ruby-concurrency/concurrent-ruby/blob/master/docs-source/thread_pools.md
17
+ pool = Concurrent::ThreadPoolExecutor.new(
18
+ :min_threads => MAX_THREADS,
19
+ :max_threads => MAX_THREADS,
20
+ :max_queue => MAX_QUEUE_SIZE,
21
+ :fallback_policy => :caller_runs
22
+ )
23
+ files.each_slice(MAX_QUEUE_SIZE) do |batch|
24
+ puts("Queueing next batch")
25
+ batch.each do |file|
26
+ pool.post do
27
+ puts("#{Thread.current.object_id}: Queued processing #{file}")
28
+ annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file, resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call
29
+ File.open(File.join(File.dirname(file), "#{File.basename(file, '.exp')}_annotated.exp"), 'w') do |file|
30
+ file.puts(annotated)
31
+ end
32
+ puts("#{Thread.current.object_id}: Done processing #{file}")
33
+ end
34
+ end
35
+ pool.shutdown
36
+ end
37
+
38
+ # cleanup
39
+ `rm "#{resource_docs_cache_file}"`
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nokogiri'
4
+ require 'json'
5
+
6
+ stepmod_dir = ARGV.first || Dir.pwd
7
+
8
+ schemas = {}
9
+ Dir.glob(File.join(stepmod_dir, 'data/resource_docs/*/resource.xml')).each do |resource_docs_file|
10
+ match = resource_docs_file.match('data/resource_docs/([^/]+)/resource.xml')
11
+ resource_docs_dir = match.captures[0]
12
+
13
+ resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
14
+ resource_docs.xpath('schema').each do |schema|
15
+ schemas[schema['name']] = resource_docs_dir
16
+ end
17
+ end
18
+
19
+ puts JSON.pretty_generate(schemas)
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ class Gem::Specification
15
+ def this; self; end
16
+ end
17
+
18
+ require 'bundler/setup'
19
+ require 'stepmod/utils/smrl_description_converter'
20
+
21
+ ReverseAdoc.config.unknown_tags = :bypass
22
+
23
+ input_content = ARGF.read
24
+
25
+ result = Stepmod::Utils::SmrlDescriptionConverter.convert(input_content, {})
26
+ result.split("\n").each do |line|
27
+ begin
28
+ $stdout.puts(line)
29
+ $stdout.flush
30
+ rescue Errno::EPIPE
31
+ exit(74)
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ class Gem::Specification
15
+ def this; self; end
16
+ end
17
+
18
+ require 'bundler/setup'
19
+ require 'stepmod/utils/smrl_resource_converter'
20
+
21
+ ReverseAdoc.config.unknown_tags = :bypass
22
+
23
+ input_content = ARGF.read
24
+
25
+ result = Stepmod::Utils::SmrlResourceConverter.convert(input_content, {})
26
+ result.split("\n").each do |line|
27
+ begin
28
+ $stdout.puts(line)
29
+ $stdout.flush
30
+ rescue Errno::EPIPE
31
+ exit(74)
32
+ end
33
+ end
@@ -1,8 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  #!/usr/bin/env ruby
4
2
  # encoding: UTF-8
5
3
 
4
+ require 'pry'
6
5
  # resolve bin path, ignoring symlinks
7
6
  require "pathname"
8
7
  bin_file = Pathname.new(__FILE__).realpath
@@ -21,6 +20,7 @@ require 'bundler/setup'
21
20
  require 'stepmod/utils/stepmod_definition_converter'
22
21
  require 'stepmod/utils/bibdata'
23
22
  require 'stepmod/utils/concept'
23
+ require 'ptools'
24
24
 
25
25
  ReverseAdoc.config.unknown_tags = :bypass
26
26
 
@@ -34,7 +34,22 @@ def log message
34
34
  puts "[stepmod-utils] #{message}"
35
35
  end
36
36
 
37
- log "STEPmod directory set to #{stepmod_dir}. Detecting paths..."
37
+ stepmod_path = Pathname.new(stepmod_dir).realpath
38
+
39
+ # If we are using the stepmod CVS repository, provide the revision number per file
40
+ has_cvs = File.which("cvs")
41
+ cvs_mode = has_cvs && Dir.exists?(stepmod_path.join('CVS'))
42
+
43
+ log "INFO: STEPmod directory set to #{stepmod_dir}."
44
+
45
+ if cvs_mode
46
+ log "INFO: STEPmod directory is a CVS repository and will detect revisions."
47
+ log "INFO: [CVS] Detecting file revisions can be slow, please be patient!"
48
+ else
49
+ log "INFO: STEPmod directory is not a CVS repository, skipping revision detection."
50
+ end
51
+
52
+ log "INFO: Detecting paths..."
38
53
 
39
54
  files = %w(
40
55
  resource.xml
@@ -46,25 +61,48 @@ files = %w(
46
61
  end.flatten.sort.uniq
47
62
 
48
63
  files.each do |file_path|
49
- log "Processing XML file #{file_path}"
64
+ file_path = Pathname.new(file_path).realpath
65
+ fpath = file_path.relative_path_from(stepmod_path)
66
+
67
+ log "INFO: Processing XML file #{fpath}"
50
68
  current_document = Nokogiri::XML(File.read(file_path)).root
51
69
 
52
70
  bibdata = nil
53
71
  begin
54
72
  bibdata = Stepmod::Utils::Bibdata.new(document: current_document)
55
73
  rescue
56
- log "WARNING: Unknown file #{file_path}, skipped"
74
+ log "WARNING: Unknown file #{fpath}, skipped"
57
75
  next
58
76
  end
59
77
 
60
78
  # TODO: we may want a command line option to override this in the future
61
79
  unless %w(IS DIS TS).include? bibdata.doctype
62
- log "WARNING: skipping #{bibdata.docid} as it is not IS, DIS or TS"
80
+ log "INFO: skipped #{bibdata.docid} as it is not IS, DIS or TS"
63
81
  next
64
82
  end
65
83
 
66
84
  if bibdata.part.to_s.empty?
67
- log "FATAL: missing `part` attribute: #{file_path}"
85
+ log "FATAL: missing `part` attribute: #{fpath}"
86
+ log "INFO: skipped #{bibdata.docid} as it is missing `part` attribute."
87
+ next
88
+ end
89
+
90
+ revision_string = "\n// CVS: revision not detected"
91
+ if cvs_mode
92
+ # Run `cvs status` to find out version
93
+
94
+ log "INFO: Detecting CVS revision..."
95
+ Dir.chdir(stepmod_path) do
96
+ status = `cvs status #{fpath}`
97
+
98
+ unless status.empty?
99
+ working_rev = status.split(/\n/).grep(/Working revision:/).first.match(/revision:\s+(.+)$/)[1]
100
+ repo_rev = status.split(/\n/).grep(/Repository revision:/).first.match(/revision:\t(.+)\t/)[1]
101
+ log "INFO: CVS working rev (#{working_rev}), repo rev (#{repo_rev})"
102
+ revision_string = "\n// CVS working rev: (#{working_rev}), repo rev (#{repo_rev})\n" +
103
+ "// CVS: revision #{working_rev == repo_rev ? 'up to date' : 'differs'}"
104
+ end
105
+ end
68
106
  end
69
107
 
70
108
  # read definitions
@@ -73,23 +111,28 @@ files.each do |file_path|
73
111
  term_id = definition['id']
74
112
  unless term_id.nil?
75
113
  if encountered_terms[term_id]
76
- log "FATAL: Duplicated term with id: #{term_id}, #{file_path}"
114
+ log "FATAL: Duplicated term with id: #{term_id}, #{fpath}"
77
115
  end
78
116
  encountered_terms[term_id] = true
79
117
  end
80
118
 
119
+ # Assume that definition is located in clause 3 of the ISO document
120
+ # in order. We really don't have a good reference here.
121
+ ref_clause = "3.#{index}"
122
+
81
123
  concept = Stepmod::Utils::Concept.parse(
82
124
  definition,
83
125
  reference_anchor: bibdata.anchor,
84
- # Assume that definition is located in clause 3 of the ISO document
85
- # in order. We really don't have a good reference here.
86
- reference_clause: "3.#{index}"
126
+ reference_clause: ref_clause,
127
+ file_path: fpath + revision_string
87
128
  )
88
129
 
89
130
  parsed_terms << concept
90
131
  parsed_bibliography << bibdata
91
132
  end
92
133
 
134
+ log "INFO: Completed processing XML file #{fpath}"
135
+
93
136
  end
94
137
 
95
138
  parsed_bibliography.uniq!
@@ -98,10 +141,10 @@ File.open('031-generated-terms.adoc', 'w') { |file|
98
141
  file.puts(parsed_terms.map(&:to_mn_adoc).join("\n"))
99
142
  }
100
143
 
101
- log "written to: 031-generated-terms.adoc"
144
+ log "INFO: written to: 031-generated-terms.adoc"
102
145
 
103
146
  File.open('991-generated-bibliography.adoc', 'w') { |file|
104
147
  file.puts(parsed_bibliography.map(&:to_mn_adoc).join("\n"))
105
148
  }
106
149
 
107
- log "written to: 991-generated-bibliography.adoc"
150
+ log "INFO: written to: 991-generated-bibliography.adoc"