stepmod-utils 0.3.11 → 0.3.15

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
  SHA256:
3
- metadata.gz: b5d62b153f828f24d5e128e84ffcf18acdeaff96a8fb472e8d78432dce0eb7b0
4
- data.tar.gz: 3eff53e916039c898332294e2f6ae6b61195ff0eca6d6e26b8551f7c753b35a9
3
+ metadata.gz: e0fb38c39db845a0b6ff3358d7dea3b0b5f687c50109ee6318438a7787453e5e
4
+ data.tar.gz: 7ac3bdf768eeac0805f19fd41703632ed12460c4216b98c5a4b689dc99491033
5
5
  SHA512:
6
- metadata.gz: 47ca986f76df9da95c7acd5b6716311b7575f570a47ded6d27099f28ccf1ada59e9065825909df8a9e07932fba4e76c81a7746cbc93970fc4c451b90816d1f5e
7
- data.tar.gz: 96e624ef8e1223e4a09a6969e04aff34ef2ac75575f532f27da090a89b13ee5366b1b2d22bd2c319ba430aa5ac7f9a13c2513db391b005df55eb1b13b4bf3032
6
+ metadata.gz: 799b824cd2eec2efe7d3c5a7972ac21ead6af9b493e13e7ec78a3cfb6417e3576835e5aead8ac07ca264ae3513758cb212259d7ed0e0cb9713acb025393c26e6
7
+ data.tar.gz: 2b95f4f76fb19b09695d6cceddce5d854a4843bdfab62d645363b9fa379ad8616c8e1c361802264703c00684b9a3f7242c0aa22b6448ec8cc2e555cea85e797e
data/README.adoc CHANGED
@@ -10,7 +10,8 @@ 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
14
+ repository.
14
15
 
15
16
 
16
17
  == CVS to Git migration procedures
@@ -31,11 +32,8 @@ Or include it in your gemspec.
31
32
 
32
33
  [source,sh]
33
34
  ----
34
- # Extracts from current directory
35
- $ stepmod-extract-terms
36
-
37
- # Extracts from specified stepmod/ or stepmod/data/ directory
38
- $ stepmod-extract-terms {stepmod-data-directory}
35
+ # Extracts from specified stepmod/data/ directory
36
+ $ stepmod-extract-terms -p {stepmod-data-directory} -i {path-to-repository_index.xml}
39
37
  ----
40
38
 
41
39
  Then these files will be created:
@@ -20,15 +20,52 @@ end
20
20
 
21
21
  require "bundler/setup"
22
22
  require "stepmod/utils/terms_extractor"
23
+ require 'optparse'
23
24
 
24
- stepmod_dir = ARGV.first || Dir.pwd
25
+ def log(message)
26
+ puts "[stepmod-utils] #{message}"
27
+ end
28
+
29
+ options = {}
30
+ OptionParser.new do |opts|
31
+ opts.banner = "Usage: #{$0} [options]"
32
+
33
+ opts.on("-p", "--path STEPMOD_DATA_PATH", String, "Path to STEPmod CVS data directory") do |path|
34
+ options[:stepmod_dir] = path
35
+ end
36
+
37
+ opts.on("-i", "--index INDEX_PATH", String, "Path to repository_index.xml") do |path|
38
+ unless path.nil?
39
+ options[:index_path] = Pathname.new(path).to_s
40
+ end
41
+ end
42
+
43
+ opts.on_tail("-h", "--help", "Show this message") do
44
+ puts opts
45
+ exit
46
+ end
47
+ end.parse!
48
+
49
+ stepmod_dir = options[:stepmod_dir]
50
+ if stepmod_dir.nil?
51
+ raise StandardError.new("STEPmod data path not set, set with the `-p` option.")
52
+ else
53
+ log "STEPmod data path: `#{stepmod_dir}`"
54
+ end
55
+
56
+ index_path = options[:index_path] || File.join(stepmod_dir, "repository_index.xml")
57
+ unless File.exists?(index_path)
58
+ raise StandardError.new("Index file not present at #{index_path}, set with the `-i` option.")
59
+ else
60
+ log "Repository index path: `#{index_path}`"
61
+ end
25
62
 
26
63
  general_concepts,
27
64
  resource_concepts,
28
65
  parsed_bibliography,
29
66
  part_concepts,
30
67
  part_resources,
31
- part_modules = Stepmod::Utils::TermsExtractor.call(stepmod_dir)
68
+ part_modules = Stepmod::Utils::TermsExtractor.call(stepmod_dir, index_path)
32
69
 
33
70
  def part_to_title(bibdata)
34
71
  case bibdata.part.to_i
@@ -69,10 +106,6 @@ def replace_images(content)
69
106
  content
70
107
  end
71
108
 
