forked from xak-mcu/ruleuser
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreads.py
More file actions
165 lines (125 loc) · 4.67 KB
/
threads.py
File metadata and controls
165 lines (125 loc) · 4.67 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#! /usr/bin/env python
# -*- coding: utf8 -*-
###################################################################################################
# RuleUser
# threads.py
#
# Copyright (C) 2012,2013 Andrey Burbovskiy <xak-altsp@yandex.ru>
# Copyright (C) 2017 Артем Проскурнев (Artem Proskurnev) <tema@proskurnev.name>
# Поддерживается в Школе №830 г. Москва
#
# Developed specially for ALT Linux School.
# http://www.altlinux.org/LTSP
#
# Computer management and monitoring of users:
# - LTSP servers
# - Linux standalone clients
# - Windows standalone clients(only VNC)
#
# 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 2 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 gettext
import gobject
import threading
import time
import os
_ = gettext.gettext
####################################################################################################
# поток для комманд
class thread_command(threading.Thread):
def __init__(self, command):
threading.Thread.__init__(self)
self.stopthread = threading.Event()
self.cond = threading.Condition()
# список комманд
self.command = command
def run(self):
self.cond.acquire()
for line in self.command:
os.system(line)
self.cond.notify()
self.cond.release()
def stop(self):
self.stopthread.set()
####################################################################################################
# поток для функции + gobject
class thread_gfunc(threading.Thread, gobject.GObject):
__gsignals__ = {
"completed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
"data": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
}
def __init__(self, cfg, cursor, sensitive, func, *args):
threading.Thread.__init__(self)
gobject.GObject.__init__(self)
self.cond = threading.Condition()
self.stopthread = threading.Event()
self.func = func
self.args = args
self.cfg = cfg
self.cursor = cursor
self.sensitive = sensitive
def run(self):
if self.cursor:
from util import cursor_wait
cursor_wait(self.cfg, True)
if self.sensitive == False:
self.cfg.window.set_sensitive(False)
self.cond.acquire()
self.emit("data", self.run_func())
self.emit('completed')
# sleep на всякий случай
time.sleep(0.1)
self.cond.notify()
self.cond.release()
if self.cursor:
cursor_wait(self.cfg, False)
if self.sensitive == False:
self.cfg.window.set_sensitive(True)
def run_func(self):
self.func(*self.args)
def stop(self):
self.stopthread.set()
####################################################################################################
class _IdleObject(gobject.GObject):
def __init__(self):
gobject.GObject.__init__(self)
def emit(self, *args):
gobject.idle_add(gobject.GObject.emit, self, *args)
####################################################################################################
# поток для функции
class thread_func(threading.Thread):
def __init__(self, cfg, cursor, func, *args):
threading.Thread.__init__(self)
self.cond = threading.Condition()
self.stopthread = threading.Event()
self.func = func
self.args = args
self.cfg = cfg
self.cursor = cursor
def run(self):
if self.cursor:
from util import cursor_wait
cursor_wait(self.cfg, True)
self.cond.acquire()
self.run_func()
self.cond.notify()
self.cond.release()
if self.cursor:
cursor_wait(self.cfg, False)
def run_func(self):
self.func(*self.args)
def stop(self):
self.stopthread.set()
####################################################################################################