Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-images-generator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-images-generator
Commits
668f6cd2
Commit
668f6cd2
authored
Mar 30, 2016
by
Peter Xin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FIX.
Added Git module Added Commands module
parent
c96e4c4e
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
19 deletions
+91
-19
Commands.rb
Commands.rb
+42
-0
Git.rb
Git.rb
+2
-6
Global.rb
Global.rb
+2
-0
HashJudger.rb
HashJudger.rb
+14
-8
MSETranslator.rb
MSETranslator.rb
+2
-2
Server.rb
Server.rb
+6
-1
Sqlite.rb
Sqlite.rb
+23
-2
No files found.
Commands.rb
View file @
668f6cd2
# Commands Reflector
# Commands Reflector
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Sqlite.rb'
require
File
.
dirname
(
__FILE__
)
+
'/MSETranslator.rb'
require
File
.
dirname
(
__FILE__
)
+
'/HashJudger.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
module
Commands
module
Commands
module_function
module_function
...
@@ -7,6 +12,43 @@ module Commands
...
@@ -7,6 +12,43 @@ module Commands
end
end
def
change_password
(
password
)
def
change_password
(
password
)
Authorize
.
change_password
password
end
def
generate_all
Log
.
logger
.
info
"Generate all the card images."
self
.
clear_mse
data
=
Sqlite
.
split
Sqlite
.
load
MSETranslator
.
generate_mse_all
(
data
)
MSETranslator
.
export_mse_all
end
def
generate_delta
Log
.
logger
.
info
"Generate delta card image(s)"
self
.
clear_mse
data
=
Sqlite
.
load
changes
=
HashJudger
.
compare
data
generates
=
changes
[
0
]
+
changes
[
2
]
removes
=
changes
[
1
]
for
card
in
removes
id
=
YGOCoreJudgers
.
get_id
card
path
=
Global
.
full_image_name
id
File
.
delete
path
if
File
.
exist?
path
end
data
=
Sqlite
.
split
generates
MSETranslator
.
generate_mse_all
(
data
)
MSETranslator
.
export_mse_all
end
def
generate_single
(
id
)
Log
.
logger
.
info
"Generate single card image
#{
id
}
"
self
.
clear_mse
MSETranslator
.
generate_mse
Sqlite
.
load
(
id
)
MSETranslator
.
export_mse_all
end
def
clear_mse
Log
.
logger
.
info
"Clearing MSE Path"
Dir
.
glob
(
"
#{
Global
.
mse_set_path
}
/*.mse-set"
)
{
|
set
|
File
.
delete
set
}
end
end
end
end
\ No newline at end of file
Git.rb
View file @
668f6cd2
...
@@ -13,11 +13,7 @@ module Git
...
@@ -13,11 +13,7 @@ module Git
return
`cd
#{
global
.
answer_path
}
&& git push`
return
`cd
#{
global
.
answer_path
}
&& git push`
end
end
def
commit
def
commit
(
message
=
""
)
return
`cd
#{
global
.
answer_path
}
&& git add . && git commit -a -m
\"
Update card images
\"
`
end
def
hook
end
end
end
end
\ No newline at end of file
Global.rb
View file @
668f6cd2
...
@@ -12,6 +12,7 @@ module Global
...
@@ -12,6 +12,7 @@ module Global
attr_accessor
:answer_uri
attr_accessor
:answer_uri
attr_accessor
:mse_path
attr_accessor
:mse_path
attr_accessor
:mse_set_path
attr_accessor
:mse_set_path
attr_accessor
:sql_fix_name
end
end
self
.
language
=
'cn'
self
.
language
=
'cn'
self
.
git_path
=
'ygopro-images-raw'
self
.
git_path
=
'ygopro-images-raw'
...
@@ -22,6 +23,7 @@ module Global
...
@@ -22,6 +23,7 @@ module Global
self
.
answer_path
=
"ygopro-images"
self
.
answer_path
=
"ygopro-images"
self
.
answer_uri
=
"https://github.com/mycard/ygo-images.git"
self
.
answer_uri
=
"https://github.com/mycard/ygo-images.git"
self
.
mse_path
=
"MagicSetEditor2"
self
.
mse_path
=
"MagicSetEditor2"
self
.
sql_fix_name
=
"fix.sql"
self
.
mse_set_path
=
"mse-sets"
self
.
mse_set_path
=
"mse-sets"
module_function
module_function
def
full_database_path
def
full_database_path
...
...
HashJudger.rb
View file @
668f6cd2
# Judge the hash.
# Judge the hash.
# offer the CSV version and JSON Version.
# Use the JSON Version.
# Use the JSON Version.
require
'JSON'
require
'JSON'
...
@@ -7,6 +6,7 @@ require File.dirname(__FILE__) + '/Authorize.rb'
...
@@ -7,6 +6,7 @@ require File.dirname(__FILE__) + '/Authorize.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Sqlite.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Sqlite.rb'
require
File
.
dirname
(
__FILE__
)
+
'/YgoCoreJudgers.rb'
module
HashJudger
module
HashJudger
module_function
module_function
...
@@ -36,20 +36,24 @@ module HashJudger
...
@@ -36,20 +36,24 @@ module HashJudger
return
[
Authorize
.
md5_file
(
image_path
),
Authorize
.
md5
(
data
)]
return
[
Authorize
.
md5_file
(
image_path
),
Authorize
.
md5
(
data
)]
end
end
@@temp_id_to_data
=
{}
def
generate_document
(
sql_data
)
def
generate_document
(
sql_data
)
answer
=
{}
answer
=
{}
@@temp_id_to_data
=
{}
for
data
in
sql_data
for
data
in
sql_data
id
=
data
[
0
]
id
=
YGOCoreJudgers
.
get_id
data
hash
=
self
.
generate_hash
id
,
data
hash
=
self
.
generate_hash
id
,
data
answer
[
id
.
to_s
]
=
hash
if
hash
!=
nil
next
if
hash
==
nil
answer
[
id
.
to_s
]
=
hash
@@temp_id_to_data
[
id
.
to_s
]
=
data
end
end
return
answer
return
answer
end
end
def
compare
def
compare
(
data
)
# 读取两组数据
# 读取两组数据
old_data
=
self
.
load
old_data
=
self
.
load
new_data
=
generate_document
(
Sqlite
.
load
)
new_data
=
generate_document
(
data
)
# 生成编号序列
# 生成编号序列
# 添加
# 添加
adds
=
new_data
.
keys
-
old_data
.
keys
adds
=
new_data
.
keys
-
old_data
.
keys
...
@@ -67,6 +71,8 @@ module HashJudger
...
@@ -67,6 +71,8 @@ module HashJudger
Log
.
logger
.
info
"Following cards removed:"
Log
.
logger
.
info
"Following cards removed:"
removes
.
each
{
|
id
|
Log
.
logger
.
info
"
#{
[
id
]
}
"
}
removes
.
each
{
|
id
|
Log
.
logger
.
info
"
#{
[
id
]
}
"
}
end
end
adds
.
map!
{
|
id
|
@@temp_id_to_data
[
id
]}
removes
.
map!
{
|
id
|
@@temp_id_to_data
[
id
]}
# 公共部分
# 公共部分
commons
=
new_data
.
keys
&
old_data
.
keys
commons
=
new_data
.
keys
&
old_data
.
keys
changes
=
[]
changes
=
[]
...
@@ -77,13 +83,13 @@ module HashJudger
...
@@ -77,13 +83,13 @@ module HashJudger
new_piece
=
new_data
[
id
]
new_piece
=
new_data
[
id
]
if
old_piece
[
0
]
!=
new_piece
[
0
]
and
old_piece
[
1
]
!=
new_piece
[
1
]
if
old_piece
[
0
]
!=
new_piece
[
0
]
and
old_piece
[
1
]
!=
new_piece
[
1
]
Log
.
logger
.
info
"[
#{
id
}
] Both changed"
Log
.
logger
.
info
"[
#{
id
}
] Both changed"
changes
.
push
id
changes
.
push
@@temp_id_to_data
[
id
]
elsif
old_piece
[
0
]
!=
new_piece
[
0
]
elsif
old_piece
[
0
]
!=
new_piece
[
0
]
Log
.
logger
.
info
"[
#{
id
}
] image changed"
Log
.
logger
.
info
"[
#{
id
}
] image changed"
changes
.
push
id
changes
.
push
@@temp_id_to_data
[
id
]
elsif
old_piece
[
1
]
!=
new_piece
[
1
]
elsif
old_piece
[
1
]
!=
new_piece
[
1
]
Log
.
logger
.
info
"[
#{
id
}
] data changed"
Log
.
logger
.
info
"[
#{
id
}
] data changed"
changes
.
push
id
changes
.
push
@@temp_id_to_data
[
id
]
end
end
end
end
Log
.
logger
.
info
"Oooooops but no data or file changed."
if
changes
==
[]
Log
.
logger
.
info
"Oooooops but no data or file changed."
if
changes
==
[]
...
...
MSETranslator.rb
View file @
668f6cd2
require
File
.
dirname
(
__FILE__
)
+
'/MSEConstants.rb'
require
File
.
dirname
(
__FILE__
)
+
'/MSEConstants.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Y
GO
CoreJudgers.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Y
go
CoreJudgers.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
require
'zip'
module
MSETranslator
module
MSETranslator
module_function
module_function
...
@@ -94,7 +95,6 @@ module MSETranslator
...
@@ -94,7 +95,6 @@ module MSETranslator
end
end
def
generate_mse
(
data
,
key
=
""
)
def
generate_mse
(
data
,
key
=
""
)
require
'zip'
path
=
File
.
join
Global
.
mse_set_path
,
"data
#{
key
}
-
#{
Global
.
language
}
.mse-set"
path
=
File
.
join
Global
.
mse_set_path
,
"data
#{
key
}
-
#{
Global
.
language
}
.mse-set"
clear_data
=
[]
clear_data
=
[]
Zip
::
File
.
open
(
path
,
Zip
::
File
::
CREATE
)
do
|
zipfile
|
Zip
::
File
.
open
(
path
,
Zip
::
File
::
CREATE
)
do
|
zipfile
|
...
...
Server.rb
View file @
668f6cd2
# sinatra server core
# sinatra server core
require
"sinatra"
require
"sinatra"
require
File
.
dirname
(
__FILE__
)
+
"/Git.rb"
require
File
.
dirname
(
__FILE__
)
+
"/Command.rb"
post
'/command'
do
post
'/command'
do
end
end
post
'/hook'
do
post
'/hook'
do
Git
.
pull
Commands
.
generate_delta
Git
.
commit
Git
.
push
end
end
\ No newline at end of file
Sqlite.rb
View file @
668f6cd2
...
@@ -5,16 +5,37 @@ require File.dirname(__FILE__) + '/Log.rb'
...
@@ -5,16 +5,37 @@ require File.dirname(__FILE__) + '/Log.rb'
require
File
.
dirname
(
__FILE__
)
+
'/MSEConstants.rb'
require
File
.
dirname
(
__FILE__
)
+
'/MSEConstants.rb'
module
Sqlite
module
Sqlite
def
self
.
load
def
self
.
load
(
id
=
-
1
)
begin
begin
db
=
SQLite3
::
Database
.
new
Global
.
full_database_path
db
=
SQLite3
::
Database
.
new
Global
.
full_database_path
db
.
execute
"select * from datas join texts on datas.id == texts.id"
self
.
run_fix
(
db
)
command
=
"select * from datas join texts on datas.id == texts.id"
command
+=
" where datas.id ==
#{
id
}
"
if
id
>
0
ans
=
db
.
execute
command
db
.
close
ans
rescue
Exception
=>
e
rescue
Exception
=>
e
Log
.
logger
.
error
"Failed to load sql while running command:
#{
command
}
."
Log
.
logger
.
error
e
.
inspect
Log
.
logger
.
error
e
.
inspect
nil
nil
end
end
end
end
def
self
.
run_fix
(
db
)
if
File
.
exist?
(
Global
.
sql_fix_name
)
begin
Log
.
logger
.
info
"Going to run fix sql"
content
=
File
.
open
(
Global
.
sql_fix_name
)
{
|
f
|
f
.
read
}
db
.
execute
(
content
)
rescue
Exception
=>
e
Log
.
logger
.
error
"Failed to run the sql fix."
Log
.
logger
.
error
e
.
inspect
end
else
Log
.
logger
.
warn
"No file named
#{
Global
.
sql_fix_name
}
. Skip the sql fix process."
end
end
def
self
.
split
(
data
)
def
self
.
split
(
data
)
size
=
MSEConstants
::
SingleFileMaxCount
size
=
MSEConstants
::
SingleFileMaxCount
count
=
(
data
.
size
-
1
)
/
size
+
1
count
=
(
data
.
size
-
1
)
/
size
+
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment