-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewerd.py
executable file
·97 lines (72 loc) · 2.02 KB
/
viewerd.py
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
#!/usr/bin/python
import os
import sys
import datetime
import time
import glob
import re
import feh
from math import sqrt
from config import *
feh = feh.Feh()
list_counter = 0
files = []
user_files = []
sorted_raw_img_path = raw_img_path + "/"
def sleep(t):
print "--- sleeping %s seconds... ---" % t
print
time.sleep(t)
sleep(10)
while 1:
# Scan for images in drop dir, else show raw data
try:
user_files = os.listdir(drop_img_path)
except OSError:
print "OSError"
sleep(def_sleep_time)
continue
if len(user_files) > 0:
print "Full screen mode for user images"
feh.full_screen(drop_img_path)
sleep(def_sleep_time)
continue
print "Raw data mode in 100% zoom"
try:
files = os.listdir(raw_img_path)
except OSError:
print "OSerror"
sleep(def_sleep_time)
continue
if 'Caption' in files:
files.remove('Caption')
# Cifs drops sometimes temp files in the directory. remove
for fil in files:
if re.match("cifs.{4}", fil):
files.remove(fil)
files.sort(key=lambda x: os.path.getctime(sorted_raw_img_path + x))
num_of_files = len(files)
if num_of_files == 0:
sleep(def_sleep_time)
continue
current = files.pop(0)
if os.path.exists(sorted_raw_img_path + current):
print "Show %s" % current
if feh.current!=current:
feh.zoom_100(current, sorted_raw_img_path)
else:
print "File %s does not exist. Weird! System overloaded?" % current
time.sleep(min_sleep_time)
continue
sleep_time = max_sleep_time/sqrt(num_of_files)
if sleep_time<min_sleep_time:
sleep(min_sleep_time)
else:
sleep(sleep_time)
if num_of_files>1:
try:
os.remove(sorted_raw_img_path + current)
os.remove(sorted_raw_img_path + 'Caption/' + current + '.txt')
except OSError, e:
print "File already deleted."
pass