-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsugar-network-thumber
executable file
·108 lines (88 loc) · 3.4 KB
/
sugar-network-thumber
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
105
106
107
108
#!/usr/bin/env python
# Copyright (C) 2014 Aleksey Lim
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from os.path import exists, join
from sugar_network.toolkit import coroutine
coroutine.inject()
from sugar_network import toolkit
from sugar_network.node import model
from sugar_network.node.slave import SlaveRoutes
from sugar_network.toolkit import application, i18n, Option, enforce
data_root = Option(
'path to a directory to place node data',
default='/var/lib/sugar-network', name='data_root')
force = Option(
'intensify regular behaviour',
default=False, type_cast=Option.bool_cast, short_option='-f',
action='store_true', name='force')
class Application(application.Daemon):
seqno = None
volume = None
jobs = coroutine.Pool()
def prolog(self):
if not exists(data_root.value):
os.makedirs(data_root.value)
enforce(os.access(data_root.value, os.W_OK),
'No write access to %r directory', data_root.value)
for opt, dirname in [
(application.logdir, 'log'),
(application.rundir, 'run'),
]:
if not opt.value:
opt.value = join(data_root.value, dirname)
if not exists(opt.value):
os.makedirs(opt.value)
self.seqno = toolkit.Bin(
join(data_root.value, 'var', 'seqno-thumbs'), 1)
self.volume = model.Volume(data_root.value, SlaveRoutes.RESOURCES)
def run(self):
self.jobs.spawn(self.volume.blobs.poll_thumbs)
self.jobs.spawn(self.volume.blobs.populate_thumbs, self.seqno.value)
self.accept()
try:
self.jobs.join()
finally:
self.seqno.value = self.volume.seqno.value
self.seqno.commit()
def shutdown(self):
self.jobs.kill()
@application.command(
'generate missed thumbnails; if --force is specified, '
'all thumbnails will be re-generated', name='thumb')
def thumb(self):
self.volume.blobs.populate_thumbs(
seqno=None if force.value else self.seqno.value,
force=force.value)
self.seqno.value = self.volume.seqno.value
self.seqno.commit()
i18n.init('sugar-network')
# New defaults
application.logdir.value = None
application.rundir.value = None
Option.seek('main', application)
Option.seek('main', [force])
Option.seek('node', [data_root])
app = Application(
name='sugar-network-thumber',
description='Generate thumbnails on demand on Sugar Network node side',
epilog='See http://wiki.sugarlabs.org/go/Sugar_Network '
'for details.',
config_files=[
'/etc/sugar-network.d',
'/etc/sugar-network.conf',
'~/.config/sugar-network/config',
])
app.start()