Mercurial > repos > rmarenco > hubarchivecreator
view doc/_build/html/_modules/hubArchiveCreator.html @ 31:9c5d82d3c87e draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit cd459f55fcb828e250986412fb779234ad89b3b2
author | yating-l |
---|---|
date | Tue, 19 Jun 2018 13:16:08 -0400 |
parents | 40469b265ddb |
children |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>hubArchiveCreator — HubArchiveCreator 2.3 documentation</title> <link rel="stylesheet" href="../_static/classic.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.3', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="top" title="HubArchiveCreator 2.3 documentation" href="../index.html" /> <link rel="up" title="Module code" href="index.html" /> </head> <body role="document"> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">HubArchiveCreator 2.3 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <h1>Source code for hubArchiveCreator</h1><div class="highlight"><pre> <span></span><span class="ch">#!/usr/bin/python</span> <span class="c1"># -*- coding: utf8 -*-</span> <span class="sd">"""</span> <span class="sd">This Galaxy tool permits to prepare your files to be ready for</span> <span class="sd">Assembly Hub visualization.</span> <span class="sd">Program test arguments:</span> <span class="sd">hubArchiveCreator.py -g test-data/augustusDbia3.gff3 -f test-data/dbia3.fa -d . -u ./tools -o output.html</span> <span class="sd">"""</span> <span class="kn">import</span> <span class="nn">argparse</span> <span class="kn">import</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="nn">json</span> <span class="kn">import</span> <span class="nn">logging</span> <span class="kn">import</span> <span class="nn">os</span> <span class="kn">import</span> <span class="nn">sys</span> <span class="c1"># Internal dependencies</span> <span class="kn">from</span> <span class="nn">Bam</span> <span class="k">import</span> <span class="n">Bam</span> <span class="kn">from</span> <span class="nn">BedSimpleRepeats</span> <span class="k">import</span> <span class="n">BedSimpleRepeats</span> <span class="kn">from</span> <span class="nn">Bed</span> <span class="k">import</span> <span class="n">Bed</span> <span class="kn">from</span> <span class="nn">BigWig</span> <span class="k">import</span> <span class="n">BigWig</span> <span class="kn">from</span> <span class="nn">util.Fasta</span> <span class="k">import</span> <span class="n">Fasta</span> <span class="kn">from</span> <span class="nn">util.Filters</span> <span class="k">import</span> <span class="n">TraceBackFormatter</span> <span class="kn">from</span> <span class="nn">Gff3</span> <span class="k">import</span> <span class="n">Gff3</span> <span class="kn">from</span> <span class="nn">Gtf</span> <span class="k">import</span> <span class="n">Gtf</span> <span class="kn">from</span> <span class="nn">Psl</span> <span class="k">import</span> <span class="n">Psl</span> <span class="kn">from</span> <span class="nn">TrackHub</span> <span class="k">import</span> <span class="n">TrackHub</span> <span class="c1"># TODO: Verify each subprocessed dependency is accessible [gff3ToGenePred, genePredToBed, twoBitInfo, faToTwoBit, bedToBigBed, sort</span> <span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="p">):</span> <span class="c1"># Command Line parsing init</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s1">'Create a foo.txt inside the given folder.'</span><span class="p">)</span> <span class="c1"># Reference genome mandatory</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-f'</span><span class="p">,</span> <span class="s1">'--fasta'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Fasta file of the reference genome'</span><span class="p">)</span> <span class="c1"># GFF3 Management</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--gff3'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'GFF3 format'</span><span class="p">)</span> <span class="c1"># GTF Management</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--gtf'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'GTF format'</span><span class="p">)</span> <span class="c1"># Bed4+12 (TrfBig)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--bedSimpleRepeats'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Bed4+12 format, using simpleRepeats.as'</span><span class="p">)</span> <span class="c1"># Generic Bed (Blastx transformed to bed)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--bed'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Bed generic format'</span><span class="p">)</span> <span class="c1"># BigWig Management</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--bigwig'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'BigWig format'</span><span class="p">)</span> <span class="c1"># Bam Management</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--bam'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Bam format'</span><span class="p">)</span> <span class="c1"># Psl Management</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--psl'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'append'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Psl format'</span><span class="p">)</span> <span class="c1"># TODO: Check if the running directory can have issues if we run the tool outside</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-d'</span><span class="p">,</span> <span class="s1">'--directory'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Running tool directory, where to find the templates. Default is running directory'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-u'</span><span class="p">,</span> <span class="s1">'--ucsc_tools_path'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Directory where to find the executables needed to run this tool'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-e'</span><span class="p">,</span> <span class="s1">'--extra_files_path'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Name, in galaxy, of the output folder. Where you would want to build the Track Hub Archive'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-o'</span><span class="p">,</span> <span class="s1">'--output'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Name of the HTML summarizing the content of the Track Hub Archive'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'-j'</span><span class="p">,</span> <span class="s1">'--data_json'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Json containing the metadata of the inputs'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--user_email'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Email of the user who launched the Hub Archive Creation'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--genome_name'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'UCSC Genome Browser assembly ID'</span><span class="p">)</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--debug_mode'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Allow more details about the errors'</span><span class="p">)</span> <span class="c1"># Begin init variables</span> <span class="n">toolDirectory</span> <span class="o">=</span> <span class="s1">'.'</span> <span class="n">extra_files_path</span> <span class="o">=</span> <span class="s1">'.'</span> <span class="c1"># Get the args passed in parameter</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span> <span class="n">extra_files_path</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">extra_files_path</span> <span class="n">toolDirectory</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">directory</span> <span class="c1">#### Logging management ####</span> <span class="c1"># If we are in Debug mode, also print in stdout the debug dump</span> <span class="n">configure_logger</span><span class="p">(</span><span class="n">extra_files_path</span><span class="o">=</span><span class="n">extra_files_path</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="n">args</span><span class="o">.</span><span class="n">debug_mode</span><span class="p">)</span> <span class="c1">#### END Logging management ####</span> <span class="n">array_inputs_reference_genome</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">fasta</span><span class="p">)</span> <span class="c1"># TODO: Replace these with the object Fasta</span> <span class="n">input_fasta_file</span> <span class="o">=</span> <span class="n">array_inputs_reference_genome</span><span class="p">[</span><span class="s2">"false_path"</span><span class="p">]</span> <span class="n">input_fasta_file_name</span> <span class="o">=</span> <span class="n">sanitize_name_input</span><span class="p">(</span><span class="n">array_inputs_reference_genome</span><span class="p">[</span><span class="s2">"name"</span><span class="p">])</span> <span class="n">genome_name</span> <span class="o">=</span> <span class="n">sanitize_name_input</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">genome_name</span><span class="p">)</span> <span class="n">reference_genome</span> <span class="o">=</span> <span class="n">Fasta</span><span class="p">(</span><span class="n">input_fasta_file</span><span class="p">,</span> <span class="n">input_fasta_file_name</span><span class="p">,</span> <span class="n">genome_name</span><span class="p">)</span> <span class="n">user_email</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">user_email</span> <span class="c1"># TODO: Use a class to have a better management of the structure of these inputs</span> <span class="c1"># These inputs are populated in the Galaxy Wrapper xml and are in this format:</span> <span class="c1"># ARRAY[DICT{FILE_PATH: DICT{NAME: NAME_VALUE, EXTRA_DATA: EXTRA_DATA_VALUE}}]</span> <span class="c1"># EXTRA_DATA could be anything, for example the index of a BAM => {"index", FILE_PATH}</span> <span class="n">array_inputs_bam</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bam</span> <span class="n">array_inputs_bed_generic</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bed</span> <span class="n">array_inputs_bed_simple_repeats</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bedSimpleRepeats</span> <span class="n">array_inputs_bigwig</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bigwig</span> <span class="n">array_inputs_gff3</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">gff3</span> <span class="n">array_inputs_gtf</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">gtf</span> <span class="n">array_inputs_psl</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">psl</span> <span class="n">outputFile</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">output</span> <span class="n">json_inputs_data</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">data_json</span> <span class="n">inputs_data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">json_inputs_data</span><span class="p">)</span> <span class="c1"># We remove the spaces in ["name"] of inputs_data</span> <span class="n">sanitize_name_inputs</span><span class="p">(</span><span class="n">inputs_data</span><span class="p">)</span> <span class="c1"># TODO: Check here all the binaries / tools we need. Exception if missing</span> <span class="c1"># Create the Track Hub folder</span> <span class="n">trackHub</span> <span class="o">=</span> <span class="n">TrackHub</span><span class="p">(</span><span class="n">reference_genome</span><span class="p">,</span> <span class="n">user_email</span><span class="p">,</span> <span class="n">outputFile</span><span class="p">,</span> <span class="n">extra_files_path</span><span class="p">,</span> <span class="n">toolDirectory</span><span class="p">)</span> <span class="n">all_datatype_dictionary</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">for</span> <span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">datatype_class</span><span class="p">)</span> <span class="ow">in</span> <span class="p">[</span> <span class="p">(</span><span class="n">array_inputs_bam</span><span class="p">,</span> <span class="n">Bam</span><span class="p">),</span> <span class="p">(</span><span class="n">array_inputs_bed_generic</span><span class="p">,</span> <span class="n">Bed</span><span class="p">),</span> <span class="p">(</span><span class="n">array_inputs_bigwig</span><span class="p">,</span> <span class="n">BigWig</span><span class="p">),</span> <span class="p">(</span><span class="n">array_inputs_bed_simple_repeats</span><span class="p">,</span> <span class="n">BedSimpleRepeats</span><span class="p">),</span> <span class="p">(</span><span class="n">array_inputs_gff3</span><span class="p">,</span> <span class="n">Gff3</span><span class="p">),</span> <span class="p">(</span><span class="n">array_inputs_gtf</span><span class="p">,</span> <span class="n">Gtf</span><span class="p">),</span> <span class="p">(</span><span class="n">array_inputs_psl</span><span class="p">,</span> <span class="n">Psl</span><span class="p">)]:</span> <span class="k">if</span> <span class="n">inputs</span><span class="p">:</span> <span class="n">all_datatype_dictionary</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">create_ordered_datatype_objects</span><span class="p">(</span><span class="n">datatype_class</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">inputs_data</span><span class="p">))</span> <span class="c1"># Create Ordered Dictionary to add the tracks in the tool form order</span> <span class="n">all_datatype_ordered_dictionary</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">OrderedDict</span><span class="p">(</span><span class="n">all_datatype_dictionary</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"----- End of all_datatype_dictionary processing -----"</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"all_datatype_ordered_dictionary keys are: </span><span class="si">{0}</span><span class="s2">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">all_datatype_ordered_dictionary</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"----- Beginning of Track adding processing -----"</span><span class="p">)</span> <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">datatypeObject</span> <span class="ow">in</span> <span class="n">all_datatype_ordered_dictionary</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span> <span class="n">trackHub</span><span class="o">.</span><span class="n">addTrack</span><span class="p">(</span><span class="n">datatypeObject</span><span class="o">.</span><span class="n">track</span><span class="o">.</span><span class="n">trackDb</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"----- End of Track adding processing -----"</span><span class="p">)</span> <span class="c1"># We process all the modifications to create the zip file</span> <span class="c1">#trackHub.createZip()</span> <span class="c1"># We terminate le process and so create a HTML file summarizing all the files</span> <span class="n">trackHub</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'#### End of HubArchiveCreator Debug Mode: Bye! ####'</span><span class="p">)</span> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <div class="viewcode-block" id="sanitize_name_input"><a class="viewcode-back" href="../code.html#hubArchiveCreator.sanitize_name_input">[docs]</a><span class="k">def</span> <span class="nf">sanitize_name_input</span><span class="p">(</span><span class="n">string_to_sanitize</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Sanitize the string passed in parameter by replacing '/' and ' ' by '_'</span> <span class="sd"> :param string_to_sanitize:</span> <span class="sd"> :return :</span> <span class="sd"> :Example:</span> <span class="sd"> >>> sanitize_name_input('this/is an//example')</span> <span class="sd"> this_is_an__example</span> <span class="sd"> """</span> <span class="k">return</span> <span class="n">string_to_sanitize</span> \ <span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"/"</span><span class="p">,</span> <span class="s2">"_"</span><span class="p">)</span> \ <span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">" "</span><span class="p">,</span> <span class="s2">"_"</span><span class="p">)</span></div> <div class="viewcode-block" id="sanitize_name_inputs"><a class="viewcode-back" href="../code.html#hubArchiveCreator.sanitize_name_inputs">[docs]</a><span class="k">def</span> <span class="nf">sanitize_name_inputs</span><span class="p">(</span><span class="n">inputs_data</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Sanitize value of the keys "name" of the dictionary passed in parameter.</span> <span class="sd"> Because sometimes output from Galaxy, or even just file name, from user inputs, have spaces.</span> <span class="sd"> Also, it can contain '/' character and could break the use of os.path function.</span> <span class="sd"> :param inputs_data: dict[string, dict[string, string]]</span> <span class="sd"> """</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">inputs_data</span><span class="p">:</span> <span class="n">inputs_data</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">"name"</span><span class="p">]</span> <span class="o">=</span> <span class="n">sanitize_name_input</span><span class="p">(</span><span class="n">inputs_data</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">"name"</span><span class="p">])</span></div> <div class="viewcode-block" id="create_ordered_datatype_objects"><a class="viewcode-back" href="../code.html#hubArchiveCreator.create_ordered_datatype_objects">[docs]</a><span class="k">def</span> <span class="nf">create_ordered_datatype_objects</span><span class="p">(</span><span class="n">ExtensionClass</span><span class="p">,</span> <span class="n">array_inputs</span><span class="p">,</span> <span class="n">inputs_data</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Function which executes the creation all the necessary files / folders for a special Datatype, for TrackHub</span> <span class="sd"> and update the dictionary of datatype</span> <span class="sd"> :param ExtensionClass:</span> <span class="sd"> :param array_inputs:</span> <span class="sd"> :param inputs_data:</span> <span class="sd"> :type ExtensionClass: Datatype</span> <span class="sd"> :type array_inputs: list[string]</span> <span class="sd"> :type inputs_data: dict</span> <span class="sd"> :rtype: dict</span> <span class="sd"> """</span> <span class="n">datatype_dictionary</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># TODO: Optimize this double loop</span> <span class="k">for</span> <span class="n">input_false_path</span> <span class="ow">in</span> <span class="n">array_inputs</span><span class="p">:</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">data_value</span> <span class="ow">in</span> <span class="n">inputs_data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="n">input_false_path</span><span class="p">:</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"input_false_path: "</span> <span class="o">+</span> <span class="n">input_false_path</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"data_value: "</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">data_value</span><span class="p">))</span> <span class="n">extensionObject</span> <span class="o">=</span> <span class="n">ExtensionClass</span><span class="p">(</span><span class="n">input_false_path</span><span class="p">,</span> <span class="n">data_value</span><span class="p">)</span> <span class="n">datatype_dictionary</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">data_value</span><span class="p">[</span><span class="s2">"order_index"</span><span class="p">]:</span> <span class="n">extensionObject</span><span class="p">})</span> <span class="k">return</span> <span class="n">datatype_dictionary</span></div> <span class="k">def</span> <span class="nf">configure_logger</span><span class="p">(</span><span class="n">extra_files_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">extra_files_path</span><span class="p">:</span> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">"Extra files path is not set. Stopping the application"</span><span class="p">)</span> <span class="c1"># All case log: log everything in a .log file</span> <span class="n">logger_file_name</span> <span class="o">=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">__name__</span><span class="p">,</span> <span class="s1">'.log'</span><span class="p">])</span> <span class="n">logging_file_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">extra_files_path</span><span class="p">,</span> <span class="n">logger_file_name</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">logging_file_path</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span> <span class="n">log_stdout</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">debug</span><span class="p">:</span> <span class="n">configure_logger_user</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span> <span class="k">else</span><span class="p">:</span> <span class="n">configure_logger_dev</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span> <span class="c1"># stderr configuration</span> <span class="n">configure_logger_stderr</span><span class="p">()</span> <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">'#### Welcome in HubArchiveCreator Debug Mode ####</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span> <div class="viewcode-block" id="configure_logger_user"><a class="viewcode-back" href="../code.html#hubArchiveCreator.configure_logger_user">[docs]</a><span class="k">def</span> <span class="nf">configure_logger_user</span><span class="p">(</span><span class="n">log_stdout</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> User Logger is defined as following:</span> <span class="sd"> - User needs to have WARN, ERROR and CRITICAL but well formatted / without traceback</span> <span class="sd"> in STDOUT</span> <span class="sd"> - Still access to full, brute and traceback for errors</span> <span class="sd"> in STDERR</span> <span class="sd"> - And further access to debug if needed</span> <span class="sd"> in .log</span> <span class="sd"> """</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">log_stdout</span><span class="p">:</span> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">"No log_stdout given. Stopping the application"</span><span class="p">)</span> <span class="c1"># stdout for INFO / WARN / ERROR / CRITICAL</span> <span class="n">log_stdout</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span> <span class="n">formatter</span> <span class="o">=</span> <span class="n">TraceBackFormatter</span><span class="p">(</span><span class="s1">'</span><span class="si">%(message)s</span><span class="s1">'</span><span class="p">)</span> <span class="n">log_stdout</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">formatter</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span></div> <div class="viewcode-block" id="configure_logger_dev"><a class="viewcode-back" href="../code.html#hubArchiveCreator.configure_logger_dev">[docs]</a><span class="k">def</span> <span class="nf">configure_logger_dev</span><span class="p">(</span><span class="n">log_stdout</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> <span class="sd">"""</span> <span class="sd"> Dev Logger is defined as following:</span> <span class="sd"> - Dev needs to have WARN, ERROR and CRITICAL but well formatted / without traceback, in stdout</span> <span class="sd"> - Still access to full, brute and traceback in stderr for errors</span> <span class="sd"> - And further access to debug if needed</span> <span class="sd"> """</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">log_stdout</span><span class="p">:</span> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">"No log_stdout given. Stopping the application"</span><span class="p">)</span> <span class="n">log_format</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%(message)s</span><span class="s1">'</span> <span class="c1"># stdout and stderr and both identical for INFO / WARN / ERROR / CRITICAL</span> <span class="n">log_stdout</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span> <span class="n">formatter</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="n">log_format</span><span class="p">)</span> <span class="n">log_stdout</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">formatter</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span></div> <div class="viewcode-block" id="configure_logger_stderr"><a class="viewcode-back" href="../code.html#hubArchiveCreator.configure_logger_stderr">[docs]</a><span class="k">def</span> <span class="nf">configure_logger_stderr</span><span class="p">():</span> <span class="sd">"""</span> <span class="sd"> Configure what should be logged in stderr</span> <span class="sd"> """</span> <span class="n">log_error</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">)</span> <span class="n">log_error</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">ERROR</span><span class="p">)</span> <span class="n">log_error_format</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%(message)s</span><span class="s1">'</span> <span class="n">formatter_error</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="n">log_error_format</span><span class="p">)</span> <span class="n">log_error</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">formatter_error</span><span class="p">)</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">log_error</span><span class="p">)</span></div> <span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span> <span class="n">main</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span> </pre></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <div><input type="text" name="q" /></div> <div><input type="submit" value="Go" /></div> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">HubArchiveCreator 2.3 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >Module code</a> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2016, Remi Marenco. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8. </div> </body> </html>