2424# Import third party libs
2525import jinja2
2626
27- sys .path .insert (0 , os .path .abspath (' ../' ))
28- sys .path .insert (0 , os .path .abspath (' _themes' ))
27+ sys .path .insert (0 , os .path .abspath (" ../" ))
28+ sys .path .insert (0 , os .path .abspath (" _themes" ))
2929
3030import napalm_logs # noqa
3131from napalm_logs .base import NapalmLogs # noqa
4242# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4343# ones.
4444extensions = [
45- ' sphinx.ext.autodoc' ,
46- ' sphinx.ext.doctest' ,
47- ' sphinx.ext.intersphinx' ,
48- ' sphinx.ext.coverage' ,
49- ' sphinx.ext.viewcode' ,
50- ' sphinx.ext.githubpages' ,
45+ " sphinx.ext.autodoc" ,
46+ " sphinx.ext.doctest" ,
47+ " sphinx.ext.intersphinx" ,
48+ " sphinx.ext.coverage" ,
49+ " sphinx.ext.viewcode" ,
50+ " sphinx.ext.githubpages" ,
5151]
5252
5353# Add any paths that contain templates here, relative to this directory.
54- templates_path = [' _templates' ]
54+ templates_path = [" _templates" ]
5555
5656# The suffix(es) of source filenames.
5757# You can specify multiple suffix as a list of string:
5858#
5959# source_suffix = ['.rst', '.md']
60- source_suffix = ' .rst'
60+ source_suffix = " .rst"
6161
6262# The master toctree document.
63- master_doc = ' index'
63+ master_doc = " index"
6464
6565# General information about the project.
66- project = u' napalm-logs'
67- copyright = u' 2017-2019, Mircea Ulinic'
68- author = u' Mircea Ulinic'
66+ project = " napalm-logs"
67+ copyright = " 2017-2019, Mircea Ulinic"
68+ author = " Mircea Ulinic"
6969
7070# The version info for the project you're documenting, acts as replacement for
7171# |version| and |release|, also used in various other places throughout the
8686# List of patterns, relative to source directory, that match files and
8787# directories to ignore when looking for source files.
8888# This patterns also effect to html_static_path and html_extra_path
89- exclude_patterns = [' _build' , ' Thumbs.db' , ' .DS_Store' ]
89+ exclude_patterns = [" _build" , " Thumbs.db" , " .DS_Store" ]
9090
9191# The name of the Pygments (syntax highlighting) style to use.
92- pygments_style = ' flask_theme_support.FlaskyStyle'
92+ pygments_style = " flask_theme_support.FlaskyStyle"
9393
9494# If true, `todo` and `todoList` produce output, else they produce nothing.
9595todo_include_todos = False
9999# The theme to use for HTML and HTML Help pages. See the documentation for
100100# a list of builtin themes.
101101#
102- html_theme = ' alabaster'
102+ html_theme = " alabaster"
103103
104104# Theme options are theme-specific and customize the look and feel of a theme
105105# further. For a list of options available for each theme, see the
106106# documentation.
107107#
108108html_theme_options = {
109- ' show_powered_by' : False ,
110- ' github_user' : ' napalm-automation' ,
111- ' github_repo' : ' napalm-logs' ,
112- ' github_banner' : True ,
113- ' show_related' : False ,
109+ " show_powered_by" : False ,
110+ " github_user" : " napalm-automation" ,
111+ " github_repo" : " napalm-logs" ,
112+ " github_banner" : True ,
113+ " show_related" : False ,
114114}
115115
116116# Add any paths that contain custom static files (such as style sheets) here,
117117# relative to this directory. They are copied after the builtin static files,
118118# so a file named "default.css" will overwrite the builtin "default.css".
119- html_static_path = [' _static' ]
119+ html_static_path = [" _static" ]
120120
121121# Custom sidebar templates, must be a dictionary that maps document names
122122# to template names.
123123#
124124# This is required for the alabaster theme
125125# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
126126html_sidebars = {
127- '**' : [
128- ' about.html' ,
129- ' navigation.html' ,
130- ' links.html' ,
131- ' relations.html' , # needs 'show_related': True theme option to display
132- ' searchbox.html' ,
133- ' donate.html' ,
127+ "**" : [
128+ " about.html" ,
129+ " navigation.html" ,
130+ " links.html" ,
131+ " relations.html" , # needs 'show_related': True theme option to display
132+ " searchbox.html" ,
133+ " donate.html" ,
134134 ]
135135}
136136
146146# -- Options for HTMLHelp output ------------------------------------------
147147
148148# Output file base name for HTML help builder.
149- htmlhelp_basename = ' napalm-logsdoc'
149+ htmlhelp_basename = " napalm-logsdoc"
150150
151151
152152# -- Options for LaTeX output ---------------------------------------------
172172latex_documents = [
173173 (
174174 master_doc ,
175- ' napalm-logs.tex' ,
176- u' napalm-logs Documentation' ,
177- u' Mircea Ulinic' ,
178- ' manual' ,
175+ " napalm-logs.tex" ,
176+ " napalm-logs Documentation" ,
177+ " Mircea Ulinic" ,
178+ " manual" ,
179179 ),
180180]
181181
184184
185185# One entry per manual page. List of tuples
186186# (source start file, name, description, authors, manual section).
187- man_pages = [(master_doc , ' napalm-logs' , u' napalm-logs Documentation' , [author ], 1 )]
187+ man_pages = [(master_doc , " napalm-logs" , " napalm-logs Documentation" , [author ], 1 )]
188188
189189
190190# -- Options for Texinfo output -------------------------------------------
195195texinfo_documents = [
196196 (
197197 master_doc ,
198- ' napalm-logs' ,
199- u' napalm-logs Documentation' ,
198+ " napalm-logs" ,
199+ " napalm-logs Documentation" ,
200200 author ,
201- ' napalm-logs' ,
201+ " napalm-logs" ,
202202 (
203- ' napalm-logs is a Python library that listens to syslog messages from network devices and returns strucuted data'
204- ' following the OpenConfig or IETF YANG models'
203+ " napalm-logs is a Python library that listens to syslog messages from network devices and returns strucuted data"
204+ " following the OpenConfig or IETF YANG models"
205205 ),
206- ' Miscellaneous' ,
206+ " Miscellaneous" ,
207207 ),
208208]
209209
225225# epub_uid = ''
226226
227227# A list of files that should not be packed into the epub file.
228- epub_exclude_files = [' search.html' ]
228+ epub_exclude_files = [" search.html" ]
229229
230230
231231def gen_messages_rst ():
@@ -250,71 +250,71 @@ def gen_messages_rst():
250250 nl_ = NapalmLogs (publisher = [])
251251 defined_errors = {}
252252 for os_name , os_cfg in nl_ .config_dict .items ():
253- for message in os_cfg [' messages' ]:
254- error_name = message [' error' ]
253+ for message in os_cfg [" messages" ]:
254+ error_name = message [" error" ]
255255 if error_name not in defined_errors :
256- defined_errors [error_name ] = {' doc' : '' , 'os' : [], ' model' : '' }
257- if not defined_errors [error_name ][' doc' ] or len (
258- defined_errors [error_name ][' doc' ]
259- ) < len (message [' __doc__' ]):
260- defined_errors [error_name ][' doc' ] = message [' __doc__' ]
261- if not defined_errors [error_name ][' model' ]:
262- defined_errors [error_name ][' model' ] = message [' model' ]
263- defined_errors [error_name ]['os' ].append (os_name )
256+ defined_errors [error_name ] = {" doc" : "" , "os" : [], " model" : "" }
257+ if not defined_errors [error_name ][" doc" ] or len (
258+ defined_errors [error_name ][" doc" ]
259+ ) < len (message [" __doc__" ]):
260+ defined_errors [error_name ][" doc" ] = message [" __doc__" ]
261+ if not defined_errors [error_name ][" model" ]:
262+ defined_errors [error_name ][" model" ] = message [" model" ]
263+ defined_errors [error_name ]["os" ].append (os_name )
264264 # The collect the mock data from the tests:
265265 cwd = os .path .dirname (__file__ )
266- test_root_path = os .path .join (cwd , '..' , ' tests' , ' config' )
267- env = jinja2 .Environment (loader = jinja2 .FileSystemLoader ('.' ))
266+ test_root_path = os .path .join (cwd , ".." , " tests" , " config" )
267+ env = jinja2 .Environment (loader = jinja2 .FileSystemLoader ("." ))
268268 for error_name , error_details in defined_errors .items ():
269- os_name = error_details ['os' ][0 ] # Picking up the first OS in the list.
269+ os_name = error_details ["os" ][0 ] # Picking up the first OS in the list.
270270 error_path = os .path .join (test_root_path , os_name , error_name )
271271 test_cases = [
272272 name
273273 for name in os .listdir (error_path )
274274 if os .path .isdir (os .path .join (error_path , name ))
275275 ]
276276 test_case_name = (
277- ' default' if ' default' in test_cases else test_cases [0 ]
277+ " default" if " default" in test_cases else test_cases [0 ]
278278 ) # Picking up a test case.
279279 test_case_path = os .path .join (error_path , test_case_name )
280- raw_message_filepath = os .path .join (test_case_path , ' syslog.msg' )
281- log .debug (' Looking for %s' , raw_message_filepath )
280+ raw_message_filepath = os .path .join (test_case_path , " syslog.msg" )
281+ log .debug (" Looking for %s" , raw_message_filepath )
282282 assert os .path .isfile (raw_message_filepath )
283- with open (raw_message_filepath , 'r' ) as raw_message_fh :
283+ with open (raw_message_filepath , "r" ) as raw_message_fh :
284284 raw_message = raw_message_fh .read ()
285- log .debug (' Read raw message:' )
285+ log .debug (" Read raw message:" )
286286 log .debug (raw_message )
287- yang_message_filepath = os .path .join (test_case_path , ' yang.json' )
288- log .debug (' Looking for %s' , yang_message_filepath )
287+ yang_message_filepath = os .path .join (test_case_path , " yang.json" )
288+ log .debug (" Looking for %s" , yang_message_filepath )
289289 assert os .path .isfile (yang_message_filepath )
290- with open (yang_message_filepath , 'r' ) as yang_message_fh :
290+ with open (yang_message_filepath , "r" ) as yang_message_fh :
291291 yang_message = yang_message_fh .read ()
292- log .debug (' Read YANG text:' )
292+ log .debug (" Read YANG text:" )
293293 log .debug (yang_message )
294294 struct_yang_message = json .loads (yang_message )
295295 indented_yang_message = json .dumps (
296296 struct_yang_message , indent = 4 , sort_keys = True
297297 )
298- log .debug (' Struct YANG message:' )
298+ log .debug (" Struct YANG message:" )
299299 log .debug (struct_yang_message )
300- msg_template = env .get_template (' message_template.jinja' )
300+ msg_template = env .get_template (" message_template.jinja" )
301301 rendered_template = msg_template .render (
302302 error_name = error_name ,
303- error_doc = error_details [' doc' ],
304- error_yang = error_details [' model' ],
305- error_os_list = list (set (error_details ['os' ])),
303+ error_doc = error_details [" doc" ],
304+ error_yang = error_details [" model" ],
305+ error_os_list = list (set (error_details ["os" ])),
306306 error_txt_example = raw_message .strip (),
307- error_json_example = indented_yang_message .replace (' \n }' , ' \n }' ),
307+ error_json_example = indented_yang_message .replace (" \n }" , " \n }" ),
308308 )
309- message_rst_path = ' messages/{error_name}.rst' .format (error_name = error_name )
310- with open (message_rst_path , 'w' ) as rst_fh :
309+ message_rst_path = " messages/{error_name}.rst" .format (error_name = error_name )
310+ with open (message_rst_path , "w" ) as rst_fh :
311311 rst_fh .write (rendered_template )
312- index_tpl_file = env .get_template (' messages_index_template.jinja' )
312+ index_tpl_file = env .get_template (" messages_index_template.jinja" )
313313 messages_list = list (defined_errors .keys ())
314- messages_list .extend ([' RAW' , ' UNKNOWN' ])
314+ messages_list .extend ([" RAW" , " UNKNOWN" ])
315315 messages_list .sort ()
316316 rendered_template = index_tpl_file .render (error_list = messages_list )
317- with open (' messages/index.rst' , 'w' ) as index_fh :
317+ with open (" messages/index.rst" , "w" ) as index_fh :
318318 index_fh .write (rendered_template )
319319
320320
0 commit comments