stepmod-utils 0.3.10 → 0.3.14

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: 8c31735350e54a2aa7f6de9b0de749126887d48a8e1ce23fd56378c7a5319641
4
- data.tar.gz: aa494232f4f3858ea26f3379f602888066a7d1b98abd6d3c5cccc415d24fc58b
3
+ metadata.gz: 2dbfad6cebbd4552c2b91cfd5aac3dc5a032bde8a44269b83303d8472bf86310
4
+ data.tar.gz: 185a292f76f2e5b792383b8f2ca17438cb939a557f3df763ed5c9321c28b7438
5
5
  SHA512:
6
- metadata.gz: cb202b0ed3ca8ccc4a21c36e68a4135b06d2b136227caf9b5d6627dc706d85ab7b0c1396582f5d71f967e3a35c11884a6dc30256e91fedae0a0e2d9ca52c5db9
7
- data.tar.gz: 8a221bd8da7e75cf5653dee02fe484fbf1ab648ac8a0929941497d170310a5585b506e769c2f7ee695d3f694848aab1c874e83a668cdf397db6751d6ee3ca0b9
6
+ metadata.gz: a6f855167c151253c8b2278dfafe460198fe2c7789ce3cb2eba4dca20dc216546d88b68f199f48a6508574b1c28eaf476604799c99b3762662269eec743e0d5e
7
+ data.tar.gz: a85e8f5a2d4607f5c001c5889c4549d2698279bb5163b3e87c79e5e28c3f0bbea7a38dd56d3440af3b43467ac2d93d7b16407d63f27c7abc61ca3fe1f5aa6551
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:
@@ -21,14 +21,48 @@ end
21
21
  require "bundler/setup"
22
22
  require "stepmod/utils/terms_extractor"
23
23
 
24
- stepmod_dir = ARGV.first || Dir.pwd
24
+ require 'optparse'
25
+
26
+ options = {}
27
+ OptionParser.new do |opts|
28
+ opts.banner = "Usage: #{$0} [options]"
29
+
30
+ opts.on("-p", "--path STEPMOD_DATA_PATH", String, "Path to STEPmod CVS data directory") do |path|
31
+ options[:stepmod_dir] = path
32
+ end
33
+
34
+ opts.on("-i", "--index INDEX_PATH", String, "Path to repository_index.xml") do |path|
35
+ unless path.nil?
36
+ options[:index_path] = Pathname.new(path).to_s
37
+ end
38
+ end
39
+
40
+ opts.on_tail("-h", "--help", "Show this message") do
41
+ puts opts
42
+ exit
43
+ end
44
+ end.parse!
45
+
46
+ stepmod_dir = options[:stepmod_dir]
47
+ if stepmod_dir.nil?
48
+ raise StandardError.new("STEPmod data path not set, set with the `-p` option.")
49
+ else
50
+ log "STEPmod data path: `#{stepmod_dir}`"
51
+ end
52
+
53
+ index_path = options[:index_path] || File.join(stepmod_dir, "repository_index.xml")
54
+ unless File.exists?(index_path)
55
+ raise StandardError.new("Index file not present at #{index_path}, set with the `-i` option.")
56
+ else
57
+ log "Repository index path: `#{index_path}`"
58
+ end
25
59
 
26
60
  general_concepts,
27
61
  resource_concepts,
28
62
  parsed_bibliography,
29
63
  part_concepts,
30
64
  part_resources,
31
- part_modules = Stepmod::Utils::TermsExtractor.call(stepmod_dir)
65
+ part_modules = Stepmod::Utils::TermsExtractor.call(stepmod_dir, index_path)
32
66
 
33
67
  def part_to_title(bibdata)
34
68
  case bibdata.part.to_i
@@ -87,7 +121,7 @@ end
87
121
 
88
122
  File.open("03x-stepmod.adoc", "w") do |file|
89
123
  part_concepts.sort_by do |(bibdata, current_part_concepts)|
90
- bibdata.part
124
+ bibdata.part.to_i
91
125
  end.each do |(bibdata, current_part_concepts)|
92
126
  fn = "03x-stepmod-#{bibdata.part}.adoc"
93
127
  file.puts("\ninclude::#{fn}[]\n")
@@ -102,7 +136,7 @@ part_resources.each do |(bibdata, current_part_resources)|
102
136
  end
103
137
  fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
104
138
  File.open(fn, "w") do |file|
105
- file.puts("== #{part_to_title(bibdata)}\n\n")
139
+ # file.puts("== #{part_to_title(bibdata)}\n\n")
106
140
  file.puts(replace_images(current_part_resources.map(&:to_mn_adoc).join("\n")))
107
141
  end
108
142
  log "INFO: written to: #{fn}"
@@ -110,7 +144,7 @@ end
110
144
 
111
145
  File.open("04x-stepmod-entities-resources.adoc", "w") do |file|
112
146
  part_resources.sort_by do |(bibdata, current_part_resources)|
113
- bibdata.part
147
+ bibdata.part.to_i
114
148
  end.each do |(bibdata, current_part_resources)|
115
149
  fn = "04x-stepmod-entities-resources-#{bibdata.part}.adoc"
116
150
  file.puts("\ninclude::#{fn}[]\n")
@@ -152,7 +186,7 @@ end
152
186
 
153
187
  File.open("05x-stepmod-entities-modules.adoc", "w") do |file|
154
188
  part_modules.sort_by do |(bibdata, part_modules_arm, part_modules_mim)|
155
- bibdata.part
189
+ bibdata.part.to_i
156
190
  end.each do |(bibdata, part_modules_arm, part_modules_mim)|
157
191
  fn = "05x-stepmod-entities-modules-#{bibdata.part}.adoc"
158
192
  file.puts("\ninclude::#{fn}[]\n")
@@ -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.10".freeze
3
+ VERSION = "0.3.14".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.10
4
+ version: 0.3.14
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
-