def _done(x, filename): try: fin = open(filename, 'rb') src = strng.to_text(fin.read()) fin.close() except: if output_func: output_func('error opening downloaded starter file') result.errback(Exception('error opening downloaded starter file')) return local_filename = os.path.join(GetLocalDir(), settings.WindowsStarterFileName()) bpio.backup_and_remove(local_filename) try: os.rename(filename, local_filename) lg.out(4, 'os_windows_update.download_and_replace_starter file %s was updated' % local_filename) except: lg.out(1, 'os_windows_update.download_and_replace_starter ERROR can not rename %s to %s ' % (filename, local_filename)) lg.exc() result.errback(Exception('can not rename the file ' + filename)) return python27dll_path = os.path.join(GetLocalDir(), 'python27.dll') if not os.path.exists(python27dll_path): lg.out(4, 'os_windows_update.download_and_replace_starter file "python27.dll" not found download from "%s" repo' % repo) url = settings.DefaultRepoURL(repo) + 'python27.dll' d = net_misc.downloadHTTP(url, python27dll_path) d.addCallback(_done_python27_dll, filename) d.addErrback(_fail, filename) return result.callback(1)
def _done(x, filename): try: fin = open(filename, 'rb') src = fin.read() fin.close() except: if output_func: output_func('error opening downloaded starter file') result.errback(Exception('error opening downloaded starter file')) return local_filename = os.path.join(GetLocalDir(), settings.WindowsStarterFileName()) bpio.backup_and_remove(local_filename) try: os.rename(filename, local_filename) lg.out(4, 'os_windows_update.download_and_replace_starter file %s was updated' % local_filename) except: lg.out(1, 'os_windows_update.download_and_replace_starter ERROR can not rename %s to %s ' % (filename, local_filename)) lg.exc() result.errback(Exception('can not rename the file ' + filename)) return python27dll_path = os.path.join(GetLocalDir(), 'python27.dll') if not os.path.exists(python27dll_path): lg.out(4, 'os_windows_update.download_and_replace_starter file "python27.dll" not found download from "%s" repo' % repo) url = settings.DefaultRepoURL(repo) + 'python27.dll' d = net_misc.downloadHTTP(url, python27dll_path) d.addCallback(_done_python27_dll, filename) d.addErrback(_fail, filename) return result.callback(1)
def download_and_replace_starter(output_func=None): repo, locationURL = misc.ReadRepoLocation() url = locationURL + settings.WindowsStarterFileName() lg.out(6, 'os_windows_update.download_and_replace_starter ' + str(url)) result = Deferred() def _done(x, filename): try: fin = open(filename, 'rb') src = strng.to_text(fin.read()) fin.close() except: if output_func: output_func('error opening downloaded starter file') result.errback(Exception('error opening downloaded starter file')) return local_filename = os.path.join(GetLocalDir(), settings.WindowsStarterFileName()) bpio.backup_and_remove(local_filename) try: os.rename(filename, local_filename) lg.out(4, 'os_windows_update.download_and_replace_starter file %s was updated' % local_filename) except: lg.out(1, 'os_windows_update.download_and_replace_starter ERROR can not rename %s to %s ' % (filename, local_filename)) lg.exc() result.errback(Exception('can not rename the file ' + filename)) return python27dll_path = os.path.join(GetLocalDir(), 'python27.dll') if not os.path.exists(python27dll_path): lg.out(4, 'os_windows_update.download_and_replace_starter file "python27.dll" not found download from "%s" repo' % repo) url = settings.DefaultRepoURL(repo) + 'python27.dll' d = net_misc.downloadHTTP(url, python27dll_path) d.addCallback(_done_python27_dll, filename) d.addErrback(_fail, filename) return result.callback(1) def _done_python27_dll(x, filename): lg.out(4, 'os_windows_update.download_and_replace_starter file %s was updated' % filename) result.callback(1) def _fail(x, filename): lg.out(1, 'os_windows_update.download_and_replace_starter FAILED') if output_func: try: output_func(x.getErrorMessage()) except: output_func('error downloading starter') try: os.remove(filename) except: lg.out(1, 'os_windows_update.download_and_replace_starter ERROR can not remove ' + filename) result.errback(Exception('error downloading starter')) fileno, filename = tmpfile.make('all', extension='.starter') os.close(fileno) d = net_misc.downloadHTTP(url, filename) d.addCallback(_done, filename) d.addErrback(_fail, filename) return result
def download_and_replace_starter(output_func=None): repo, locationURL = misc.ReadRepoLocation() url = locationURL + settings.WindowsStarterFileName() lg.out(6, 'os_windows_update.download_and_replace_starter ' + str(url)) result = Deferred() def _done(x, filename): try: fin = open(filename, 'rb') src = fin.read() fin.close() except: if output_func: output_func('error opening downloaded starter file') result.errback(Exception('error opening downloaded starter file')) return local_filename = os.path.join(GetLocalDir(), settings.WindowsStarterFileName()) bpio.backup_and_remove(local_filename) try: os.rename(filename, local_filename) lg.out(4, 'os_windows_update.download_and_replace_starter file %s was updated' % local_filename) except: lg.out(1, 'os_windows_update.download_and_replace_starter ERROR can not rename %s to %s ' % (filename, local_filename)) lg.exc() result.errback(Exception('can not rename the file ' + filename)) return python27dll_path = os.path.join(GetLocalDir(), 'python27.dll') if not os.path.exists(python27dll_path): lg.out(4, 'os_windows_update.download_and_replace_starter file "python27.dll" not found download from "%s" repo' % repo) url = settings.DefaultRepoURL(repo) + 'python27.dll' d = net_misc.downloadHTTP(url, python27dll_path) d.addCallback(_done_python27_dll, filename) d.addErrback(_fail, filename) return result.callback(1) def _done_python27_dll(x, filename): lg.out(4, 'os_windows_update.download_and_replace_starter file %s was updated' % filename) result.callback(1) def _fail(x, filename): lg.out(1, 'os_windows_update.download_and_replace_starter FAILED') if output_func: try: output_func(x.getErrorMessage()) except: output_func('error downloading starter') try: os.remove(filename) except: lg.out(1, 'os_windows_update.download_and_replace_starter ERROR can not remove ' + filename) result.errback(Exception('error downloading starter')) fileno, filename = tmpfile.make('other', '.starter') os.close(fileno) d = net_misc.downloadHTTP(url, filename) d.addCallback(_done, filename) d.addErrback(_fail, filename) return result