Package setuplib

Source Code for Package setuplib

  1  # -*- coding: utf-8 -*- 
  2  """Setup helper library specific for the runtime environment of *distutils* and *setuptools*. 
  3  """ 
  4  from __future__ import absolute_import 
  5   
  6  import os 
  7  import re 
  8  import fnmatch 
  9  import tempfile 
 10  import shutil 
 11   
 12   
 13  __author__ = 'Arno-Can Uestuensoez' 
 14  __author_email__ = 'acue_sf2@sourceforge.net' 
 15  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 16  __copyright__ = "Copyright (C) 2015-2019 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez" 
 17  __uuid__ = "239b0bf7-674a-4f53-a646-119f591af806" 
 18   
 19  __version__ = "01.01.001" 
 20   
 21   
22 -class SetuplibError(Exception):
23 pass
24 25
26 -def help_on_user_options(uopt, uoptions, raw=False):
27 """Displays the standard option data as provided by the 28 "distuitls" API variable 'user_options'. 29 30 The supported format is:: 31 32 user_options = [ 33 (<user-option-long>, <user-option-short>, <user-option-description>), 34 ... 35 ] 36 37 Args: 38 uopt: 39 User option:: 40 41 uopt := ( 42 <user-option-long> 43 | <user-option-short> 44 | #index 45 ) 46 47 user-option-long := ( 48 <literal-no-args> 49 | <literal-with-hyphen-no-args> # leading '--' 50 | <literal-with-args> # trailing '=' 51 | <literal-with-hyphen-with-args> # leading '--' and trailing '=' 52 ) 53 54 user-option-short := ( 55 <literal-no-hyphen> 56 | <literal-with-hyphen> # leading '--' 57 ) 58 59 index := int[0, length(user_options)) 60 # use for development and test only, 61 # production use is not recommended 62 63 uoptions: 64 The options definition. 65 66 raw: 67 If set to 'True', the original entry tuple is returned, 68 else the formatted string for console display. 69 70 Results: 71 Return string reference to the defined help-string. 72 73 Raises: 74 SetupDocXError 75 76 pass-through 77 78 """ 79 _uopt = re.sub(r'^[-][-]{0,1}', r'', uopt) 80 81 if len(_uopt) == 1: # short-opts 82 _uohelp = [x[2] for x in uoptions if x[1] == _uopt] 83 84 else: 85 # only options with arguments can have the 'help' argument 86 # the long and short form too 87 88 # long-opts with arguments 89 _uohelp = [x for x in uoptions if x[0] == _uopt or (x[0][:-1] == _uopt and x[0][-1] == '=')] 90 91 # if not _uohelp: 92 # # long-opts - literally 93 # _uohelp = [x for x in uoptions if x[0] == _uopt] 94 95 if not _uohelp: 96 # short-opts - literally 97 _uohelp = [x for x in uoptions if x[1] == _uopt] 98 99 if not _uohelp: 100 try: 101 # try as index - convert to int if required 102 _uohelp = _uopt[int(uopt)] 103 except: 104 raise SetuplibError( 105 "Unknonw option: " + str(uopt) 106 ) 107 108 if raw: 109 return _uohelp 110 111 return "Help on Option:\n\nlong: %s\nshort: %s\ndescription: %s\n" %( 112 str(_uohelp[0][0]), str(_uohelp[0][1]), str(_uohelp[0][2]) 113 )
114 115
116 -def check_for_context_help(cmdobj, raw=False):
117 """Scans for any requested context help, if present returns either a formatted 118 string for console display, or the reference to the raw help entry. 119 120 Args: 121 cmdobj: 122 The command object 'distutils.cmd.Command'. 123 124 raw: 125 If 'True' returns the raw entry. else a formatted 126 string for console display. 127 128 Returns: 129 The help entry, either raw, or as a formatted console string. 130 131 Raises: 132 pass-through 133 134 """ 135 for o in cmdobj.user_options: 136 _ax = re.sub(r'[-]', '_', o[0]) 137 _ax = re.sub(r'=$', '', _ax) 138 if hasattr(cmdobj, _ax) and getattr(cmdobj, _ax) == 'help': 139 return help_on_user_options(o[0], cmdobj.user_options)
140