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
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_function
...
...
@@ -7,6 +12,43 @@ module Commands
end
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
\ No newline at end of file
Git.rb
View file @
668f6cd2
...
...
@@ -13,11 +13,7 @@ module Git
return
`cd
#{
global
.
answer_path
}
&& git push`
end
def
commit
end
def
hook
def
commit
(
message
=
""
)
return
`cd
#{
global
.
answer_path
}
&& git add . && git commit -a -m
\"
Update card images
\"
`
end
end
\ No newline at end of file
Global.rb
View file @
668f6cd2
...
...
@@ -12,6 +12,7 @@ module Global
attr_accessor
:answer_uri
attr_accessor
:mse_path
attr_accessor
:mse_set_path
attr_accessor
:sql_fix_name
end
self
.
language
=
'cn'
self
.
git_path
=
'ygopro-images-raw'
...
...
@@ -22,6 +23,7 @@ module Global
self
.
answer_path
=
"ygopro-images"
self
.
answer_uri
=
"https://github.com/mycard/ygo-images.git"
self
.
mse_path
=
"MagicSetEditor2"
self
.
sql_fix_name
=
"fix.sql"
self
.
mse_set_path
=
"mse-sets"
module_function
def
full_database_path
...
...
HashJudger.rb
View file @
668f6cd2
# Judge the hash.
# offer the CSV version and JSON Version.
# Use the JSON Version.
require
'JSON'
...
...
@@ -7,6 +6,7 @@ require File.dirname(__FILE__) + '/Authorize.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Sqlite.rb'
require
File
.
dirname
(
__FILE__
)
+
'/YgoCoreJudgers.rb'
module
HashJudger
module_function
...
...
@@ -36,20 +36,24 @@ module HashJudger
return
[
Authorize
.
md5_file
(
image_path
),
Authorize
.
md5
(
data
)]
end
@@temp_id_to_data
=
{}
def
generate_document
(
sql_data
)
answer
=
{}
@@temp_id_to_data
=
{}
for
data
in
sql_data
id
=
data
[
0
]
id
=
YGOCoreJudgers
.
get_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
return
answer
end
def
compare
def
compare
(
data
)
# 读取两组数据
old_data
=
self
.
load
new_data
=
generate_document
(
Sqlite
.
load
)
new_data
=
generate_document
(
data
)
# 生成编号序列
# 添加
adds
=
new_data
.
keys
-
old_data
.
keys
...
...
@@ -67,6 +71,8 @@ module HashJudger
Log
.
logger
.
info
"Following cards removed:"
removes
.
each
{
|
id
|
Log
.
logger
.
info
"
#{
[
id
]
}
"
}
end
adds
.
map!
{
|
id
|
@@temp_id_to_data
[
id
]}
removes
.
map!
{
|
id
|
@@temp_id_to_data
[
id
]}
# 公共部分
commons
=
new_data
.
keys
&
old_data
.
keys
changes
=
[]
...
...
@@ -77,13 +83,13 @@ module HashJudger
new_piece
=
new_data
[
id
]
if
old_piece
[
0
]
!=
new_piece
[
0
]
and
old_piece
[
1
]
!=
new_piece
[
1
]
Log
.
logger
.
info
"[
#{
id
}
] Both changed"
changes
.
push
id
changes
.
push
@@temp_id_to_data
[
id
]
elsif
old_piece
[
0
]
!=
new_piece
[
0
]
Log
.
logger
.
info
"[
#{
id
}
] image changed"
changes
.
push
id
changes
.
push
@@temp_id_to_data
[
id
]
elsif
old_piece
[
1
]
!=
new_piece
[
1
]
Log
.
logger
.
info
"[
#{
id
}
] data changed"
changes
.
push
id
changes
.
push
@@temp_id_to_data
[
id
]
end
end
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__
)
+
'/Y
GO
CoreJudgers.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Y
go
CoreJudgers.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Global.rb'
require
File
.
dirname
(
__FILE__
)
+
'/Log.rb'
require
'zip'
module
MSETranslator
module_function
...
...
@@ -94,7 +95,6 @@ module MSETranslator
end
def
generate_mse
(
data
,
key
=
""
)
require
'zip'
path
=
File
.
join
Global
.
mse_set_path
,
"data
#{
key
}
-
#{
Global
.
language
}
.mse-set"
clear_data
=
[]
Zip
::
File
.
open
(
path
,
Zip
::
File
::
CREATE
)
do
|
zipfile
|
...
...
Server.rb
View file @
668f6cd2
# sinatra server core
require
"sinatra"
require
File
.
dirname
(
__FILE__
)
+
"/Git.rb"
require
File
.
dirname
(
__FILE__
)
+
"/Command.rb"
post
'/command'
do
end
post
'/hook'
do
Git
.
pull
Commands
.
generate_delta
Git
.
commit
Git
.
push
end
\ No newline at end of file
Sqlite.rb
View file @
668f6cd2
...
...
@@ -5,16 +5,37 @@ require File.dirname(__FILE__) + '/Log.rb'
require
File
.
dirname
(
__FILE__
)
+
'/MSEConstants.rb'
module
Sqlite
def
self
.
load
def
self
.
load
(
id
=
-
1
)
begin
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
Log
.
logger
.
error
"Failed to load sql while running command:
#{
command
}
."
Log
.
logger
.
error
e
.
inspect
nil
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
)
size
=
MSEConstants
::
SingleFileMaxCount
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