Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kiosk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
don
kiosk
Commits
53bb6f9f
Commit
53bb6f9f
authored
6 years ago
by
don
Browse files
Options
Downloads
Patches
Plain Diff
major update for simpler configuration and usage
parent
c4340684
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
bin/install-pi
+1
-1
1 addition, 1 deletion
bin/install-pi
bin/install-root
+1
-1
1 addition, 1 deletion
bin/install-root
bin/process-conf
+1
-1
1 addition, 1 deletion
bin/process-conf
bin/run
+185
-119
185 additions, 119 deletions
bin/run
bin/show
+2
-8
2 additions, 8 deletions
bin/show
with
190 additions
and
130 deletions
bin/install-pi
+
1
−
1
View file @
53bb6f9f
#!/bin/bash
cd
/home/pi/kiosk
mkdir
content slides
state
tmp
mkdir
content slides
var
tmp
/home/pi/kiosk/bin/change-file a /home/pi/.config/lxsession/LXDE-pi/autostart
'@xset s noblank'
'@xset s off'
'@xset -dpms'
This diff is collapsed.
Click to expand it.
bin/install-root
+
1
−
1
View file @
53bb6f9f
...
...
@@ -6,7 +6,7 @@ apt-get -y install enscript feh ghostscript gsfonts imagemagick imagemagick-6-co
/home/pi/kiosk/bin/change-file a /etc/xdg/lxsession/LXDE/autostart
'@xset s noblank'
'@xset s off'
'@xset -dpms'
# make it start on boot
/home/pi/kiosk/bin/change-file c /etc/rc.local
'exit 0'
'#exit 0'
/home/pi/kiosk/bin/change-file a /etc/rc.local
'sleep
9
'
'sudo -u pi /home/pi/kiosk/bin/show'
'exit 0'
/home/pi/kiosk/bin/change-file a /etc/rc.local
'sleep
5
'
'sudo -u pi /home/pi/kiosk/bin/show'
'exit 0'
# make sure Raspberry Pi is caught up on all updates
apt-get
-y
update
apt-get
-y
dist-upgrade
...
...
This diff is collapsed.
Click to expand it.
bin/process-conf
+
1
−
1
View file @
53bb6f9f
#!/bin/sh
cd
/home/pi/kiosk/content
libreoffice
--headless
--convert-to
csv conf.xlsx
/bin/mv
-f
conf.csv ..
/bin/mv
-f
conf.csv ..
/var
This diff is collapsed.
Click to expand it.
bin/run
+
185
−
119
View file @
53bb6f9f
...
...
@@ -2,17 +2,25 @@
import
magic
,
os
,
pickle
,
re
,
subprocess
basedir
=
'
/home/pi/kiosk
'
remote
=
'
Kiosks:Kiosks/Test2
'
statusfile
=
os
.
path
.
join
(
basedir
,
'
state
'
,
'
statusfile
'
)
remote
=
'
Kiosks:Kiosks/Test3
'
contentbase
=
os
.
path
.
join
(
basedir
,
'
content
'
)
slidebase
=
os
.
path
.
join
(
basedir
,
'
slides
'
)
tmpdir
=
os
.
path
.
join
(
basedir
,
'
tmp
'
)
loopfile
=
os
.
path
.
join
(
basedir
,
'
state
'
,
'
loop
'
)
looptmp
=
os
.
path
.
join
(
basedir
,
'
state
'
,
'
loop.tmp
'
)
confcsv
=
os
.
path
.
join
(
basedir
,
'
conf.csv
'
)
statusfile
=
os
.
path
.
join
(
basedir
,
'
var
'
,
'
statusfile
'
)
loopfile
=
os
.
path
.
join
(
basedir
,
'
var
'
,
'
loop
'
)
looptmp
=
os
.
path
.
join
(
basedir
,
'
var
'
,
'
loop.tmp
'
)
waitfile
=
os
.
path
.
join
(
basedir
,
'
var
'
,
'
wait
'
)
waittmp
=
os
.
path
.
join
(
basedir
,
'
var
'
,
'
wait.tmp
'
)
confcsv
=
os
.
path
.
join
(
basedir
,
'
var
'
,
'
conf.csv
'
)
rclonebase
=
[
'
/usr/bin/rclone
'
,
'
sync
'
]
synccommand
=
rclonebase
+
[
remote
,
contentbase
]
# Default parameter values; each value is given as a triple:
# [default, minimum, maximum]
defaults
=
{
'
slide_rate
'
:
[
10
,
2
,
60
],
'
check_time
'
:
[
30
,
1
,
60
],
}
# File formats that "feh" can display directly with no processing
directformats
=
[
...
...
@@ -22,8 +30,44 @@ directformats = [
'
Netpbm image
'
,
]
# Interpreter line for the loop script
loopscript
=
'
#!/bin/bash
\n
'
# Video file formats that "omxplayer" can display
videoformats
=
[
'
ISO Media
'
,
'
AVI
'
,
'
DivX
'
,
]
# Template for loop script
looptemplate
=
'''
#!/bin/bash
cd %s
feh --cycle-once -FZ -D %d
'''
# Template for wait script
waittemplate
=
'''
#!/bin/bash
sleep %d
'''
# Keep track of history to avoid repeating work
filestatus
=
{}
# List of videos to play will get built here
videolist
=
[]
# Actual parameter values will get filled in here
parameters
=
{}
# Set a parameter from the config file and the defaults
def
setparam
(
parname
):
# Set up parameters
v
=
-
1
try
:
v
=
int
(
parameters
[
parname
])
except
:
pass
if
(
v
<
defaults
[
parname
][
1
])
or
(
v
>
defaults
[
parname
][
2
]):
v
=
defaults
[
parname
][
0
]
return
(
v
)
# Empty the temporary working directory
def
cleantmp
():
...
...
@@ -36,185 +80,206 @@ def cleantmp():
pass
# Copy a file into the temporary directory
def
tmpcopy
(
contentdir
,
filename
):
srcpath
=
os
.
path
.
join
(
contentbase
,
contentdir
,
filename
)
def
tmpcopy
(
filename
):
srcpath
=
os
.
path
.
join
(
contentbase
,
filename
)
dstpath
=
os
.
path
.
join
(
tmpdir
,
filename
)
subprocess
.
call
([
'
/bin/cp
'
,
'
-p
'
,
'
-f
'
,
srcpath
,
dstpath
])
# Move PNG files from temporary to slide directory
# Returns a list of moved files, and cleans the temporary directory
def
tmpmove
(
contentdir
,
moveall
):
def
tmpmove
(
moveall
):
tmpfiles
=
os
.
listdir
(
tmpdir
)
tmpfiles
.
sort
()
filelist
=
[]
for
f
in
tmpfiles
:
srcpath
=
os
.
path
.
join
(
tmpdir
,
f
)
if
moveall
or
(
f
[
-
4
:]
==
'
.png
'
):
dstpath
=
os
.
path
.
join
(
slidebase
,
contentdir
,
f
)
dstpath
=
os
.
path
.
join
(
slidebase
,
f
)
subprocess
.
call
([
'
/bin/mv
'
,
'
-f
'
,
srcpath
,
dstpath
])
filelist
+=
[
f
]
else
:
os
.
unlink
(
srcpath
)
return
(
filelist
)
# Synchronize with cloud storage
subprocess
.
call
(
synccommand
)
# Set up to read magic numbers and guess file types
ms
=
magic
.
open
(
magic
.
NONE
)
ms
.
load
()
# Write out a new version of an executable script file
def
writescript
(
scriptpath
,
content
):
tmppath
=
scriptpath
+
'
.new
'
fdout
=
open
(
tmppath
,
'
w
'
)
fdout
.
write
(
content
)
fdout
.
close
()
subprocess
.
call
([
'
/bin/chmod
'
,
'
u+x
'
,
tmppath
])
subprocess
.
call
([
'
/bin/mv
'
,
'
-f
'
,
tmppath
,
scriptpath
])
# Empty temporary directory
cleantmp
()
# Read previous file status, if it exists
try
:
stf
=
open
(
statusfile
,
'
rb
'
)
filestatus
=
pickle
.
load
(
stf
)
stf
.
close
()
except
:
filestatus
=
{}
# Slide files to preserve
keepcontent
=
{}
keepslides
=
{}
def
processfile
(
contentdir
,
f
):
print
(
'
processfile start
'
,
contentdir
,
f
)
slidedir
=
os
.
path
.
join
(
slidebase
,
contentdir
)
contentpath
=
os
.
path
.
join
(
contentbase
,
contentdir
)
filepath
=
os
.
path
.
join
(
contentpath
,
f
)
def
processfile
(
f
):
global
videolist
print
(
'
processfile start
'
,
f
)
filepath
=
os
.
path
.
join
(
contentbase
,
f
)
sb
=
os
.
stat
(
filepath
)
filetype
=
ms
.
file
(
filepath
)
filetag
=
os
.
path
.
join
(
contentdir
,
f
)
# Active file, save status record
keepcontent
[
f
iletag
]
=
True
if
f
iletag
in
filestatus
:
keepcontent
[
f
]
=
True
if
f
in
filestatus
:
# Status record exists
# Check size and modification time
thisstatus
=
filestatus
[
f
iletag
]
thisstatus
=
filestatus
[
f
]
if
(
thisstatus
[
'
s
'
]
==
sb
.
st_size
)
and
(
thisstatus
[
'
m
'
]
==
sb
.
st_mtime
)
and
(
thisstatus
[
'
t
'
]
==
filetype
):
# exact match, do not need to process this file
print
(
'
exact
'
,
f
)
# mark resulting slide files to save them
for
i
in
thisstatus
[
'
f
'
]:
keepslides
[
os
.
path
.
join
(
contentdir
,
i
)]
=
True
# See if it is video or slides
if
thisstatus
[
'
v
'
]:
# Mark this video to get played
videolist
+=
[
f
]
else
:
# mark resulting slide files to save them
for
i
in
thisstatus
[
'
f
'
]:
keepslides
[
i
]
=
True
return
else
:
# something has changed
print
(
'
changed
'
,
f
)
thisstatus
[
'
s
'
]
=
sb
.
st_size
thisstatus
[
'
m
'
]
=
sb
.
st_mtime
thisstatus
[
'
t
'
]
=
filetype
filestatus
[
f
][
'
s
'
]
=
sb
.
st_size
filestatus
[
f
][
'
m
'
]
=
sb
.
st_mtime
filestatus
[
f
][
'
t
'
]
=
filetype
filestatus
[
f
][
'
v
'
]
=
False
else
:
# new file, no status record yet, so make one
print
(
'
new
'
,
f
)
filestatus
[
filetag
]
=
{}
filestatus
[
filetag
][
'
s
'
]
=
sb
.
st_size
filestatus
[
filetag
][
'
m
'
]
=
sb
.
st_mtime
filestatus
[
filetag
][
'
t
'
]
=
filetype
filestatus
[
f
]
=
{}
filestatus
[
f
][
'
s
'
]
=
sb
.
st_size
filestatus
[
f
][
'
m
'
]
=
sb
.
st_mtime
filestatus
[
f
][
'
t
'
]
=
filetype
filestatus
[
f
][
'
v
'
]
=
False
# Figure out some useful paths
tmppath
=
os
.
path
.
join
(
tmpdir
,
f
)
destpath
=
os
.
path
.
join
(
slidedir
,
f
)
destpath
=
os
.
path
.
join
(
slidebase
,
f
)
# Check for images that can be displayed directly as slides
direct
=
False
for
d
in
directformats
:
if
d
in
filetype
:
for
ff
in
directformats
:
if
ff
in
filetype
:
direct
=
True
# Check for files that can be played as video clips
video
=
False
for
ff
in
videoformats
:
if
ff
in
filetype
:
video
=
True
if
direct
:
# files that can be displayed directly just need to be copied into place
print
(
'
direct
'
,
filepath
)
tmpcopy
(
contentdir
,
f
)
tmpcopy
(
f
)
subprocess
.
call
([
'
/bin/cp
'
,
'
-p
'
,
'
-f
'
,
filepath
,
destpath
])
keepslides
[
f
iletag
]
=
True
keepslides
[
f
]
=
True
elif
'
PDF document
'
in
filetype
:
tmpcopy
(
contentdir
,
f
)
tmpcopy
(
f
)
subprocess
.
call
([
'
/home/pi/kiosk/bin/file-pdf
'
])
elif
'
PostScript document
'
in
filetype
:
tmpcopy
(
contentdir
,
f
)
tmpcopy
(
f
)
subprocess
.
call
([
'
/home/pi/kiosk/bin/file-ps
'
])
elif
'
PowerPoint
'
in
filetype
or
'
Microsoft Word
'
in
filetype
or
'
Zip archive data
'
in
filetype
:
tmpcopy
(
contentdir
,
f
)
tmpcopy
(
f
)
subprocess
.
call
([
'
/home/pi/kiosk/bin/file-office
'
])
elif
'
ASCII text
'
in
filetype
:
tmpcopy
(
contentdir
,
f
)
tmpcopy
(
f
)
subprocess
.
call
([
'
/home/pi/kiosk/bin/file-text
'
])
elif
video
:
videolist
+=
[
f
]
else
:
print
(
'
unknown
'
,
filepath
)
print
(
filetype
)
filelist
=
tmpmove
(
contentdir
,
direct
)
filestatus
[
filetag
][
'
f
'
]
=
filelist
print
(
f
,
filetype
,
direct
,
video
)
filelist
=
tmpmove
(
direct
)
filestatus
[
f
][
'
f
'
]
=
filelist
for
i
in
filelist
:
keepslides
[
os
.
path
.
join
(
contentdir
,
i
)]
=
True
print
(
'
processfile done
'
,
contentdir
,
f
)
keepslides
[
i
]
=
True
filestatus
[
f
][
'
v
'
]
=
video
print
(
'
processfile done
'
,
f
)
# end of functions, main program starts here
# Process all files in one directory into one set of slides
def
processdir
(
contentdir
):
slidedir
=
os
.
path
.
join
(
slidebase
,
contentdir
)
contentpath
=
os
.
path
.
join
(
contentbase
,
contentdir
)
# Make the slide directory, in case it is new
try
:
os
.
mkdir
(
slidedir
)
except
:
pass
# Start by synchronizing with cloud storage to get content
# subprocess.call(synccommand)
# Set up to read magic numbers and guess file types
ms
=
magic
.
open
(
magic
.
NONE
)
ms
.
load
()
# Get list of content files
files
=
os
.
listdir
(
os
.
path
.
join
(
contentbase
,
contentdir
))
files
.
sort
()
# Empty temporary directory
cleantmp
()
# Read previous file status, if it exists
try
:
stf
=
open
(
statusfile
,
'
rb
'
)
filestatus
=
pickle
.
load
(
stf
)
stf
.
close
()
except
:
pass
# Examine all content files
for
f
in
files
:
processfile
(
contentdir
,
f
)
# Slide files to preserve
keepcontent
=
{}
keepslides
=
{}
contentdirs
=
[
'
.
'
]
# Turn the configuration file from a Google Sheet to a CSV file
subprocess
.
call
([
'
/home/pi/kiosk/bin/process-conf
'
])
# Run through the configuration file
# Run through the configuration file
and record parameters
confdata
=
open
(
confcsv
).
readlines
()
for
confline
in
confdata
[
1
:]:
# Ignore comments
if
confline
[
0
]
!=
'
#
'
:
fields
=
confline
.
split
(
'
,
'
)
action
=
fields
[
0
].
strip
().
lower
()
parameter
=
fields
[
1
].
strip
()
pathname
=
fields
[
2
].
strip
()
if
action
==
'
slides
'
:
loopscript
+=
"
cd
'
%s
'
\n
"
%
pathname
loopscript
+=
"
feh --cycle-once -FZ -D %s -R %s
\n
"
%
(
parameter
,
parameter
)
loopscript
+=
"
cd ..
\n
"
contentdirs
+=
[
pathname
]
processdir
(
pathname
)
uppath
=
fields
[
3
].
strip
()
if
uppath
!=
'
-
'
:
upsrc
=
os
.
path
.
join
(
slidebase
,
pathname
)
updst
=
os
.
path
.
join
(
remote
,
uppath
)
doupload
=
rclonebase
+
[
upsrc
,
updst
]
subprocess
.
call
(
doupload
)
if
action
==
'
video
'
:
loopscript
+=
"
omxplayer -b
'
../content/%s
'
\n
"
%
pathname
loopout
=
open
(
looptmp
,
'
w
'
)
loopout
.
write
(
loopscript
)
loopout
.
close
()
subprocess
.
call
([
'
/bin/chmod
'
,
'
u+x
'
,
looptmp
])
subprocess
.
call
([
'
/bin/mv
'
,
'
-f
'
,
looptmp
,
loopfile
])
fields
=
confline
.
split
(
'
,
'
)
if
len
(
fields
)
>
1
:
parameter
=
fields
[
0
].
strip
()
value
=
fields
[
1
].
strip
()
parameters
[
parameter
]
=
value
slide_rate
=
setparam
(
'
slide_rate
'
)
check_time
=
setparam
(
'
check_time
'
)
print
(
'
slide_rate
'
,
slide_rate
)
print
(
'
check_time
'
,
check_time
)
# Examine and process all content files
contentfiles
=
os
.
listdir
(
contentbase
)
contentfiles
.
sort
()
for
f
in
contentfiles
:
# Do not process config file as content
if
f
!=
'
conf.xlsx
'
:
processfile
(
f
)
# If requested, upload rendered slides for verification
try
:
doupload
=
rclonebase
+
[
slidebase
,
updst
]
updst
=
os
.
path
.
join
(
remote
,
parameters
[
'
verify_folder
'
])
# subprocess.call(doupload)
except
:
pass
# Prepare the looping script
loopscript
=
looptemplate
%
(
slidebase
,
slide_rate
)
# Videos get run one at a time
for
video
in
videolist
:
loopscript
+=
"
omxplayer -b
'
../content/%s
'
\n
"
%
video
# Write out the completed looping script
writescript
(
loopfile
,
loopscript
)
# Prepare and write out the waiting script (convert minutes to seconds)
waitscript
=
waittemplate
%
(
check_time
*
60
)
writescript
(
waitfile
,
waitscript
)
print
(
'
keepslides
'
,
keepslides
)
# final cleanup, delete obsolete slides
# Get list of slide files
for
d
in
contentdirs
:
slidedir
=
os
.
path
.
join
(
slidebase
,
d
)
files
=
os
.
listdir
(
slidedir
)
files
.
sort
()
for
f
in
files
:
if
os
.
path
.
join
(
d
,
f
)
not
in
keepslides
:
try
:
os
.
unlink
(
os
.
path
.
join
(
slidedir
,
f
))
print
(
'
unlink slide
'
,
f
)
except
:
pass
files
=
os
.
listdir
(
slidebase
)
files
.
sort
()
for
f
in
files
:
if
f
not
in
keepslides
:
try
:
os
.
unlink
(
os
.
path
.
join
(
slidebase
,
f
))
print
(
'
unlink slide
'
,
f
)
except
:
pass
# Delete status records for obsolete content
deletekeys
=
[]
...
...
@@ -230,3 +295,4 @@ for s in deletekeys:
stf
=
open
(
statusfile
,
'
wb
'
)
pickle
.
dump
(
filestatus
,
stf
)
stf
.
close
()
This diff is collapsed.
Click to expand it.
bin/show
+
2
−
8
View file @
53bb6f9f
#!/bin/sh
export
DISPLAY
=
:0
/home/pi/kiosk/bin/do-runner
>
/home/pi/kiosk/log 2>&1 &
cd
/home/pi/kiosk/content
feh
-FZ
background.png &
while
true
do
/home/pi/kiosk/state/loop
done
/home/pi/kiosk/bin/do-run
>
/home/pi/kiosk/var/log.run 2>&1 &
/home/pi/kiosk/bin/do-show
>
/home/pi/kiosk/var/log.show 2>&1 &
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment