def gen_output_directory(output_directory, progress=Progress(verbose=False), run=Run(), delete_if_exists=False): if os.path.exists(output_directory) and delete_if_exists: try: run.warning( 'filesnpaths::gen_output_directory: the client asked the existing directory \ "%s" to be removed.. Just so you know :/ (You have 5 seconds to press\ CTRL + C).' % output_directory) time.sleep(5) shutil.rmtree(output_directory) except: progress.end() raise FilesNPathsError, "I was instructed to remove this directory, but I failed: '%s' :/" % output_directory if not os.path.exists(output_directory): try: os.makedirs(output_directory) except: progress.end() raise FilesNPathsError, "Output directory does not exist (attempt to create one failed as well): '%s'" % \ (output_directory) if not os.access(output_directory, os.W_OK): progress.end() raise FilesNPathsError, "You do not have write permission for the output directory: '%s'" % output_directory return output_directory
def __init__(self, from_address='admin@localhost', server_address='localhost', server_port=25, init_tls=False, username = None, password = None, run = Run(verbose = False), progress = Progress(verbose=False)): self.from_address = from_address self.server_address = server_address self.server_port = server_port self.init_tls = init_tls self.username = username self.password = password self.server = None self.config_ini_path = None self.run = run self.progress = progress self.config_template = { 'SMTP': { 'from_address' : {'mandatory': True, 'test': lambda x: str(x)}, 'server_address' : {'mandatory': True, 'test': lambda x: str(x)}, 'server_port' : {'mandatory': True, 'test': lambda x: RepresentsInt(x) and int(x) > 0, 'required': 'an integer'}, 'init_tls' : {'mandatory': True, 'test': lambda x: x in ['True', 'False'], 'required': 'True or False'}, 'username' : {'mandatory': True, 'test': lambda x: str(x)}, 'password' : {'mandatory': True, 'test': lambda x: str(x)}, }, }
def run_processes(self, processes_to_run, progress=Progress(verbose=False)): tot_num_processes = len(processes_to_run) sent_to_run = 0 while 1: NumRunningProceses = lambda: len( [p for p in self.processes if p.is_alive()]) if NumRunningProceses() < self.num_thread and processes_to_run: for i in range(0, self.num_thread - NumRunningProceses()): if len(processes_to_run): sent_to_run += 1 self.run(processes_to_run.pop()) if not NumRunningProceses() and not processes_to_run: # let the blastn program finish writing all output files. # FIXME: this is ridiculous. find a better solution. time.sleep(1) break progress.update('%d of %d done in %d threads (currently running processes: %d)'\ % (sent_to_run - NumRunningProceses(), tot_num_processes, self.num_thread, NumRunningProceses())) time.sleep(1)
def gen_output_directory(output_directory, progress=Progress(verbose=False), run=Run(), delete_if_exists=False, dont_warn=False): if not output_directory: raise FilesNPathsError("Someone called `gen_output_directory` function without an output\ directory name :( An embarrassing moment for everyone involved.") if os.path.exists(output_directory) and delete_if_exists and not is_dir_empty(output_directory): try: if not dont_warn: run.warning('The existing directory "%s" is about to be removed... (You have \ 20 seconds to press CTRL + C). [filesnpaths::gen_output_directory]' % output_directory, header = '!!! READ THIS NOW !!!') time.sleep(20) shutil.rmtree(output_directory) except: progress.end() raise FilesNPathsError("I was instructed to remove this directory, but I failed: '%s' :/" % output_directory) if not os.path.exists(output_directory): try: os.makedirs(output_directory) except: progress.end() raise FilesNPathsError("Output directory does not exist (attempt to create one failed as well): '%s'" % \ (output_directory)) if not os.access(output_directory, os.W_OK): progress.end() raise FilesNPathsError("You do not have write permission for the output directory: '%s'" % output_directory) return output_directory
def __init__(self, search_path='.', max_files_and_dirs_to_process=50000, depth=3, run=Run(), progress=Progress()): self.run = run self.progress = progress self.depth = int(depth) self.search_path = search_path self.max_files_and_dirs_to_process = max_files_and_dirs_to_process self.anvio_dbs = {} for db_path, level in self.walk(): db_info = DBInfo(db_path, dont_raise=True) if db_info is not None: if db_info.db_type not in self.anvio_dbs: self.anvio_dbs[db_info.db_type] = [] # Add a cheeky `level` attribute to db_info for no other reason than to order dbs after the walk db_info.level = level self.anvio_dbs[db_info.db_type].append(db_info) # sort by level, so we know what is closest to the search_path root directory for db_type in self.anvio_dbs: self.anvio_dbs[db_type] = sorted(self.anvio_dbs[db_type], key=lambda d: d.level) self.anvio_dbs_found = True
def is_file_exists(file_path, dont_raise=False): if not file_path: raise FilesNPathsError("No input file is declared...") if not os.path.exists(os.path.abspath(file_path)): if dont_raise: return False else: Progress().reset() raise FilesNPathsError("No such file: '%s' :/" % file_path) return True
# -*- coding: utf-8 """Classes and functions for handling, storing, and retrieving atomic data from contigs and splits""" import anvio from anvio.sequence import Coverage from anvio.terminal import Run, Progress from anvio.terminal import pretty_print as pp from anvio.variability import VariablityTestFactory import anvio.tables as t run = Run() progress = Progress() progress.verbose = False try: from anvio.columnprofile import ColumnProfile except ImportError: run.info_single('C extension for ColumnProfile failed to load, falling back to the Python implementation...', mc = 'gray', nl_after = 1) from anvio.variability import ColumnProfile __author__ = "A. Murat Eren" __copyright__ = "Copyright 2015, The anvio Project" __credits__ = ["Faruk Uzun"] __license__ = "GPL 3.0" __version__ = anvio.__version__ __maintainer__ = "A. Murat Eren" __email__ = "*****@*****.**" __status__ = "Development"
# -*- coding: utf-8 """Classes and functions for handling, storing, and retrieving atomic data from contigs and splits""" import anvio from anvio.sequence import Coverage from anvio.terminal import Run, Progress from anvio.terminal import pretty_print as pp from anvio.variability import VariablityTestFactory import anvio.tables as t run = Run() progress = Progress() progress.verbose = False try: from anvio.columnprofile import ColumnProfile except ImportError: run.info_single( 'C extension for ColumnProfile failed to load, falling back to the Python implementation...', mc='gray', nl_after=1) from anvio.variability import ColumnProfile __author__ = "A. Murat Eren" __copyright__ = "Copyright 2015, The anvio Project" __credits__ = ["Faruk Uzun"] __license__ = "GPL 3.0" __version__ = anvio.__version__ __maintainer__ = "A. Murat Eren"