72
- def log(message)
73
- puts "[stepmod-utils] #{message}"
74
- end
75
-
76
109
  part_concepts.each do |(bibdata, current_part_concepts)|
77
110
  current_part_concepts = current_part_concepts.to_a.map do |n|
78
111
  n.localizations["en"]
@@ -102,7 +135,7 @@ part_resources.each do |(bibdata, current_part_resources)|
102
135
  end
103
136
  fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
104
137
  File.open(fn, "w") do |file|
105
- file.puts("== #{part_to_title(bibdata)}\n\n")
138
+ # file.puts("== #{part_to_title(bibdata)}\n\n")
106
139
  file.puts(replace_images(current_part_resources.map(&:to_mn_adoc).join("\n")))
107
140
  end
108
141
  log "INFO: written to: #{fn}"
@@ -4,7 +4,9 @@ module Stepmod
4
4
  module Utils
5
5
  class Cleaner < ReverseAdoc::Cleaner
6
6
  def tidy(string)
7
- super.gsub(/^ +/, "")
7
+ super
8
+ .gsub(/^ +/, "")
9
+ .gsub(/\*\s([,.])/, '*\1') # remove space between * and comma or dot.
8
10
  end
9
11
  end
10
12
  end
@@ -124,7 +124,7 @@ module Stepmod
124
124
 
125
125
  def to_mn_adoc
126
126
  <<~TEXT
127
- // STEPmod path:#{!file_path.empty? ? " #{file_path}" : ''}
127
+ // STEPmod path:#{file_path.empty? ? '' : " #{file_path}"}
128
128
  #{converted_definition}
129
129
 
130
130
  [.source]
@@ -3,7 +3,7 @@ module Stepmod
3
3
  module Converters
4
4
  class ExtDescription < ReverseAdoc::Converters::Base
5
5
  def convert(node, state = {})
6
- state = state.merge(schema_name: node["linkend"])
6
+ state = state.merge(schema_name: node["linkend"], non_flanking_whitesapce: true)
7
7
  child_text = treat_children(node, state).strip
8
8
 
9
9
  <<~TEMPLATE
@@ -29,6 +29,13 @@ module Stepmod
29
29
  child_text = first_child
30
30
  end
31
31
 
32
+ # TEMP: Remove any whitespace (" ", not newlines) after an immediate
33
+ # newline due to:
34
+ # https://github.com/metanorma/iso-10303-2/issues/71
35
+ if child_text =~ /\n\ +/
36
+ child_text = child_text.gsub(/\n\ +/, "\n")
37
+ end
38
+
32
39
  # # Only taking the first sentence
33
40
  # if child_text.contains?(".")
34
41
  # child_text = child_text.split(".").first
@@ -36,10 +43,10 @@ module Stepmod
36
43
 
37
44
  domain = case linkend.first
38
45
  when /_mim$/, /_arm$/
39
- "STEP module"
46
+ "ISO 10303 application module"
40
47
  # when /_schema$/
41
48
  else
42
- "STEP resource"
49
+ "ISO 10303 resource"
43
50
  end
44
51
 
45
52
  <<~TEMPLATE
@@ -8,12 +8,13 @@ module Stepmod
8
8
 
9
9
  def convert(node, state = {})
10
10
  content = treat_children(node, state.merge(already_strong: true))
11
+ strong_tag = state[:non_flanking_whitesapce] ? '**' : '*'
11
12
  if content.strip.empty? || state[:already_strong]
12
13
  content
13
14
  else
14
15
  handle_express_escape_seq(
15
16
  node,
16
- "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
17
+ "#{content[/^\s*/]}#{strong_tag}#{content.strip}#{strong_tag}#{content[/\s*$/]}"
17
18
  )
18
19
  end
19
20
  end
@@ -14,7 +14,7 @@ module Stepmod
14
14
  # <<~TEXT
15
15
  # === #{node['name'].strip}
16
16
 
17
- # <STEP module> #{treat_children(node, state).strip}
17
+ # <ISO 10303 application module> #{treat_children(node, state).strip}
18
18
  # TEXT
19
19
  end
20
20
  end
@@ -17,6 +17,7 @@ require "stepmod/utils/converters/term"
17
17
  require "stepmod/utils/converters/synonym"
18
18
  require "stepmod/utils/converters/uof"
19
19
  require "stepmod/utils/converters/figure"
20
+ require "stepmod/utils/cleaner"
20
21
 
21
22
  require "reverse_adoc/converters/a"
22
23
  require "reverse_adoc/converters/blockquote"
@@ -56,7 +57,7 @@ module Stepmod
56
57
  options)
57
58
  return "" unless result
58
59
 
59
- ReverseAdoc.cleaner.tidy(result.dup)
60
+ Stepmod::Utils::Cleaner.new.tidy(result.dup)
60
61
  end
61
62
  end
62
63
  end
@@ -15,6 +15,7 @@ module Stepmod
15
15
 
16
16
  attr_reader :stepmod_path,
17
17
  :stepmod_dir,
18
+ :index_path,
18
19
  :general_concepts,
19
20
  :resource_concepts,
20
21
  :parsed_bibliography,
@@ -25,14 +26,15 @@ module Stepmod
25
26
  :part_modules,
26
27
  :stdout
27
28
 
28
- def self.call(stepmod_dir, stdout = $stdout)
29
- new(stepmod_dir, stdout).call
29
+ def self.call(stepmod_dir, index_path, stdout = $stdout)
30
+ new(stepmod_dir, index_path, stdout).call
30
31
  end
31
32
 
32
- def initialize(stepmod_dir, stdout)
33
+ def initialize(stepmod_dir, index_path, stdout)
33
34
  @stdout = stdout
34
35
  @stepmod_dir = stepmod_dir
35
36
  @stepmod_path = Pathname.new(stepmod_dir).realpath
37
+ @index_path = Pathname.new(index_path).to_s
36
38
  @general_concepts = Glossarist::Collection.new
37
39
  @resource_concepts = Glossarist::Collection.new
38
40
  @parsed_bibliography = []
@@ -79,7 +81,7 @@ module Stepmod
79
81
 
80
82
  log "INFO: Detecting paths..."
81
83
 
82
- repo_index = Nokogiri::XML(File.read(stepmod_path.join("repository_index.xml"))).root
84
+ repo_index = Nokogiri::XML(File.read(@index_path)).root
83
85
 
84
86
  files = []
85
87
 
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.11".freeze
3
+ VERSION = "0.3.15".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -215,7 +215,6 @@ files:
215
215
  - lib/stepmod/utils/stepmod_file_annotator.rb
216
216
  - lib/stepmod/utils/terms_extractor.rb
217
217
  - lib/stepmod/utils/version.rb
218
- - migrating_from_cvs.adoc
219
218
  - resource_example.xml
220
219
  - stepmod-utils.gemspec
221
220
  homepage: https://github.com/metanorma/stepmod-utils
