1 2 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 3 <html><head><title>Python: module telemetry.internal.util.command_line</title> 4 <meta charset="utf-8"> 5 </head><body bgcolor="#f0f0f8"> 6 7 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> 8 <tr bgcolor="#7799ee"> 9 <td valign=bottom> <br> 10 <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="telemetry.html"><font color="#ffffff">telemetry</font></a>.<a href="telemetry.internal.html"><font color="#ffffff">internal</font></a>.<a href="telemetry.internal.util.html"><font color="#ffffff">util</font></a>.command_line</strong></big></big></font></td 11 ><td align=right valign=bottom 12 ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="../telemetry/internal/util/command_line.py">telemetry/internal/util/command_line.py</a></font></td></tr></table> 13 <p><tt># Copyright 2014 The Chromium Authors. All rights reserved.<br> 14 # Use of this source code is governed by a BSD-style license that can be<br> 15 # found in the LICENSE file.</tt></p> 16 <p> 17 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 18 <tr bgcolor="#aa55cc"> 19 <td colspan=3 valign=bottom> <br> 20 <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> 21 22 <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> 23 <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="argparse.html">argparse</a><br> 24 </td><td width="25%" valign=top><a href="telemetry.internal.util.camel_case.html">telemetry.internal.util.camel_case</a><br> 25 </td><td width="25%" valign=top><a href="difflib.html">difflib</a><br> 26 </td><td width="25%" valign=top><a href="optparse.html">optparse</a><br> 27 </td></tr></table></td></tr></table><p> 28 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 29 <tr bgcolor="#ee77aa"> 30 <td colspan=3 valign=bottom> <br> 31 <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> 32 33 <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> 34 <td width="100%"><dl> 35 <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> 36 </font></dt><dd> 37 <dl> 38 <dt><font face="helvetica, arial"><a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a> 39 </font></dt><dd> 40 <dl> 41 <dt><font face="helvetica, arial"><a href="telemetry.internal.util.command_line.html#Command">Command</a> 42 </font></dt><dd> 43 <dl> 44 <dt><font face="helvetica, arial"><a href="telemetry.internal.util.command_line.html#OptparseCommand">OptparseCommand</a> 45 </font></dt><dt><font face="helvetica, arial"><a href="telemetry.internal.util.command_line.html#SubcommandCommand">SubcommandCommand</a> 46 </font></dt></dl> 47 </dd> 48 </dl> 49 </dd> 50 </dl> 51 </dd> 52 </dl> 53 <p> 54 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 55 <tr bgcolor="#ffc8d8"> 56 <td colspan=3 valign=bottom> <br> 57 <font color="#000000" face="helvetica, arial"><a name="ArgumentHandlerMixIn">class <strong>ArgumentHandlerMixIn</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> 58 59 <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> 60 <td colspan=2><tt>A structured way to handle command-line arguments.<br> 61 <br> 62 In AddCommandLineArgs, add command-line arguments.<br> 63 In ProcessCommandLineArgs, validate them and store them in a private class<br> 64 variable. This way, each class encapsulates its own arguments, without needing<br> 65 to pass an arguments <a href="__builtin__.html#object">object</a> around everywhere.<br> </tt></td></tr> 66 <tr><td> </td> 67 <td width="100%">Class methods defined here:<br> 68 <dl><dt><a name="ArgumentHandlerMixIn-AddCommandLineArgs"><strong>AddCommandLineArgs</strong></a>(cls, parser)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Override to accept custom command-line arguments.</tt></dd></dl> 69 70 <dl><dt><a name="ArgumentHandlerMixIn-ProcessCommandLineArgs"><strong>ProcessCommandLineArgs</strong></a>(cls, parser, args)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Override to process command-line arguments.<br> 71 <br> 72 We pass in parser so we can call parser.error().</tt></dd></dl> 73 74 <hr> 75 Data descriptors defined here:<br> 76 <dl><dt><strong>__dict__</strong></dt> 77 <dd><tt>dictionary for instance variables (if defined)</tt></dd> 78 </dl> 79 <dl><dt><strong>__weakref__</strong></dt> 80 <dd><tt>list of weak references to the object (if defined)</tt></dd> 81 </dl> 82 </td></tr></table> <p> 83 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 84 <tr bgcolor="#ffc8d8"> 85 <td colspan=3 valign=bottom> <br> 86 <font color="#000000" face="helvetica, arial"><a name="Command">class <strong>Command</strong></a>(<a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a>)</font></td></tr> 87 88 <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> 89 <td colspan=2><tt>An abstraction for things that run from the command-line.<br> </tt></td></tr> 90 <tr><td> </td> 91 <td width="100%"><dl><dt>Method resolution order:</dt> 92 <dd><a href="telemetry.internal.util.command_line.html#Command">Command</a></dd> 93 <dd><a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a></dd> 94 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> 95 </dl> 96 <hr> 97 Methods defined here:<br> 98 <dl><dt><a name="Command-Run"><strong>Run</strong></a>(self, args)</dt></dl> 99 100 <hr> 101 Class methods defined here:<br> 102 <dl><dt><a name="Command-Description"><strong>Description</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 103 104 <dl><dt><a name="Command-Name"><strong>Name</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 105 106 <dl><dt><a name="Command-main"><strong>main</strong></a>(cls, args<font color="#909090">=None</font>)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Main method to run this command as a standalone script.</tt></dd></dl> 107 108 <hr> 109 Class methods inherited from <a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a>:<br> 110 <dl><dt><a name="Command-AddCommandLineArgs"><strong>AddCommandLineArgs</strong></a>(cls, parser)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Override to accept custom command-line arguments.</tt></dd></dl> 111 112 <dl><dt><a name="Command-ProcessCommandLineArgs"><strong>ProcessCommandLineArgs</strong></a>(cls, parser, args)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Override to process command-line arguments.<br> 113 <br> 114 We pass in parser so we can call parser.error().</tt></dd></dl> 115 116 <hr> 117 Data descriptors inherited from <a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a>:<br> 118 <dl><dt><strong>__dict__</strong></dt> 119 <dd><tt>dictionary for instance variables (if defined)</tt></dd> 120 </dl> 121 <dl><dt><strong>__weakref__</strong></dt> 122 <dd><tt>list of weak references to the object (if defined)</tt></dd> 123 </dl> 124 </td></tr></table> <p> 125 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 126 <tr bgcolor="#ffc8d8"> 127 <td colspan=3 valign=bottom> <br> 128 <font color="#000000" face="helvetica, arial"><a name="OptparseCommand">class <strong>OptparseCommand</strong></a>(<a href="telemetry.internal.util.command_line.html#Command">Command</a>)</font></td></tr> 129 130 <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> 131 <td colspan=2><tt># TODO: Convert everything to argparse.<br> </tt></td></tr> 132 <tr><td> </td> 133 <td width="100%"><dl><dt>Method resolution order:</dt> 134 <dd><a href="telemetry.internal.util.command_line.html#OptparseCommand">OptparseCommand</a></dd> 135 <dd><a href="telemetry.internal.util.command_line.html#Command">Command</a></dd> 136 <dd><a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a></dd> 137 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> 138 </dl> 139 <hr> 140 Methods defined here:<br> 141 <dl><dt><a name="OptparseCommand-Run"><strong>Run</strong></a>(self, args)</dt></dl> 142 143 <hr> 144 Class methods defined here:<br> 145 <dl><dt><a name="OptparseCommand-AddCommandLineArgs"><strong>AddCommandLineArgs</strong></a>(cls, parser, environment)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 146 147 <dl><dt><a name="OptparseCommand-CreateParser"><strong>CreateParser</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 148 149 <dl><dt><a name="OptparseCommand-ProcessCommandLineArgs"><strong>ProcessCommandLineArgs</strong></a>(cls, parser, args, environment)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 150 151 <dl><dt><a name="OptparseCommand-main"><strong>main</strong></a>(cls, args<font color="#909090">=None</font>)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Main method to run this command as a standalone script.</tt></dd></dl> 152 153 <hr> 154 Data and other attributes defined here:<br> 155 <dl><dt><strong>usage</strong> = ''</dl> 156 157 <hr> 158 Class methods inherited from <a href="telemetry.internal.util.command_line.html#Command">Command</a>:<br> 159 <dl><dt><a name="OptparseCommand-Description"><strong>Description</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 160 161 <dl><dt><a name="OptparseCommand-Name"><strong>Name</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 162 163 <hr> 164 Data descriptors inherited from <a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a>:<br> 165 <dl><dt><strong>__dict__</strong></dt> 166 <dd><tt>dictionary for instance variables (if defined)</tt></dd> 167 </dl> 168 <dl><dt><strong>__weakref__</strong></dt> 169 <dd><tt>list of weak references to the object (if defined)</tt></dd> 170 </dl> 171 </td></tr></table> <p> 172 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 173 <tr bgcolor="#ffc8d8"> 174 <td colspan=3 valign=bottom> <br> 175 <font color="#000000" face="helvetica, arial"><a name="SubcommandCommand">class <strong>SubcommandCommand</strong></a>(<a href="telemetry.internal.util.command_line.html#Command">Command</a>)</font></td></tr> 176 177 <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> 178 <td colspan=2><tt>Combines Commands into one big command with sub-commands.<br> 179 <br> 180 E.g. "svn checkout", "svn update", and "svn commit" are separate sub-commands.<br> 181 <br> 182 Example usage:<br> 183 class MyCommand(command_line.<a href="#SubcommandCommand">SubcommandCommand</a>):<br> 184 commands = (Help, List, Run)<br> 185 <br> 186 if __name__ == '__main__':<br> 187 sys.exit(MyCommand.<a href="#SubcommandCommand-main">main</a>())<br> </tt></td></tr> 188 <tr><td> </td> 189 <td width="100%"><dl><dt>Method resolution order:</dt> 190 <dd><a href="telemetry.internal.util.command_line.html#SubcommandCommand">SubcommandCommand</a></dd> 191 <dd><a href="telemetry.internal.util.command_line.html#Command">Command</a></dd> 192 <dd><a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a></dd> 193 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> 194 </dl> 195 <hr> 196 Methods defined here:<br> 197 <dl><dt><a name="SubcommandCommand-Run"><strong>Run</strong></a>(self, args)</dt></dl> 198 199 <hr> 200 Class methods defined here:<br> 201 <dl><dt><a name="SubcommandCommand-AddCommandLineArgs"><strong>AddCommandLineArgs</strong></a>(cls, parser)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 202 203 <dl><dt><a name="SubcommandCommand-ProcessCommandLineArgs"><strong>ProcessCommandLineArgs</strong></a>(cls, parser, args)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 204 205 <hr> 206 Data and other attributes defined here:<br> 207 <dl><dt><strong>commands</strong> = ()</dl> 208 209 <hr> 210 Class methods inherited from <a href="telemetry.internal.util.command_line.html#Command">Command</a>:<br> 211 <dl><dt><a name="SubcommandCommand-Description"><strong>Description</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 212 213 <dl><dt><a name="SubcommandCommand-Name"><strong>Name</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt></dl> 214 215 <dl><dt><a name="SubcommandCommand-main"><strong>main</strong></a>(cls, args<font color="#909090">=None</font>)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Main method to run this command as a standalone script.</tt></dd></dl> 216 217 <hr> 218 Data descriptors inherited from <a href="telemetry.internal.util.command_line.html#ArgumentHandlerMixIn">ArgumentHandlerMixIn</a>:<br> 219 <dl><dt><strong>__dict__</strong></dt> 220 <dd><tt>dictionary for instance variables (if defined)</tt></dd> 221 </dl> 222 <dl><dt><strong>__weakref__</strong></dt> 223 <dd><tt>list of weak references to the object (if defined)</tt></dd> 224 </dl> 225 </td></tr></table></td></tr></table><p> 226 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> 227 <tr bgcolor="#eeaa77"> 228 <td colspan=3 valign=bottom> <br> 229 <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> 230 231 <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> 232 <td width="100%"><dl><dt><a name="-GetMostLikelyMatchedObject"><strong>GetMostLikelyMatchedObject</strong></a>(objects, target_name, name_func<font color="#909090">=<function <lambda>></font>, matched_score_threshold<font color="#909090">=0.4</font>)</dt><dd><tt>Matches objects whose names are most likely matched with target.<br> 233 <br> 234 Args:<br> 235 objects: list of objects to match.<br> 236 target_name: name to match.<br> 237 name_func: function to get <a href="__builtin__.html#object">object</a> name to match. Default bypass.<br> 238 matched_score_threshold: threshold of likelihood to match.<br> 239 <br> 240 Returns:<br> 241 A list of objects whose names are likely target_name.</tt></dd></dl> 242 </td></tr></table> 243 </body></html>