def reduce_silence(path, audio_file, name_audio): cut_times = 0 start_time = 0 audios_with_silence = [] new_audios = [] end_time = 0 silence_time = 0 score_final = 0 detect_speech(audio_file) text_file = open("result.txt", "r") for text_line in text_file.readlines(): text_line = text_line.rstrip() items = text_line.split(" ") time_mil_1_final = get_time_file(items[1]) time_mil_2_final = get_time_file(items[2]) if score_final != 0: silence_time = time_mil_1_final - score_final if silence_time > 1.0: end_time = score_final new_audio_file = split_audios_with_times(path, name_audio, start_time, end_time, audio_file, cut_times) new_audios.append(new_audio_file) audios_with_silence.append( mixed_silence(path, name_audio, new_audio_file, cut_times)) start_time = time_mil_1_final cut_times = cut_times + 1 score_final = time_mil_2_final audios_with_silence.append( split_audios_with_times(path, name_audio, start_time, 30, audio_file, cut_times + 1)) mixed_audio(path, name_audio, audios_with_silence, audio_file) utils.delete_files(new_audios) utils.delete_files(audios_with_silence) utils.delete_file("result.txt")
def delete(self): """ { file_name: replicate: } """ data = request.json file_name = data['file_name'] replicate = data['replicate'] if does_file_exist(file_name, FILE_SERVER_PATH): try: delete_file(file_name, FILE_SERVER_PATH) print('File deleted from ', SERVER_PORT) #Alert dir server if replicate == True: dir_port = get_port('dir_server') req = format_file_req(dir_port) data = { 'file_name': file_name, 'file_server_port': str(SERVER_PORT) } requests.delete(req, data=json.dumps(data), headers=cf.JSON_HEADER) except: print('Unable to delete file') abort(409)
def on_post(self, req, resp): cmd = req.get_param('cmd') result = {} if cmd == 'add': book = req.get_param('book') file_path = save_file(book) task_data = {'path': file_path} try: add_book_task.delay(task_data) result = {'msg': 'file putted in queue'} except Exception as e: result = {'error': str(e)} delete_file(file_path) elif cmd == 'create': result = create_index() elif cmd == 'delete': result = delete_index() elif cmd == 'count': result = count_items() elif cmd == 'search': q = req.get_param('q') result = search(q) elif cmd == 'search_advanced': q = req.get_param('q') result = search_advanced(q) resp.body = json.dumps(result) resp.status = falcon.HTTP_200
def send_file(filename): mimetype_value = 'audio/mp4' if Path(filename).suffix == ".m4a" else '' try: return send_from_directory(download_dir, filename, mimetype=mimetype_value) finally: delete_file(os.path.join('downloads', filename))
async def clearall(self): while len(self.songqueue): if self.songqueue[0].dir != '': delete_file(self.songqueue[0].dir) del self.songqueue[0] self.songqueue.clear() await self.sendPlaylist()
def clean_dir(base_directory): print('Cleaning all of the files in "%s".' % base_directory) files = get_files(base_directory) for f in files: file_name = '%s/%s' % (base_directory, f) print('Deleting file "%s".' % file_name) delete_file(file_name) print('Deleted %d file%s.' % (len(files), 's' if len(files) > 1 else ''))
def index(request: flask.Request): """HTTP Cloud Function Args: request (flask.Request): The request object. Returns: The response text, or any set of values that can be turned into a Response object using `make_response` """ # nonlocal MODEL try: if request.method == "GET": raise NotImplementedError("GET method not supported") headers = cors(request) form_result = parse_multipart(request) # Load image image_file = form_result["files"][0] filename, *args = image_file image = load_image(filename) # Load Model model = load_model("v1") score = model.predict(image).flatten() prediction = tf.where(score < THRESHOLD, 0, 1).numpy() prediction = prediction[0].item() score = score[0].item() prob_is_jollof = f"{round((1 - score) * 100, 2)}%" is_jollof = True if prediction == 0 else False delete_file(filename) return ( jsonify( data=dict( prediction=prediction, score=score, is_jollof=is_jollof, probability_is_jollof=prob_is_jollof, ), status="success", ), 200, headers, ) except Exception as e: print("Error: ", e) errorMessage = e.__str__() log_event(request, "error", errorMessage) return ( jsonify(error=errorMessage, status="error"), 500, )
def delete_ices_from_file_system(self, tmp_file=None): files = [ self.playlist_module_path, self.playlist_module_path + 'c', self.ices_config_path ] if tmp_file: files.append(tmp_file) for fname in files: if file_exists(fname): delete_file(fname)
async def stop(self): if self.running() or self.isPaused(): self.player.stop() delete_file(self.path) self.path = '' self.dur = 0 time.sleep(0.01) await self.sendDuration() else: print("Unable to skip - no song playing")
def send_file(filename): log.info(f'{datetime.now().strftime("[%H:%M:%S]")} {filename}') mimetype_value = 'audio/mp4' if os.path.splitext( filename)[1] == '.m4a' else '' try: return send_from_directory('conversions', filename, mimetype=mimetype_value, as_attachment=True) finally: delete_file(os.path.join('conversions', filename))
def compare_files(cfg, local_filename, server, remote_filename): result = False try: utils.delete_file(remote_filename) remote_api.run_cmd(cfg, server, 'chmod 777 '+remote_filename) remote_api.copy_file_from(cfg, server, remote_filename, remote_filename) result = filecmp.cmp(local_filename, remote_filename) except: pass finally: utils.delete_file(remote_filename) return result
def delete(): # TODO token与用户验证 topic_id = int(request.args.get('id')) tp = Topic.find(topic_id) print('删除 的 topic 是', tp) t = Theme.find(tp.theme_id) t.topic_num -= 1 t.save() delete_file(local_image_director, tp.banner_img) tp.delete() return redirect(url_for('theme.detail'))
def docs_generator(files_dir): files_path = glob(os.path.join(files_dir, "*.gz")) for gzip_file in files_path: file_name = os.path.basename(gzip_file).split(".")[ 0] # filename without extension ofp = os.path.join(files_dir, file_name) utils.extract_gzip(gzip_file, ofp) with open(ofp, encoding='utf-8') as fobj: yield fobj, file_name utils.delete_file(ofp)
def setupGAEngine(genome=G1DList.G1DList(), population_size=10, mutation_rate=0.02, crossover_rate=0.8, max_gens=2000, callback_functions=[], optimization_type='maximize', temp_fname='.__fitness_history__.csv', stop_fname='.stop'): ga = GSimpleGA.GSimpleGA(genome) ga.setPopulationSize(population_size) ga.setMinimax(Consts.minimaxType[optimization_type]) # ga.setCrossoverRate(crossover_probability) genome.mutator.set(Mutators.G1DListMutatorRealGaussian) # genome.initializator.set() # genome.mutator. # ga.setMutationRate(mutation_probability) fname = os.path.join(ga_folder(), temp_fname) utils.delete_file(fname) ga.stepCallback.set(lambda x: saveGenerationStats(x, temp_fname)) # ga.stepCallback.add(mockCallback) for func in callback_functions: ga.stepCallback.add(func) # fun = lambda x: callbackWrapper(x, callback_function) # def funcWrap(x): # __ = func() # return False # ga.stepCallback.add(copy.deepcopy(funcWrap)) # fname = os.path.join(ga_folder(), temp_fname) # adapter = DBAdapters.DBFileCSV(filename=fname, # identify="run_01", # frequency=1, reset=True) # ga.setDBAdapter(adapter) ga.selector.set(Selectors.GRankSelector) ga.setGenerations(max_gens) ga.setMutationRate(mutation_rate) ga.setCrossoverRate(crossover_rate) fname = os.path.join(ga_folder(), stop_fname) utils.delete_file(fname) ga.terminationCriteria.set(lambda x: checkStop(x, stop_fname)) pop = ga.getPopulation() pop.scaleMethod.set(Scaling.SigmaTruncScaling) print len(pop) # pop[0] = population_size * [0] return ga
def _execute_job(self, job_info): if self._mount_drive(): job = StoreFileJob(job_info.src_file_name, job_info.process_mne, job_info.tmp_path, job_info.compress, self._log) while job.is_running(): utils.wait(0.25) else: self._log.error('Write failed. USB flash drive is not mounted.') # Delete the temp file. StoreFileJob usually does it. utils.delete_file(job_info.tmp_path, self._log)
def delete(): id = int(request.args.get('id')) token = request.args.get('token') u = current_user() t = get_token(u.id) if t.content == token: flash_token(t) b = Theme.find(id) log('删除 theme 用户是', u, b) delete_file(local_image_director, b.banner_img) Theme.delete(id) return redirect(url_for('board.edit')) else: abort(403)
def add_malware(request): if request.method == 'POST': form = AddMalwareForm(request.POST, request.FILES) if form.is_valid(): file_path = store_sample(request.FILES['file'].read()) obj = File(file_path=file_path) tags = request.POST.get('tags') orig_url = request.POST.get('url') file_name = request.FILES['file'].name if isinstance(obj, File): malware_entry = malware(md5=obj.get_md5(), crc32=obj.get_crc32(), sha1=obj.get_sha1(), sha256=obj.get_sha256(), sha512=obj.get_sha512(), file_size=obj.get_size(), file_type=obj.get_type(), ssdeep=obj.get_ssdeep(), orig_url=orig_url, file_name=file_name) malware_entry.save() if store_encoded: encode_sample(file_path) delete_file(file_path) if tags: tags = tags.strip() if "," in tags: tags = tags.split(",") else: tags = tags.split(" ") for t in tags: t = t.strip().lower() if t == "": continue if tag.objects.filter(tag=t).exists(): malware_entry.tags.add(tag.objects.get(tag=t)) continue malware_entry.tags.add(tag.objects.create(tag=t)) return HttpResponse( jsonize({"message": file_name + " added to repository"})) else: return HttpResponse('METHOD not supported for URL')
def restore(self, filename="", silent=False): '''restore skin settings from file''' if not filename: filename = self.get_restorefilename() progressdialog = None if not silent: progressdialog = xbmcgui.DialogProgress( self.addon.getLocalizedString(32006)) progressdialog.create(self.addon.getLocalizedString(32007)) if filename and xbmcvfs.exists(filename): # create temp path temp_path = self.create_temp() if not filename.endswith("zip"): # assume that passed filename is actually a skinsettings file skinsettingsfile = filename else: # copy zip to temp directory and unzip skinsettingsfile = temp_path + "guisettings.txt" if progressdialog: progressdialog.update(0, "unpacking backup...") zip_temp = u'%sskinbackup-%s.zip' % ( ADDON_DATA, datetime.now().strftime('%Y-%m-%d-%H-%M')) copy_file(filename, zip_temp, True) unzip_fromfile(zip_temp, temp_path) delete_file(zip_temp) # copy skinshortcuts preferences self.restore_skinshortcuts(temp_path) # restore any custom skin images or themes for directory in ["custom_images/", "themes/"]: custom_images_folder = u"special://profile/addon_data/%s/%s" % ( xbmc.getSkinDir(), directory) custom_images_folder_temp = temp_path + directory if xbmcvfs.exists(custom_images_folder_temp): for file in xbmcvfs.listdir( custom_images_folder_temp)[1]: xbmcvfs.copy(custom_images_folder_temp + file, custom_images_folder + file) # restore guisettings if xbmcvfs.exists(skinsettingsfile): self.restore_guisettings(skinsettingsfile, progressdialog) # cleanup temp recursive_delete_dir(temp_path) progressdialog.close() if not silent: xbmcgui.Dialog().ok(self.addon.getLocalizedString(32006), self.addon.getLocalizedString(32009))
def add_malware(request): if request.method == 'POST': form = AddMalwareForm(request.POST, request.FILES) if form.is_valid(): file_path=store_sample(request.FILES['file'].read()) obj = File(file_path=file_path) tags = request.POST.get('tags') orig_url = request.POST.get('url') file_name = request.FILES['file'].name if isinstance(obj, File): malware_entry = malware(md5=obj.get_md5(), crc32=obj.get_crc32(), sha1=obj.get_sha1(), sha256=obj.get_sha256(), sha512=obj.get_sha512(), file_size=obj.get_size(), file_type=obj.get_type(), ssdeep=obj.get_ssdeep(), orig_url=orig_url, file_name=file_name) malware_entry.save() if store_encoded: encode_sample(file_path) delete_file(file_path) if tags: tags = tags.strip() if "," in tags: tags = tags.split(",") else: tags = tags.split(" ") for t in tags: t = t.strip().lower() if t == "": continue if tag.objects.filter(tag=t).exists(): malware_entry.tags.add(tag.objects.get(tag=t)) continue malware_entry.tags.add(tag.objects.create(tag=t)) return HttpResponse(jsonize({"message" : file_name + " added to repository"})) else: return HttpResponse('METHOD not supported for URL')
def do_task(task_data): """ Add book to index task. Delete file after adding. :param task_data: contain path to file :type task_data: dict :return: result of book addition :rtype: dict """ path = task_data['path'] result = add_book(path) delete_file(path) return result
def choose_to_delete(self, file_name): choice = input( Console.yellow(f'Do you wish to delete {file_name}? (N/y) > ')) choice = choice.strip().lower() not_valid = choice not in ['n', 'y'] if not_valid: Console.error('Please choose a valid input!') time.sleep(.2) self.choose_to_delete(file_name) if choice == 'n': Console.log('Bye!') return Console.info(f'Deleting {file_name}...') delete_file(file_name)
async def main(loop): connection = await aio_pika.connect_robust(settings.RABBITMQ_HOST, loop=loop) queue_name = settings.PRECESS_IMG_QUEUE async with connection: # Creating channel channel = await connection.channel() # Declaring queue queue = await channel.declare_queue(queue_name, auto_delete=True) async for message in queue: with message.process(): data = json.loads(message.body.decode('utf-8')) aws_client = AWSWrapper() task_id = data['task_id'] task = Task(loop, id=task_id) await task.set_status('Started downloading') try: file_path = await aws_client.get_file(**data['aws_data']) except Exception as e: await task.set_status("Download error") raise e else: await task.set_status("Started image processing") try: result_future = canny_task.delay(file_path) canny_img_path = await wait_for_done(result_future) except Exception as e: await task.set_status("Processing error") raise e else: delete_file(file_path) data['aws_data']['file_path'] = canny_img_path data['key'] = canny_img_path.split('/')[-1] await task.set_status("Started uploading canny image") try: resp = await aws_client.upload_huge( **data['aws_data']) await task.set_status("Canny edge image uploaded") except Exception as e: await task.set_status("Error uploading") raise e delete_file(canny_img_path)
def running(self): if (self.player.get_state() == vlc.State.Playing) or (self.player.get_state() == vlc.State.Opening): return True else: if (self.player.get_state() == vlc.State.Paused) or (self.player.get_state() == vlc.State.Stopped): return False self.player.stop() if self.path != '' and os.path.exists(self.path): print("deleting") delete_file(self.path) self.path = '' self.dur = 0 return False
def handle_music_to_voice_converter(update: Update, context: CallbackContext) -> None: message = update.message context.bot.send_chat_action( chat_id=update.message.chat_id, action=ChatAction.RECORD_AUDIO ) user_data = context.user_data input_music_path = user_data['music_path'] voice_path = f"{user_data['music_path']}.ogg" lang = user_data['language'] user_data['current_active_module'] = 'mp3_to_voice_converter' # TODO: Make modules a dict os.system( f"ffmpeg -i -y {input_music_path} -ac 1 -map 0:a -codec:a opus -b:a 128k -vbr off \ {input_music_path}" ) os.system(f"ffmpeg -i {input_music_path} -c:a libvorbis -q:a 4 {voice_path}") start_over_button_keyboard = generate_start_over_keyboard(lang) context.bot.send_chat_action( chat_id=update.message.chat_id, action=ChatAction.UPLOAD_AUDIO ) try: with open(voice_path, 'rb') as voice_file: context.bot.send_voice( voice=voice_file, duration=user_data['music_duration'], chat_id=message.chat_id, caption=f"🆔 {BOT_USERNAME}", reply_markup=start_over_button_keyboard, reply_to_message_id=user_data['music_message_id'] ) except TelegramError as error: message.reply_text( translate_key_to(lp.ERR_ON_UPLOADING, lang), reply_markup=start_over_button_keyboard ) logger.exception("Telegram error: %s", error) delete_file(voice_path) reset_user_data_context(context)
def grade_update(controller_path, link_costs, link_update, updated_link_costs, cfg): cntrl_port = utils.random_port() remote_api.init_remote_assignment(cfg, cntrl_port) ROUTERS, ROUTER_ID_MAPPING = utils.gen_topology(link_costs, cntrl_port) utils.run_cmd([controller_path, '-t', 'topology', '-i', '1', '-o', 'response.pkt']) os.system('rm response.pkt*') #cleanup sleep(3) utils.run_cmd([controller_path, '-t', 'topology', '-u', ROUTER_ID_MAPPING[link_update[0]], ROUTER_ID_MAPPING[link_update[1]], str(link_update[2]), '-o', 'response.pkt']) os.system('rm response.pkt*') #cleanup sleep(3) success = False for src in ROUTERS: success = False utils.run_cmd([controller_path, '-t', 'topology', '-r', str(src.id), '-o', 'response.pkt']) try: with open('response.pkt', 'r') as f: header = struct.unpack('!4sBBH', f.read(8)) controller_ip, cntrl_code, resp_code, payload_len = utils.parse_response_header(header) payload = f.read(payload_len) os.system('hexdump -C response.pkt') if payload_len != len(ROUTERS)*8: break r_table = parse_routing_table(payload) #Build expected routing table expected_r_table = [] for dst in ROUTERS: expected_cost, nxt_hop = get_shortest_path(ROUTER_ID_MAPPING[str(src.id)], ROUTER_ID_MAPPING[str(dst.id)], updated_link_costs, ROUTER_ID_MAPPING) if expected_cost == 65535: nxt_hop = 65535 expected_r_table.append( [dst.id, nxt_hop, expected_cost] ) if cmp(sorted(r_table), sorted(expected_r_table)) == 0: success = True else: success = False break except: success = False break utils.delete_file('response.pkt') #cleanup remote_api.cleanup(cfg) utils.cleanup() return success
def post(self): '''Adds file to cache, performed on reads, also updates a file in the cache if it exists, performed on writes { 'file_name' 'file_content' 'file_version' } ''' print('post received, cache size is: ', file_map.count()) if(not request.is_json): abort(400) data = request.json file_content = data['file_content'] file_name = data['file_name'] file_version = data['file_version'] #check if the file exists on the cache #check if the cache is full, if so, boot the most recently used #Create a the file in the cache #Add it to the timestamp map if file_map.find_one({'file_name': file_name}) == None: if cache_is_full(): LRU = get_LRU_file() file_map.remove({'file_name': LRU}) delete_file(LRU, cf.CACHE_FILE_PATH) try: update_file(file_name, cf.CACHE_FILE_PATH, file_content) file_map.update_one( {'file_name': file_name}, { '$set':{ 'file_name': file_name, 'timestamp': datetime.now(), 'file_version': file_version } }, upsert=True ) except: abort(403)
def flush_old_records(self): '''deletes old runs, associated backup files and orders (deleting runs delete cascade associated orders)''' old_runs = self._get_old_runs() try: for run in old_runs: orders_in_run = self.session.query(Order).filter_by( run_obj=run).all() logging.info( f'Deleting {len(orders_in_run)} orders associated with old {run} and backup file: {run.fpath}' ) delete_file(run.fpath) self.session.delete(run) self.session.commit() except Exception as e: logging.warning( f'Unexpected err while flushing old records from db inside flush_old_records. Err: {e}. Last recorded run {run}' ) self.session.rollback()
def handle_new_blob_event(event: Event): format: FieldStorageContainers = event.data.field # Download the raw file from the common BlobStorage filepath = BlobService(event.data.field).download_blob(event.data.filepath) file = StreamFile(filepath, format) # Decimate the file file.decimate() # Upload the decimated file to AzureFiles uploaded_path = az_files_service.upload_file(file.decimated_path) # Add new messages to the queues convert_queue.send_message({"format": format.value, "path": uploaded_path}) # Cleanup delete_file(filepath) delete_file(file.decimated_path) return f"Successfully decimated {event.data.url} and uploaded result to FileStorage"
def action(self): ssid = self.entry_username.get() self.entry_username.delete(0, len(ssid)) passwd = self.password.get() self.password.delete(0, len(passwd)) # check ssid length if 0 == len(ssid): txt = "El SSID introducido es incorrecto" self.controller.show_info(txt, True) # execute uiid script update_wifi_configuration(ssid, passwd) # delete file delete_file(WIFI_TMP_CONFIG_FILE) # show next frame txt = "Wifi actualizada a {ssid}" self.controller.show_info(txt.format(ssid=ssid))
async def remove(self, _index, _title): index = _index - 1 start = _title.find(']') + 2 title = _title[start:] try: playlistTitle = self.songqueue[index].title del_path = self.songqueue[index].dir except IndexError: print('More than one user removed a song at the same time') return if title.strip() == playlistTitle.strip(): del self.songqueue[index] await self.sendPlaylist() if del_path != '': delete_file(del_path) else: print('More than one user removed a song at the same time') return
def model_form_upload(request): error = {} if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() file_name = Document.objects.all().order_by( '-uploaded_at').first().document.name file_type = form.cleaned_data['file_type'] if (TRANSACTION in file_name.lower() and FILE_TYPE.get(TRANSACTION) != file_type) or (BALANCE in file_name.lower() and FILE_TYPE.get(BALANCE) != file_type): error = { 'msg': 'Looks like you selected a wrong file type. Please verify that the file type is correct.' } delete_file(file_name) return render(request, 'home/file_upload.html', { 'form': form, 'error': error }) form.save() file_path = '{media}/{file_name}'.format(media=settings.MEDIA_ROOT, file_name=file_name) try: populate_table(request, file_path, file_type) except ValueError: error = { 'msg': 'Looks like you selected a wrong file type. Please verify that the file type is correct.' } delete_file(file_name) return render(request, 'home/file_upload.html', { 'form': form, 'error': error }) return redirect('index') else: form = DocumentForm() return render(request, 'home/file_upload.html', {'form': form})
except OSError, e: if e.errno != 17: raise if os.path.isfile(new_fullpath): # If the destination exists, raise exception unless force is True if not force: raise OSError("File %s already exists, " "not forcefully moving %s" % (new_fullpath, old_path)) if same_partition(old_path, new_dir): if always_copy: # Same partition, but forced to copy log.debug("copy %s to %s" % (old_path, new_fullpath)) shutil.copyfile(old_path, new_fullpath) else: # Same partition, just rename the file to move it log.debug("move %s to %s" % (old_path, new_fullpath)) os.rename(old_path, new_fullpath) else: # File is on different partition (different disc), copy it log.debug("copy %s to %s" % (old_path, new_fullpath)) shutil.copyfile(old_path, new_fullpath) if always_move: # Forced to move file, we just trash old file log.debug("Deleting %s" % (old_path)) delete_file(old_path) return new_fullpath
def install_item(self, current_item, dispose_dia = True): post_ga_event('install_item','artifact_%s' % current_item.name) folder = '%s/%s/' % (dir_name, current_item.folder) if not utils.check_if_already_updated_with_delta(dir_name, current_item.name, current_item.version) or not os.path.exists(folder): try: log_dia_info('Getting full entry %s' % current_item.name) retries = 0 nof_retries = 3 while retries < nof_retries: try: utils.get_file(current_item.basedir,utils.get_storage_location(current_item.file),current_item.file,current_item.name) if os.path.exists(folder): log_dia_info('Deleting current folder %s (this may take a while, please be patient)' % folder) utils.delete_folder('%s/%s/' % (dir_name, current_item.folder)) if was_dia_cancelled(): log_dia_info('Downloaded for %s was cancelled' % current_item.name) if dispose_dia: wx.CallAfter(dispose_dialog) return log_dia_info('Downloaded %s' % current_item.name) log_dia_info('Extracting files %s' %dir_name) dia_tick() utils.extract_file(utils.get_storage_location(current_item.file), dir_name,current_item,True) dia_tick() break; except InvalidZipFileException: post_ga_event('install_item_invalid_zip','artifact_%s' % current_item.name) log_info('Invalid zifile, delete and retry') utils.delete_file(utils.get_storage_location(current_item.file)) if retries == nof_retries-1: raise retries+=1 if utils.get_boolean_user_setting(delete_files_after_install): utils.delete_file(utils.get_storage_location(current_item.file)) if was_dia_cancelled(): if dispose_dia: wx.CallAfter(dispose_dialog) return log_dia_info('Update db') utils.update_db(dir_name, current_item.name, current_item.version) current_item.not_installed = False log_dia_info('Done extracting full entry %s at location %s' % (current_item.name, dir_name)) log_dia_info('Install done') if dispose_dia: wx.CallAfter(dispose_dialog) except InvalidZipFileException as e: utils.delete_folder('%s/%s/' % (dir_name, current_item.folder)) log_dia_info('Install failed du to error during fetch or unzip') if dispose_dia: wx.CallAfter(dispose_dialog_fail,e.message) except FtpOverloadedException as e: log_dia_info('Too many users, please try agin in a while') if dispose_dia: wx.CallAfter(dispose_dialog_fail,'Too many users, please try later') except: utils.delete_folder('%s/%s/' % (dir_name, current_item.folder)) log_dia_info('Install failed due to unknown error') if dispose_dia: wx.CallAfter(dispose_dialog_fail,'Unknown error %s:' % sys.exc_info()[0]) finally: update_tree_view(self) else: if dispose_dia: wx.CallAfter(dispose_dialog)
def update_item(self, item,dispose_dia = True): post_ga_event('update_item','artifact_%s' % item.name) try: if item.create_delta: for deltaitem in item.deltas: if not utils.check_if_already_updated_with_delta(dir_name, item.name, deltaitem.version): log_dia_info('Updating file %s' % deltaitem.file) retries = 0 nof_retries = 3 while retries < nof_retries: utils.get_file(utils.resolve_delta_dir(item),utils.get_storage_location(deltaitem.file),deltaitem.file,item.name) dia_tick() if was_dia_cancelled(): log_dia_info('Cancelling...') break if item.dynamic_import: utils.delete_folder(utils.user_file_cache_dyn) utils.create_dir(utils.user_file_cache_dyn) try: if was_dia_cancelled(): log_dia_info('Cancelling...') break utils.extract_file(utils.get_storage_location(deltaitem.file), utils.user_file_cache_dyn,item,True) if was_dia_cancelled(): log_dia_info('Cancelling...') break dynamic_import.move_in_place(utils.user_file_cache + 'dyn/%s/' % item.folder, '%s/%s/' % (dir_name, item.folder)) if was_dia_cancelled(): log_dia_info('Cancelling...') update_tree_view(self) break utils.update_db(dir_name, item.name, deltaitem.version) utils.delete_folder(utils.user_file_cache + 'dyn/%s/' % item.folder) item.needs_update = False update_tree_view(self) dia_tick() break except FtpOverloadedException: post_ga_event('update_item_ftp_overload','artifact_%s' % deltaitem.file) raise except InvalidZipFileException as e: post_ga_event('update_item_invalid_zip','artifact_%s' % deltaitem.file) utils.delete_file(utils.get_storage_location(deltaitem.file)) if retries == nof_retries-1: raise else: log_info('Unpacking %s into %s' % (item.name, dir_name)) try: if was_dia_cancelled(): log_dia_info('Cancelling...') break utils.extract_file(utils.get_storage_location(deltaitem.file), dir_name,item,False) if was_dia_cancelled(): log_dia_info('Cancelling...') update_tree_view(self) break utils.update_db(dir_name, item.name, deltaitem.version) target_folder = dir_name + '/' + item.folder log_dia_info('Updated %s with deltafile %s at location %s' % (item.name,deltaitem.file,target_folder)) item.needs_update = False update_tree_view(self) dia_tick() if utils.get_boolean_user_setting(delete_files_after_install): utils.delete_file(utils.get_storage_location(deltaitem.file)) break except FtpOverloadedException: post_ga_event('update_item_ftp_overload','artifact_%s' % deltaitem.file) raise except InvalidZipFileException: post_ga_event('update_item_invalid_zip','artifact_%s' % deltaitem.file) log_dia_info('Invalid deltazifile, delete and retry') utils.delete_file(utils.get_storage_location(deltaitem.file)) if retries == nof_retries-1: raise retries += 1 if dispose_dia: wx.CallAfter(dispose_dialog) except FtpOverloadedException: if dispose_dia: wx.CallAfter(dispose_dialog_fail,'Too many users right now, please try again later') except InvalidZipFileException as e: if dispose_dia: wx.CallAfter(dispose_dialog_fail,e.message) except: if dispose_dia: wx.CallAfter(dispose_dialog_fail,'Unknown error %s:' % sys.exc_info()[0]) finally: update_tree_view(self)
if args.verbose: print e if '< Status: 302 Found' in e: print 'OK' else: msg = 'Problem with download, possibly missing token?' if not args.verbose: msg += ' Use -v for detailed error' sys.exit(msg) cmd = 'tar --strip-components 1 --show-transformed-names -xzvf tmp.tgz' run_cmd(cmd) delete_file('tmp.tgz') if args.build: print 'Building {} ...'.format(dir_str) # checking path if not os.path.exists(dir_path) or not os.listdir(dir_path): sys.exit('You need to download first!') # checking changelog file changelog_file = os.path.join(dir_path, 'debian/changelog') if not os.path.exists(changelog_file): print 'No changelog, build skipped' continue # checking root
download_url = line.split('Filename: ')[1] full_download_url = 'http://80.243.184.98/archive/' + download_url download_file = False print 'Downloading {} {}'.format(p, download_url) cmd = 'curl -L -v -o tmp.deb {url}'.format(url=full_download_url) _, e, _ = run_cmd(cmd) if '< HTTP/1.1 200 OK' in e: print 'download OK' else: print e sys.exit('Problem with download') cmd = 'gdebi tmp.deb -n -q -o APT::Install-Recommends=0 -o APT::Install-Suggests=0' o, e, rc = run_cmd(cmd) if rc == 0: print 'install OK' else: print o, e, rc sys.exit('Problem with gdebi') print delete_file('tmp.deb')