78
78
#------------------------------------------------------------------------------
79
79
80
80
_CurrentProcess = None
81
- _FirstRunDelay = 1200
82
- _LoopInterval = 3600 * 6
81
+ _FirstRunDelay = 60 * 2
82
+ _LoopInterval = 60 * 3 # 60*60 *6
83
83
_ShedulerTask = None
84
84
85
85
#------------------------------------------------------------------------------
86
86
87
87
88
88
def write2log (txt ):
89
- out_file = open (settings .UpdateLogFilename (), 'a' )
90
- out_file .write (strng .to_text (txt ))
91
- out_file .close ()
89
+ try :
90
+ out_file = open (settings .UpdateLogFilename (), 'a' )
91
+ out_file .write (strng .to_text (txt ))
92
+ out_file .close ()
93
+ except :
94
+ pass
92
95
93
96
94
97
#------------------------------------------------------------------------------
@@ -129,13 +132,13 @@ def sync_callback(result):
129
132
events .send ('source-code-update-error' , data = dict (result = result ))
130
133
131
134
try :
132
- from bitdust .system import tray_icon
135
+ # from bitdust.system import tray_icon
133
136
if result == 'error' :
134
137
# tray_icon.draw_icon('error')
135
138
# reactor.callLater(5, tray_icon.restore_icon)
136
139
return
137
140
elif result == 'code-fetched' :
138
- tray_icon .set_icon ('updated' )
141
+ # tray_icon.set_icon('updated')
139
142
return
140
143
except :
141
144
pass
@@ -178,48 +181,56 @@ def sync(callback_func=None, update_method='rebase'):
178
181
`git rebase origin/master -v` or `git reset --hard origin/master`
179
182
180
183
"""
181
- src_dir_path = bpio .getExecutableDir ()
184
+ src_dir_path = os . path . abspath ( os . path . join ( bpio .getExecutableDir (), '..' ) )
182
185
expected_src_dir = os .path .join (deploy .default_base_dir_portable (), 'src' )
186
+ if _Debug :
187
+ lg .args (_DebugLevel , update_method = update_method , src_dir = src_dir_path , expected_src_dir = expected_src_dir )
183
188
if bpio .portablePath (src_dir_path ) != bpio .portablePath (expected_src_dir ):
184
189
if _Debug :
185
190
lg .out (_DebugLevel , 'git_proc.sync SKIP, non standard sources location: %r' % src_dir_path )
186
191
return
187
192
188
193
def _reset_done (response , error , retcode , result ):
194
+ if _Debug :
195
+ lg .args (_DebugLevel , retcode = retcode , error = error , response = response )
189
196
if callback_func is None :
190
197
return
198
+ if retcode != 0 :
199
+ result = 'sync-error'
200
+ else :
201
+ if result == 'new-code' :
202
+ result = 'code-fetched'
203
+ else :
204
+ result = 'up-to-date'
191
205
callback_func (result )
192
206
193
207
def _rebase_done (response , error , retcode , result ):
208
+ if _Debug :
209
+ lg .args (_DebugLevel , retcode = retcode , error = error , response = response )
194
210
if callback_func is None :
195
211
return
196
212
if retcode != 0 :
197
213
result = 'sync-error'
198
214
else :
199
- if response .count (b'Changes from' ) or response .count (b'Fast-forwarded' ):
215
+ if result == 'new-code' or response .count (b'Changes from' ) or response .count (b'Fast-forwarded' ):
200
216
result = 'code-fetched'
201
217
else :
202
218
result = 'up-to-date'
203
219
callback_func (result )
204
220
205
221
def _fetch_done (response , error , retcode ):
222
+ if _Debug :
223
+ lg .args (_DebugLevel , retcode = retcode , error = error , response = response )
206
224
if retcode != 0 :
207
225
if callback_func :
208
226
callback_func ('sync-error' )
209
227
return
210
- result = 'sync-error'
211
- if response .count (b'Unpacking' ) or \
212
- (response .count (b'master' ) and response .count (b'->' )) or \
213
- response .count (b'Updating' ) or \
214
- response .count (b'Receiving' ) or \
215
- response .count (b'Counting' ):
228
+ result = 'fetch-ok'
229
+ if response .count (b'Unpacking' ) or (response .count (b'master' ) and response .count (b'->' )) or \
230
+ response .count (b'Updating' ) or response .count (b'Receiving' ) or response .count (b'Counting' ):
216
231
result = 'new-code'
217
232
if update_method == 'reset' :
218
- run ([
219
- 'reset' ,
220
- '--hard' ,
221
- 'origin/master' ,
222
- ], callback = lambda resp , err , ret : _reset_done (resp , err , ret , result ))
233
+ run (['reset' , '--hard' , 'origin/master' ], callback = lambda resp , err , ret : _reset_done (resp , err , ret , result ))
223
234
elif update_method == 'rebase' :
224
235
run (['rebase' , 'origin/master' , '-v' ], callback = lambda resp , err , ret : _rebase_done (resp , err , ret , result ))
225
236
else :
@@ -234,7 +245,7 @@ def _fetch_done(response, error, retcode):
234
245
def run (cmdargs , base_dir = None , git_bin = None , env = None , callback = None ):
235
246
if _Debug :
236
247
lg .out (_DebugLevel , 'git_proc.run' )
237
- base_dir = base_dir or bpio .getExecutableDir ()
248
+ base_dir = base_dir or os . path . abspath ( os . path . join ( bpio .getExecutableDir (), '..' ) )
238
249
if bpio .Windows ():
239
250
cmd = [
240
251
'git' ,
0 commit comments