Skip to content

Commit

Permalink
fixed mutex_p locking, modified outputNG to emit every index-*.html s…
Browse files Browse the repository at this point in the history
…o that any opened page won't be missing, added support for Animate CC about *.jsfl.
  • Loading branch information
KojiNakamaru committed May 26, 2017
1 parent 15c9f3f commit ed17857
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions lwfs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// global/static settings
"REMOTE_SERVER": null,
"BIRD_WATCHER_SERVER": null,
"REMOTE_SERVER_SYNC_METHOD": "rsync",
"IGNORED_PATTERN": "[,#].*|.*\.sw[op]|.*~",
"ALLOWED_PREFIX_PATTERN": "",
"TARGETS":
Expand Down
63 changes: 39 additions & 24 deletions lwfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def getLWFSConf(name)
$lwfsconf = {
# global/static settings
'REMOTE_SERVER' => nil,
'REMOTE_SERVER_SYNC_METHOD' => nil,
'BIRD_WATCHER_SERVER' => nil,
'IGNORED_PATTERN' => '[,#].*|.*\.sw[op]|.*~',
'ALLOWED_PREFIX_PATTERN' => '',
Expand Down Expand Up @@ -219,19 +220,22 @@ def needUpdate?(src, dst)
AUTO_CENTERING = $lwfsconf['AUTO_CENTERING']
SCREEN_SIZE = $lwfsconf['SCREEN_SIZE']
REMOTE_SERVER = $lwfsconf['REMOTE_SERVER']
REMOTE_SERVER_SYNC_METHOD = $lwfsconf['REMOTE_SERVER_SYNC_METHOD']
BIRD_WATCHER_SERVER = $lwfsconf['BIRD_WATCHER_SERVER']
TARGETS = $lwfsconf['TARGETS']
STATS_DISPLAY = $lwfsconf['STATS_DISPLAY']
RUBY_COMMAND = (RUBY_PLATFORM =~ /java/) ? 'jruby' : 'ruby'
if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
prefix = ENV['HOME']
updateJSFL(glob(prefix + '/Library/Application Support/Adobe/Flash C[CS]*/*/Configuration/Commands'))
updateJSFL(glob([prefix + '/Library/Application Support/Adobe/Animate CC*/*/Configuration/Commands',
prefix + '/Library/Application Support/Adobe/Flash C[CS]*/*/Configuration/Commands']))
OPEN_COMMAND = 'open'
WATCH_SCRIPT = 'lib/watch.rb'
LOG_FILE = '/dev/null'
elsif RbConfig::CONFIG['host_os'].downcase =~ /mswin(?!ce)|mingw|cygwin|bccwin/
prefix = ENV['USERPROFILE'].gsub(/\\/, '/')
updateJSFL(glob([prefix + '/AppData/Local/Adobe/Flash C[CS]*/*/Configuration/Commands',
updateJSFL(glob([prefix + '/AppData/Local/Adobe/Animate CC*/*/Configuration/Commands',
prefix + '/AppData/Local/Adobe/Flash C[CS]*/*/Configuration/Commands',
prefix + '/Local Settings/Application Data/Adobe/Flash C[CS]*/*/Configuration/Commands']))
OPEN_COMMAND = 'start'
WATCH_SCRIPT = 'lib/watch.rb'
Expand Down Expand Up @@ -334,7 +338,7 @@ def needUpdate?(src, dst)
path = File.join(settings.public_folder, path)
end
begin
if path =~ /\.(html|status|loading)$/
if path =~ /\.(html|status|loading)(\?.*)?$/
$mutex_p.synchronize do
begin
last_modified File.mtime(path)
Expand Down Expand Up @@ -409,9 +413,7 @@ def needUpdate?(src, dst)
end
end
else
$mutex_p.synchronize do
updateLoadingStatus("#{DST_DIR}/", true)
end
updateLoadingStatus("#{DST_DIR}/", true)
rsync(true) unless REMOTE_SERVER.nil?
end
$is_start = false
Expand All @@ -420,9 +422,7 @@ def needUpdate?(src, dst)
checkInterruptionWait = 0.0
while is_in_progress
catch :restart do
$mutex_p.synchronize do
updateLoadingStatus("#{DST_DIR}/", true)
end
updateLoadingStatus("#{DST_DIR}/", true)
checkInterruptionWait += 0.5
checkInterruptionWait = 3.0 if checkInterruptionWait > 3.0
t1 = Time.now
Expand Down Expand Up @@ -566,9 +566,7 @@ def sync()
# added/updated folders
changes = $changes.dup
changes.each do |name|
$mutex_p.synchronize do
updateLoadingStatus("#{DST_DIR}/#{name}/", true);
end
updateLoadingStatus("#{DST_DIR}/#{name}/", true);
end
rsync() unless REMOTE_SERVER.nil?
updates = []
Expand Down Expand Up @@ -1111,7 +1109,7 @@ def outputNG(lwfsconf, update_time, folder, name, prefix, commandline, msg)
relative = '../' * (name.split('/').count + 1)
content = <<-"EOF"
<!DOCTYPE HTML>
<html>
<html lang="en">
<head>
#{HEAD_COMMON}
<title>ERROR: #{name}</title>
Expand Down Expand Up @@ -1139,6 +1137,13 @@ def outputNG(lwfsconf, update_time, folder, name, prefix, commandline, msg)
File.open("#{folder}/index-err.html", 'w') do |fp|
fp.write(content)
end
TARGETS.each do |target|
['release', 'debug', 'birdwatcher'].each do |rel|
File.open("#{folder}/index-#{target}#{(rel == 'release') ? '' : '-' + rel}.html", 'w') do |fp|
fp.write(content)
end
end
end
File.open("#{folder}/.status", 'w') do |fp|
fp.puts('NG')
fp.puts(update_time)
Expand Down Expand Up @@ -1201,21 +1206,31 @@ def updateFolders(changes)
end

def rsync(is_top_only = false)
if is_top_only
`rsync -rtz --delete --no-p --no-g --chmod=ugo=rX --exclude "#{BASE_DIR}/list/*" #{BASE_DIR}/ rsync://#{REMOTE_SERVER}/lwfs/#{MY_ID}`
else
`rsync -rtz --delete --no-p --no-g --chmod=ugo=rX --exclude list/index.html --exclude list/.loading #{BASE_DIR}/ rsync://#{REMOTE_SERVER}/lwfs/#{MY_ID}`
if REMOTE_SERVER_SYNC_METHOD == 'uusync'
if is_top_only
`uusync --exclude "/list/.*/" #{BASE_DIR} http://#{REMOTE_SERVER}/uusync/lwfs/#{MY_ID}`
else
`uusync #{BASE_DIR} http://#{REMOTE_SERVER}/uusync/lwfs/#{MY_ID}`
end
else # rsync
if is_top_only
`rsync -rtz --delete --no-p --no-g --chmod=ugo=rX --exclude "#{BASE_DIR}/list/*" #{BASE_DIR}/ rsync://#{REMOTE_SERVER}/lwfs/#{MY_ID}`
else
`rsync -rtz --delete --no-p --no-g --chmod=ugo=rX --exclude list/index.html --exclude list/.loading #{BASE_DIR}/ rsync://#{REMOTE_SERVER}/lwfs/#{MY_ID}`
end
`rsync -rtz --delete --no-p --no-g --chmod=ugo=rX #{DST_DIR}/index.html #{DST_DIR}/.loading rsync://#{REMOTE_SERVER}/lwfs/#{MY_ID}/list`
end
`rsync -rtz --delete --no-p --no-g --chmod=ugo=rX #{DST_DIR}/index.html #{DST_DIR}/.loading rsync://#{REMOTE_SERVER}/lwfs/#{MY_ID}/list`
end

def updateLoadingStatus(dir, is_in_conversion, update_time = nil)
if File.exists?(dir)
File.open("#{dir}/.loading", 'w') do |fp|
if update_time.nil?
fp.write("{\"is_in_conversion\":#{is_in_conversion}}")
else
fp.write("{\"is_in_conversion\":#{is_in_conversion},\"update_time\":#{update_time}}")
$mutex_p.synchronize do
File.open("#{dir}/.loading", 'w') do |fp|
if update_time.nil?
fp.write("{\"is_in_conversion\":#{is_in_conversion}}")
else
fp.write("{\"is_in_conversion\":#{is_in_conversion},\"update_time\":#{update_time}}")
end
end
end
end
Expand Down Expand Up @@ -1345,8 +1360,8 @@ def updateTopIndex(update_time, mode = :default, exceptions = [])
File.open("#{DST_DIR}/index.html", 'w') do |fp|
fp.write(content)
end
updateLoadingStatus("#{DST_DIR}/", mode == :start, index_update_time)
end
updateLoadingStatus("#{DST_DIR}/", mode == :start, index_update_time)
end

def sameFile?(f0, f1)
Expand Down

0 comments on commit ed17857

Please sign in to comment.