manager.py
8.31 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Tue Sep 27 12:15:56 2011
import os
import wx
import i18n
_ = i18n.language.ugettext #use ugettext instead of getttext to avoid unicode errors
from dfs.config import Config
from client import run_upload, run_download, run_download_prim, run_checkout, run_return, run_check_stats
from MainFrame import MainFrame
import utils
import const
from ready import Ready
from dir_cache import DirCache
from log_thread import LogThread
from footprints import FootPrints
class FileManager(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main_frame = MainFrame(None, -1, "")
self.SetTopWindow(self.main_frame)
self.main_frame.Show()
# Custom code
self.main_frame.set_manager(self)
self.curr_dir = None
self.config = None
self.selection = None
self.connected = False
self.dir_cache = DirCache(const.dir_cache_name, size=5)
self.refresh_thread = utils.RefreshThread(self, delay=2)
self.refresh_thread.start()
utils.fill_dir_menu(self.main_frame, self.dir_cache.get())
# End custom code
return 1
def reconf_directory(self):
if not self.curr_dir:
return
config_path = const.path(self.curr_dir, const.config_name)
if utils.create_dir_config( config_path, self.main_frame
, config=self.config ):
self.config = Config(config_path)
self.refresh()
def set_directory(self, path):
config_path = const.path(path, const.config_name)
if not os.path.exists(config_path):
if not utils.create_dir_config(config_path, self.main_frame):
return
self.config = Config(config_path)
self.ready = Ready(const.path(path, const.ready_name))
self.curr_dir = path
self.dir_cache.add(path)
self.main_frame.SetTitle(path)
self.refresh()
def begin_conn(self):
if not self.curr_dir:
wx.MessageBox(_('Directory not set'), _('Info'))
return False
if self.connected:
wx.MessageBox(_('Another operation running'), _('Info'))
return False
self.connected = True
return True
def end_conn(self, op_result):
self.connected = False
def upload(self, files, checkin=False):
if not self.begin_conn():
return
def on_end(result):
self.end_conn(result)
if checkin:
return
if result == True:
prints = self.footprints()
for file_name in files:
prints.renew(file_name)
prints.save()
logger = LogThread( text_ctrl=self.main_frame.log_ctrl
, target=run_upload
, args=( self.config["login"]
, self.config["passwd"]
, const.conn_host
, const.conn_port
, const.conn_cert
, files
, self.curr_dir
, self.config["extensions"].split()
, checkin )
, on_end=on_end )
logger.start()
def download(self, n):
if not self.begin_conn():
return
logger = LogThread( text_ctrl=self.main_frame.log_ctrl
, target=run_download
, args=( self.config["login"]
, self.config["passwd"]
, const.conn_host
, const.conn_port
, const.conn_cert
, n
, self.curr_dir )
, on_end=self.end_conn )
logger.start()
def download_prim(self, n):
if not self.begin_conn():
return
logger = LogThread( text_ctrl=self.main_frame.log_ctrl
, target=run_download_prim
, args=( self.config["login"]
, self.config["passwd"]
, const.conn_host
, const.conn_port
, const.conn_cert
, n
, self.curr_dir )
, on_end=self.end_conn )
logger.start()
def checkout(self):
if not self.begin_conn():
return
def on_end(result):
self.end_conn(result)
if result == True:
prints = self.footprints()
files_before = prints.prints.keys()
prints.renew_all()
prints.save()
logger = LogThread( text_ctrl=self.main_frame.log_ctrl
, target=run_checkout
, args=( self.config["login"]
, self.config["passwd"]
, const.conn_host
, const.conn_port
, const.conn_cert
, self.curr_dir
, self.config["extensions"].split() )
, on_end=on_end )
logger.start()
def return_files(self, files, reason):
if not self.begin_conn():
return
def on_end(result):
self.end_conn(result)
logger = LogThread( text_ctrl=self.main_frame.log_ctrl
, target=run_return
, args=( self.config["login"]
, self.config["passwd"]
, const.conn_host
, const.conn_port
, const.conn_cert
, files
, reason
, self.curr_dir
, self.config["extensions"].split()
)
, on_end=on_end )
logger.start()
def footprints(self):
return FootPrints( const.path(self.curr_dir, const.footprints_name)
, self.curr_dir
, self.config["extensions"].split() )
def refresh(self):
if self.curr_dir is None:
return
ready = self.ready.get_entries()
extensions = self.config["extensions"].split()
footprints = self.footprints()
footprints.refresh()
data = utils.normal_entries(
self.curr_dir,
extensions,
ready,
footprints)
shown = self.main_frame.files_list.shown_data()
if utils.differ(data, shown):
print "Data changed !"
self.main_frame.files_list.show(data)
footprints.save()
data = utils.super_entries(
self.curr_dir,
extensions,
ready,
footprints)
shown = self.main_frame.super_files_list.shown_data()
if utils.differ(data, shown):
print "Data changed !"
self.main_frame.super_files_list.show(data)
footprints.save()
def check_stats(self):
if not self.begin_conn():
return
def on_end(result):
self.end_conn(result)
logger = LogThread( text_ctrl=self.main_frame.log_ctrl
, target=run_check_stats
, args=( self.config["login"]
, self.config["passwd"]
, const.conn_host
, const.conn_port
, const.conn_cert )
, on_end=on_end )
logger.start()
# end of class FileManager
if __name__ == "__main__":
manager = FileManager(0)
manager.MainLoop()
manager.refresh_thread.exitFlag = True