How to use clean_tmp_files method in avocado

Best Python code snippet using avocado_python

SectionerXMLDataLoading.py

Source:SectionerXMLDataLoading.py Github

copy

Full Screen

1# Copyright (c) 2016-2017 Fred Hutchinson Cancer Research Center2#3# Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.04#5import logging6from os import listdir7import os8from os.path import isfile, join9import logging10from DataLoading.AbstractClasses import AbstractDataLoader11import xmltodict12from DataLoading.DataClasses import Document13from NERPreprocessing.DocumentPreprocessing import UnformattedDocumentPreprocessor14class SectionerXMLDataLoader(AbstractDataLoader):15 def __init__(self,xml_dir, clean_tmp_files=True):16 super(SectionerXMLDataLoader, self).__init__()17 self.xml_dir = xml_dir18 self.clean_tmp_files = clean_tmp_files19 self.logger = logging.getLogger(__name__)20 def get_annotations(self):21 '''22 Public-pacing annotation getter. This should be used as info only, not for processing, as annotation formats23 differ depending on the source so we cannot garentee any standard format at tis point.24 The document objects retrieved by get_docs() will contain standardized annotations for downstream25 processing.26 :return: A list of dictionaries of {attrib_type<string>:value<string|int>}27 '''28 self.logger.warning("The XML data loader does not load annotations: It can only read XML documents in the bioNLP format")29 raise NotImplementedError("The XML data loader does not load annotations: It can only read XML documents in the bioNLP format")30 def preprocess(self, spacy_model):31 '''32 Using attributes from self, loads documents from XML into memory33 :return: True if load() succeeded, False otherwise34 '''35 onlyfiles = [f for f in listdir(self.xml_dir) if isfile(join(self.xml_dir, f))]36 all_docs = dict()37 for doc in onlyfiles:38 doc_id = self._get_doc_id(doc)39 try:40 with open(join(self.xml_dir, doc), "rb") as f:41 xml_obj = xmltodict.parse(f.read())42 full_text = xml_obj['AnnotatedDocument']['DocumentText']43 annotation_sections = xml_obj['AnnotatedDocument']['TextAnnotationSet']['TextAnnotation']44 all_sections = dict()45 for section in annotation_sections:46 current_section = {47 'end':section['@End'],48 'start': section['@Start'],49 'type': section['@Type'],50 'text': section['Text'],51 'label':section['FeatureSet']['Feature']['#text']52 }53 if current_section['label'] not in all_sections:54 all_sections[current_section['label']] = list()55 all_sections[current_section['label']].append(current_section)56 doc_obj = Document(doc_id, full_text)57 doc_obj.set_sections(all_sections)58 all_docs[doc_id]=doc_obj59 except Exception as e:60 self.logger.warning("Failed to load XML sectioned documents for document_id: " + doc_id)61 doc_obj = Document(doc_id, full_text)62 all_docs[doc_id]=doc_obj63 #Run loaded documents through preprocessor to get sentence segmentation, indx alignment, etc64 UnformattedDocumentPreprocessor(all_docs, spacy_model=spacy_model)65 # clear out sectioned tmp folder if clean run66 if self.clean_tmp_files:67 self._clear_tmp_section_data()68 return all_docs69 def load_documents(self):70 '''71 Loads just the documents from LabKey server72 :return: list of Document objects73 '''74 self.logger.warning("load_documents has been called, but has not been implemented")75 raise NotImplementedError76 def load_annotations(self):77 '''78 Loads just the annotations from Labkey server79 :return: List of GoldAnnotation objects80 '''81 self.logger.warning("The XML data loader does not load annotations: It can only read XML documents in the bioNLP format")82 raise NotImplementedError("The XML data loader does not load annotations: It can only read XML documents in the bioNLP format")83 def _get_doc_id(self, doc):84 items = doc.split('.')85 if len(items)==1:86 return items[0]87 else:88 return '.'.join(items[0:-1])89 def _clear_tmp_section_data(self):90 sectioner_dir = self.xml_dir91 for the_file in os.listdir(sectioner_dir):92 file_path = os.path.join(sectioner_dir, the_file)93 try:94 if os.path.isfile(file_path):95 os.unlink(file_path)96 except Exception as e:97 self.logger.error("An error has occurred within _clear_tmp_section_data: {}".format(e))...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

...4from setuptools import setup, find_packages5import subprocess6sys.path.append('autohdl')7import pkg_info8def clean_tmp_files():9 if os.path.exists('AutoHDL.egg-info'):10 shutil.rmtree('AutoHDL.egg-info')11 files_to_clean = [i for i in os.listdir('autohdl') if os.path.splitext(i)[1] == '.pyc']12 for i in files_to_clean:13 os.remove(os.path.join('autohdl', i))14clean_tmp_files()15# fix Paralles Desktop bug16if 'install' in sys.argv:17 for i in ['py', 'cpy']:18 command = 'reg add HKEY_CLASSES_ROOT\{py_type}_auto_file\shell\open\command' \19 ' /ve /d "C:\windows\py.exe %1 %*" /f'.format(py_type=i)20 print('executing: ' + command)21 print(subprocess.check_output(command, shell=True))22if 'upload' in sys.argv:23 pkg_info.inc_version()24setup(name='AutoHDL',25 version=pkg_info.version(),26 description='Automatization Utilities for HDL projects',27 author='Maxim Golokhov',28 author_email='hexwer@gmail.com',...

Full Screen

Full Screen

run_all_plots.py

Source:run_all_plots.py Github

copy

Full Screen

1"""2 Script to generate all plots. It runs all other scripts inside the Plotter module except for3 the plot_animation, the plot_output_data and the support_plotter scripts.4"""5from plotter import get_training_time_traffic, plot_training_time_traffic, plot_cdf_reward, plot_reward_per_request, \6 plot_moving_avg, plot_moving_avg_for_params7from plotter.support_plotter import clear_tmp_files8# Set this flag to delete tmp files once all plots are generated9clean_tmp_files = True10get_training_time_traffic.main()11plot_training_time_traffic.main()12plot_cdf_reward.main()13plot_moving_avg.main()14plot_moving_avg_for_params.main()15plot_reward_per_request.main()16# Note that the heatmap is not plotted with this script, since it is referred to a single run17if clean_tmp_files:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful