python_uml_class 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +86 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/bin/start_python_uml_class.rb +52 -0
- data/bin/start_python_uml_class.rbw +52 -0
- data/lib/app_load.rb +2 -0
- data/lib/config/browser.json +4 -0
- data/lib/config/setting.json +47 -0
- data/lib/config.ru +107 -0
- data/lib/create_uml_class.rb +352 -0
- data/lib/css/index.css +178 -0
- data/lib/del_comment.py +36 -0
- data/lib/html/index.html +80 -0
- data/lib/js/main.js +466 -0
- data/lib/my_app_sample.rb +36 -0
- data/lib/python_uml_class/version.rb +5 -0
- data/lib/python_uml_class.rb +55 -0
- data/lib/server.rb +58 -0
- data/lib/server_app_base.rb +63 -0
- data/lib/start.rb +130 -0
- data/lib/wsserver.rb +148 -0
- data/python_uml_class.gemspec +43 -0
- data/sig/PythonUmlClass.rbs +4 -0
- metadata +102 -0
data/lib/start.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH << File.dirname(File.expand_path(__FILE__))
|
4
|
+
|
5
|
+
require "socket"
|
6
|
+
require "rack"
|
7
|
+
require "daemons"
|
8
|
+
require "fileutils"
|
9
|
+
require "kconv"
|
10
|
+
require "json"
|
11
|
+
require "facter"
|
12
|
+
|
13
|
+
# ログ出力
|
14
|
+
module Output
|
15
|
+
def self.console_and_file(output_file, stdout = true)
|
16
|
+
begin
|
17
|
+
defout = File.new(output_file, "a+")
|
18
|
+
rescue
|
19
|
+
puts $!
|
20
|
+
puts $@
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
class << defout
|
24
|
+
alias_method :write_org, :write
|
25
|
+
|
26
|
+
def initialize(stdout)
|
27
|
+
@stdout = false
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_accessor :stdout
|
31
|
+
|
32
|
+
def puts(str)
|
33
|
+
STDOUT.write(str.to_s + "\n") if @stdout
|
34
|
+
self.write_org(str.to_s + "\n")
|
35
|
+
self.flush
|
36
|
+
end
|
37
|
+
|
38
|
+
def write(str)
|
39
|
+
STDOUT.write(str) if @stdout
|
40
|
+
self.write_org(str)
|
41
|
+
self.flush
|
42
|
+
end
|
43
|
+
end
|
44
|
+
$stdout = defout
|
45
|
+
$stdout.stdout = stdout
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# ディレクトリ移動
|
50
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
51
|
+
FileUtils.cd dir
|
52
|
+
|
53
|
+
# ディレクトリ作成
|
54
|
+
pp ARGV
|
55
|
+
if ARGV[0] == "test"
|
56
|
+
$home_dir = "./"
|
57
|
+
ARGV = []
|
58
|
+
else
|
59
|
+
$home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/,"") + "/"
|
60
|
+
end
|
61
|
+
puts "home_dir=#{$home_dir}"
|
62
|
+
FileUtils.mkdir_p("#{$home_dir}/logs")
|
63
|
+
FileUtils.mkdir_p("#{$home_dir}/history")
|
64
|
+
Output.console_and_file("#{$home_dir}/logs/app.log", true)
|
65
|
+
|
66
|
+
# 空きポートを取得
|
67
|
+
def get_unused_port
|
68
|
+
s = TCPServer.open(0)
|
69
|
+
port = s.addr[1]
|
70
|
+
s.close
|
71
|
+
return port
|
72
|
+
end
|
73
|
+
|
74
|
+
# 空きポートを取得
|
75
|
+
port = get_unused_port
|
76
|
+
puts "port=#{port}"
|
77
|
+
|
78
|
+
# config.ruの編集
|
79
|
+
buf = File.binread("config.ru").toutf8
|
80
|
+
buf.gsub!(/port [0-9]+/, "port #{port}")
|
81
|
+
File.binwrite("config.ru", buf)
|
82
|
+
|
83
|
+
# main.jsの編集
|
84
|
+
buf = File.binread("js/main.js").toutf8
|
85
|
+
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
86
|
+
File.binwrite("js/main.js", buf)
|
87
|
+
|
88
|
+
# index.htaの編集
|
89
|
+
buf = File.binread("html/index.html").toutf8
|
90
|
+
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
91
|
+
File.binwrite("html/index.html", buf)
|
92
|
+
|
93
|
+
begin
|
94
|
+
Thread.start {
|
95
|
+
puts "wait start web server"
|
96
|
+
while true
|
97
|
+
begin
|
98
|
+
s = TCPSocket.open("localhost", port)
|
99
|
+
s.close
|
100
|
+
break
|
101
|
+
rescue
|
102
|
+
puts $!
|
103
|
+
sleep 0.1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
puts "start browser"
|
108
|
+
json_file = "#{$home_dir}/config/browser.json"
|
109
|
+
json = JSON.parse(File.read json_file)
|
110
|
+
puts json
|
111
|
+
kernel = Facter.value(:kernel)
|
112
|
+
if kernel == "windows"
|
113
|
+
browser = json["chrome_win"]
|
114
|
+
elsif kernel == "Linux"
|
115
|
+
browser = json["chrome_linux"]
|
116
|
+
else
|
117
|
+
browser = json["chrome_win"]
|
118
|
+
end
|
119
|
+
browser += " -app=http://localhost:#{port}"
|
120
|
+
puts browser
|
121
|
+
system browser
|
122
|
+
}
|
123
|
+
|
124
|
+
# start web server
|
125
|
+
Rack::Server.start
|
126
|
+
rescue
|
127
|
+
puts $!
|
128
|
+
puts $@
|
129
|
+
exit
|
130
|
+
end
|
data/lib/wsserver.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require "./server_app_base"
|
2
|
+
require "json"
|
3
|
+
require "cgi"
|
4
|
+
require "thread"
|
5
|
+
|
6
|
+
def config_json_hash(json)
|
7
|
+
config = {}
|
8
|
+
json["setting_list"].each do |j|
|
9
|
+
config[j["name"]] = j["value"]
|
10
|
+
end
|
11
|
+
return config
|
12
|
+
end
|
13
|
+
|
14
|
+
$ws_exit_thread = nil
|
15
|
+
|
16
|
+
class WsServer < Sinatra::Base
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
@ws_list = []
|
20
|
+
@ws_lock = Mutex.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def ws_send(str)
|
24
|
+
@ws_lock.synchronize do
|
25
|
+
if @ws_list[0] != nil
|
26
|
+
@ws_list[0].send(str)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
json_config = nil
|
32
|
+
exec_thread = nil
|
33
|
+
get "" do
|
34
|
+
if !request.websocket?
|
35
|
+
"no supported"
|
36
|
+
else
|
37
|
+
request.websocket do |ws|
|
38
|
+
ws.onopen do
|
39
|
+
puts "ws.open"
|
40
|
+
@ws_lock.synchronize do
|
41
|
+
@ws_list << ws
|
42
|
+
$app.set_ws(ws)
|
43
|
+
pp "ws=#{ws}"
|
44
|
+
end
|
45
|
+
ws_send("startup:#{$startup_file}")
|
46
|
+
puts "ws_exit_thread=#{$ws_exit_thread}"
|
47
|
+
if $ws_exit_thread != nil
|
48
|
+
puts "ws_exit_thread kill"
|
49
|
+
Thread.kill $ws_exit_thread
|
50
|
+
end
|
51
|
+
end
|
52
|
+
ws.onmessage do |msg|
|
53
|
+
puts msg
|
54
|
+
json = JSON.parse(File.read("#{$home_dir}/config/setting.json"))
|
55
|
+
json_config = config_json_hash(json)
|
56
|
+
$app.set_config(json_config)
|
57
|
+
if msg =~ /^exec:/
|
58
|
+
if exec_thread == nil
|
59
|
+
argv = msg.gsub(/^exec:/, "")
|
60
|
+
exec_thread = Thread.new {
|
61
|
+
begin
|
62
|
+
ws_send("app_start:running")
|
63
|
+
$app.start(argv.split(",")) do |out|
|
64
|
+
ws_send(out)
|
65
|
+
end
|
66
|
+
ws_send("app_end:normal")
|
67
|
+
rescue
|
68
|
+
puts $!
|
69
|
+
puts $@
|
70
|
+
puts "app_end:err"
|
71
|
+
ws_send("app_end:error")
|
72
|
+
ensure
|
73
|
+
puts "exit thread"
|
74
|
+
exec_thread = nil
|
75
|
+
end
|
76
|
+
}
|
77
|
+
else
|
78
|
+
puts "app_end:err"
|
79
|
+
ws_send("app_end:error")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
if msg =~ /^stop/
|
83
|
+
if exec_thread
|
84
|
+
Thread.kill exec_thread
|
85
|
+
ws_send("app_end:stop")
|
86
|
+
$app.stop
|
87
|
+
end
|
88
|
+
end
|
89
|
+
if msg =~ /^suspend/
|
90
|
+
if exec_thread
|
91
|
+
$app.suspend
|
92
|
+
end
|
93
|
+
end
|
94
|
+
if msg =~ /^resume/
|
95
|
+
if exec_thread
|
96
|
+
$app.resume
|
97
|
+
end
|
98
|
+
end
|
99
|
+
if msg =~ /^setting:/
|
100
|
+
json_string = msg.gsub(/^setting:/, "")
|
101
|
+
begin
|
102
|
+
json = JSON.parse(json_string)
|
103
|
+
File.open("#{$home_dir}/config/setting.json", "w") do |w|
|
104
|
+
w.puts JSON.pretty_generate(json)
|
105
|
+
end
|
106
|
+
json_config = config_json_hash(json)
|
107
|
+
$app.set_config(json_config)
|
108
|
+
rescue
|
109
|
+
# jsonファイルではない
|
110
|
+
ws_send("app_end:error")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
if msg =~ /^openfile:/
|
114
|
+
file = msg.gsub(/^openfile:/, "")
|
115
|
+
if file != ""
|
116
|
+
Thread.new {
|
117
|
+
system "#{json_config["editor"]} #{CGI.unescapeHTML(file)}"
|
118
|
+
}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# アプリケーション終了
|
123
|
+
if msg == "exit"
|
124
|
+
#halt
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# close websocket
|
130
|
+
ws.onclose do
|
131
|
+
puts "websocket closed"
|
132
|
+
@ws_lock.synchronize do
|
133
|
+
@ws_list.delete(ws)
|
134
|
+
end
|
135
|
+
puts @ws_list.size
|
136
|
+
if @ws_list.size == 0
|
137
|
+
$ws_exit_thread = Thread.start {
|
138
|
+
sleep 1
|
139
|
+
#halt
|
140
|
+
exit
|
141
|
+
}
|
142
|
+
puts "ws_exit_thread=#{$ws_exit_thread}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/python_uml_class/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "python_uml_class"
|
7
|
+
spec.version = PythonUmlClassVer::VERSION
|
8
|
+
spec.authors = ["Masataka kuwayama"]
|
9
|
+
spec.email = ["masataka.kuwayama@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Create a Python UML class diagram."
|
12
|
+
spec.description = "Create a Python UML class diagram with PlangUml."
|
13
|
+
spec.homepage = "https://github.com/kuwayama1971/PythonUmlClass"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "bin"
|
31
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
spec.add_dependency "browser_app_base", "~> 0.1"
|
38
|
+
spec.add_dependency "facter", "~> 4.2"
|
39
|
+
#spec.add_dependency "rufo", "~> 0.1"
|
40
|
+
|
41
|
+
# For more information and examples about making a new gem, check out our
|
42
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: python_uml_class
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masataka kuwayama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: browser_app_base
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: facter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
description: Create a Python UML class diagram with PlangUml.
|
42
|
+
email:
|
43
|
+
- masataka.kuwayama@gmail.com
|
44
|
+
executables:
|
45
|
+
- start_python_uml_class.rb
|
46
|
+
- start_python_uml_class.rbw
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/start_python_uml_class.rb
|
56
|
+
- bin/start_python_uml_class.rbw
|
57
|
+
- lib/app_load.rb
|
58
|
+
- lib/config.ru
|
59
|
+
- lib/config/browser.json
|
60
|
+
- lib/config/setting.json
|
61
|
+
- lib/create_uml_class.rb
|
62
|
+
- lib/css/index.css
|
63
|
+
- lib/del_comment.py
|
64
|
+
- lib/html/index.html
|
65
|
+
- lib/js/main.js
|
66
|
+
- lib/my_app_sample.rb
|
67
|
+
- lib/python_uml_class.rb
|
68
|
+
- lib/python_uml_class/version.rb
|
69
|
+
- lib/server.rb
|
70
|
+
- lib/server_app_base.rb
|
71
|
+
- lib/start.rb
|
72
|
+
- lib/wsserver.rb
|
73
|
+
- python_uml_class.gemspec
|
74
|
+
- sig/PythonUmlClass.rbs
|
75
|
+
homepage: https://github.com/kuwayama1971/PythonUmlClass
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
allowed_push_host: https://rubygems.org
|
80
|
+
homepage_uri: https://github.com/kuwayama1971/PythonUmlClass
|
81
|
+
source_code_uri: https://github.com/kuwayama1971/PythonUmlClass
|
82
|
+
changelog_uri: https://github.com/kuwayama1971/PythonUmlClass
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.6.0
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.3.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Create a Python UML class diagram.
|
102
|
+
test_files: []
|