@@ -1,190 +0,0 @@
1
- = STEPmod CVS to Git import
2
-
3
- == Purpose
4
-
5
- The `cvs/` submodule is a CSV import of STEPmod files from the CVS server hosted at Boost Conseil.
6
-
7
- The goal is to import the CSV-managed files in a way useable via Git, with full history information.
8
-
9
- This guide is used as reference for the usage of `cvs-fast-import`:
10
- https://oitofelix.github.io/article-savannah-cvs-to-git-migration/
11
-
12
-
13
- == Strategy to import
14
-
15
- Cloning a remote CVS repository while importing is super slow,
16
- especially for a large repository like STEPmod.
17
-
18
- We have tested and settled on these steps:
19
-
20
- . Maintain a local `rsync` copy of the CVS repository.
21
- . Resolve all names from the CVS repository (CVS only stores UNIX usernames, in Git are names and emails) using `cvs-fast-import`.
22
- . Run `cvs-fast-import` to import the CVS repository into the `iso-10303-stepmod-cvs` Git repo.
23
-
24
-
25
- == Creating the `rsync` clone of the CVS repository
26
-
27
- [source,sh]
28
- ----
29
- rsync -avrPz -e ssh ronald@cvs.boost-lab.net:/stepmod/ stepmod-rsync/
30
- ----
31
-
32
-
33
- == Install cvs-fast-export
34
-
35
- `cvs-fast-export` only works on Linux.
36
- Run it on Ubuntu with the `rsync`'ed CVS directory.
37
-
38
- Install:
39
- [source,sh]
40
- ----
41
- $ apt-get -y install cvs-fast-export
42
- ----
43
-
44
- == Getting all users for email mapping
45
-
46
- Find all authors in the CVS repository using `cvs-fast-export -a`.
47
- It is much faster than using the equivalent CVS command to list all authors.
48
-
49
- [source,sh]
50
- ----
51
- $ find stepmod-rsync -type f | cvs-fast-export -a
52
- ----
53
-
54
-
55
- == Create fast-import file for Git
56
-
57
- After all authors are mapped, run `cvs-fast-export` to create
58
- the import file.
59
-
60
- [source,sh]
61
- ----
62
- $ find stepmod-rsync -type f | cvs-fast-export -A author-map.txt > fast-import-file
63
- ----
64
-
65
- == Perform the Git fast-import
66
-
67
- Once the fast-import file is created, we can perform the Git import.
68
-
69
- [source,sh]
70
- ----
71
- $ cd iso-10303-stepmod-cvs
72
- $ git fast-import < ../fast-import-file
73
- ----
74
-
75
-
76
- == Upload the new Git repo
77
-
78
- [source,sh]
79
- ----
80
- git push --all && git push --tags
81
- ----
82
-
83
-
84
- == DEPRECATED steps using `git cvsimport` (do not use, it won't work)
85
-
86
- === General
87
-
88
- https://stackoverflow.com/questions/11362676/how-to-import-and-keep-updated-a-cvs-repository-in-git[This StackOverflow post]
89
- describes steps for using `git cvsimport`.
90
-
91
- Originally the `git cvsimport` tool was chosen since it is part of
92
- `git`. However, it utilizes a deprecated/unmaintained tool called
93
- `cvsps`. The latest `cvsps` is version 3, but only version 2 is
94
- compatible with `git cvsimport`.
95
-
96
- In addition, the `cvsps` tool is maintained by the maintainer
97
- of `cvs-fast-import`, and is no longer updated.
98
- Eventually `cvs-fast-import` is used instead.
99
-
100
- WARNING: This command completely fails
101
- on this repository because it is too large and complex.
102
-
103
-
104
- === Setup
105
-
106
- On macOS, run the following commands to setup for running the import. The `git` executable must be installed.
107
-
108
- Install `cvsps` version 2.
109
-
110
- NOTE: The steps from the StackOverflow of installing `cvsps` no longer work.
111
-
112
- [source,sh]
113
- ----
114
- $ brew tap Frizlab/Perso
115
- # ==> Tapping frizlab/perso
116
- # Cloning into '/usr/local/Homebrew/Library/Taps/frizlab/homebrew-perso'...
117
- # remote: Enumerating objects: 123, done.
118
- # remote: Total 123 (delta 0), reused 0 (delta 0), pack-reused 123
119
- # Receiving objects: 100% (123/123), 19.08 KiB | 91.00 KiB/s, done.
120
- # Resolving deltas: 100% (43/43), done.
121
- # Tapped 1 cask and 10 formulae (38 files, 60.5KB).
122
-
123
- $ brew install cvsps@2
124
- # ==> Installing cvsps@2 from frizlab/perso
125
- # Warning: A newer Command Line Tools release is available.
126
- # Update them from Software Update in System Preferences or
127
- # https://developer.apple.com/download/more/.
128
- # ==> Downloading https://deb.debian.org/debian/pool/main/c/cvsps/cvsps_2.1.orig.tar.gz
129
- ######################################################################## 100.0%
130
- # ==> make all
131
- # ==> make install prefix=/usr/local/Cellar/cvsps@2/2.1
132
- # 🍺 /usr/local/Cellar/cvsps@2/2.1: 7 files, 124.6KB, built in 6 seconds
133
- ----
134
-
135
- Verify it is installed:
136
- [source,sh]
137
- ----
138
- $ cvsps -v
139
- # Can't open CVS/Root
140
- # cannot determine CVSROOT
141
- ----
142
-
143
- ////
144
- == Checkout the CVS repository
145
-
146
- First set the `CVSROOT` and `CVS_RSH` variables.
147
-
148
- [source,sh]
149
- ----
150
- export CVSROOT=:ext:ronald@cvs.boost-lab.net:/stepmod
151
- export CVS_RSH=ssh
152
- cvs checkout stepmod
153
- # => stepmod/ is created in $PWD
154
- ----
155
- ////
156
-
157
-
158
- === Run the import
159
-
160
- Run the import from CVS to Git.
161
-
162
- Go to the directory that will carry the target Git repository.
163
-
164
- Run `git cvsimport`.
165
-
166
- [source,sh]
167
- ----
168
- # Importing from remote
169
- $ export CVSROOT=:ext:ronald@cvs.boost-lab.net:/stepmod
170
- $ export CVS_RSH=ssh
171
- $ git cvsimport -C iso-10303-stepmod-cvs -r cvs -k -v -d $CVSROOT stepmod
172
-
173
- # Importing from local rsync'ed copy
174
- $ export CVSROOT=$(pwd)/stepmod-rsync
175
- $ git cvsimport -C iso-10303-stepmod-cvs -r cvs -k -v -d $CVSROOT stepmod
176
- ----
177
-
178
- WARNING: TLDR. Technically this should work, but I ran into a `cvsps cannot allocate memory` error with 64GB of RAM, and not even completing the clone after 24 hours. So I gave up and switched to local. And local still takes a long time with tons of error messages. `cvs-fast-import` only takes 5-10 minutes to import.
179
-
180
-
181
- === Updating the CVS import
182
-
183
- Run `git cvsimport` to synchronize the Git repo using updated data from CVS.
184
-
185
- [source,sh]
186
- ----
187
- $ git cvsimport
188
- ----
189
-
190
-