-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderme.lua
104 lines (71 loc) · 2.57 KB
/
renderme.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- License: GPLv3 or any later version
--
-- Authors: Lsyncd devs and Riccardo Gagliarducci
-- From the idea in: https://lsyncd.github.io/lsyncd/manual/examples/auto-image-magic/
--
-- require "config"
package.path = '*.lua;' .. package.path
require "config"
log("Normal", "Watching " .. general.watchdir)
settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/var/log/lsyncd-status.log",
nodaemon = false
}
local formats = { blend = true }
render = {
delay = 0,
maxProcesses = 1,
action = function(inlet)
local event = inlet.getEvent()
if event.isdir then
-- ignores events on dirs
inlet.discardEvent(event)
return
end
-- extract extension and basefilename
local filename = event.pathname
local ext = string.match(filename, ".*%.([^.]+)$")
local base = string.match(filename, "(.*)%.[^.]+$")
if not formats[ext] then
-- an unknown extension
inlet.discardEvent(event)
return
end
-- the path, more on lsyncd.lua source
-- the baseDir as in config file
local baseDir = event.source
-- the base dir of the current file, can be subdir
local sourcePathdir = event.sourcePathdir
-- fix double slash in path
local sourcePathdir = string.gsub(sourcePathdir, "//", "/")
-- render on create and modify
if event.etype == "Create" or event.etype == "Modify" then
log("Normal", "filename ".. base)
-- Retrieve the hostname
local machinehostname = io.popen('hostname'):read('*l')
-- Name to check to start process
local machinehostnamestart = machinehostname .. ".start"
-- Check if the file base contains the "hostname-start" command
if string.match(base, machinehostnamestart) then
-- Rename the file to remove "machinehostname"
local new_filename = string.gsub(filename, machinehostnamestart, "")
os.rename(baseDir .. filename, baseDir .. new_filename)
local today = os.date('%Y-%m-%d_%H-%M-%S')
local logContent = today .. ' - Queued or processed by ' .. machinehostname .. ' - file ' .. new_filename
-- Write the processing status in lprocessing.txt, in the same source folder
os.execute('echo "' .. logContent .. '" >> "' .. sourcePathdir .. 'lprocessing.txt"')
-- Run the Blender command with the new file name
local command = 'blender -b "' .. baseDir .. new_filename .. '" -a'
os.execute(command)
log("Normal", "Rendering ".. baseDir .. new_filename)
end
end
if event.etype == "Delete" then
-- Todo kill process
end
-- ignores other events.
inlet.discardEvent(event)
end,
}
sync{render, source=general.watchdir}