8 sys.path.insert(0, "@abs_top_srcdir@/ovsdb")
9 import simplejson as json
13 class Error(Exception):
14 def __init__(self, msg):
15 Exception.__init__(self)
18 def getMember(json, name, validTypes, description, default=None):
21 if type(member) not in validTypes:
22 raise Error("%s: type mismatch for '%s' member"
23 % (description, name))
27 def mustGetMember(json, name, expectedType, description):
28 member = getMember(json, name, expectedType, description)
30 raise Error("%s: missing '%s' member" % (description, name))
34 def __init__(self, name, comment, tables, idlPrefix, idlHeader):
36 self.comment = comment
38 self.idlPrefix = idlPrefix
39 self.idlHeader = idlHeader
43 name = mustGetMember(json, 'name', [unicode], 'database')
44 comment = getMember(json, 'comment', [unicode], 'database')
45 tablesJson = mustGetMember(json, 'tables', [dict], 'database')
47 for tableName, tableJson in tablesJson.iteritems():
48 tables[tableName] = TableSchema.fromJson(tableJson,
49 "%s table" % tableName)
50 idlPrefix = mustGetMember(json, 'idlPrefix', [unicode], 'database')
51 idlHeader = mustGetMember(json, 'idlHeader', [unicode], 'database')
52 return DbSchema(name, comment, tables, idlPrefix, idlHeader)
55 def __init__(self, comment, columns):
56 self.comment = comment
57 self.columns = columns
60 def fromJson(json, description):
61 comment = getMember(json, 'comment', [unicode], description)
62 columnsJson = mustGetMember(json, 'columns', [dict], description)
64 for name, json in columnsJson.iteritems():
65 columns[name] = ColumnSchema.fromJson(
66 json, "column %s in %s" % (name, description))
67 return TableSchema(comment, columns)
70 def __init__(self, comment, type, persistent):
71 self.comment = comment
73 self.persistent = persistent
76 def fromJson(json, description):
77 comment = getMember(json, 'comment', [unicode], description)
78 type = Type.fromJson(mustGetMember(json, 'type', [dict, unicode],
80 'type of %s' % description)
81 ephemeral = getMember(json, 'ephemeral', [bool], description)
82 persistent = ephemeral != True
83 return ColumnSchema(comment, type, persistent)
85 def escapeCString(src):
106 dst += '\\%03o' % ord(c)
112 def __init__(self, type, refTable=None, minInteger=None, maxInteger=None,
113 minReal=None, maxReal=None, reMatch=None, reComment=None,
114 minLength=None, maxLength=None):
116 self.refTable = refTable
117 self.minInteger = minInteger
118 self.maxInteger = maxInteger
119 self.minReal = minReal
120 self.maxReal = maxReal
121 self.reMatch = reMatch
122 self.reComment = reComment
123 self.minLength = minLength
124 self.maxLength = maxLength
127 def fromJson(json, description):
128 if type(json) == unicode:
129 return BaseType(json)
131 atomicType = mustGetMember(json, 'type', [unicode], description)
132 refTable = getMember(json, 'refTable', [unicode], description)
133 minInteger = getMember(json, 'minInteger', [int, long], description)
134 maxInteger = getMember(json, 'maxInteger', [int, long], description)
135 minReal = getMember(json, 'minReal', [int, long, float], description)
136 maxReal = getMember(json, 'maxReal', [int, long, float], description)
137 reMatch = getMember(json, 'reMatch', [unicode], description)
138 reComment = getMember(json, 'reComment', [unicode], description)
139 minLength = getMember(json, 'minLength', [int], description)
140 maxLength = getMember(json, 'minLength', [int], description)
141 return BaseType(atomicType, refTable, minInteger, maxInteger, minReal, maxReal, reMatch, reComment, minLength, maxLength)
144 if self.type == 'uuid' and self.refTable:
149 def toCType(self, prefix):
151 return "struct %s%s *" % (prefix, self.refTable.lower())
153 return {'integer': 'int64_t ',
155 'uuid': 'struct uuid ',
157 'string': 'char *'}[self.type]
159 def copyCValue(self, dst, src):
160 args = {'dst': dst, 'src': src}
162 return ("%(dst)s = %(src)s->header_.uuid;") % args
163 elif self.type == 'string':
164 return "%(dst)s = xstrdup(%(src)s);" % args
166 return "%(dst)s = %(src)s;" % args
168 def initCDefault(self, var, isOptional):
170 return "%s = NULL;" % var
171 elif self.type == 'string' and not isOptional:
172 return "%s = \"\";" % var
174 return {'integer': '%s = 0;',
176 'uuid': 'uuid_zero(&%s);',
177 'boolean': '%s = false;',
178 'string': '%s = NULL;'}[self.type] % var
180 def cInitBaseType(self, indent, var):
182 stmts.append('ovsdb_base_type_init(&%s, OVSDB_TYPE_%s);' % (
183 var, self.type.upper()),)
184 if self.type == 'integer':
185 if self.minInteger != None:
186 stmts.append('%s.u.integer.min = %d;' % (var, self.minInteger))
187 if self.maxInteger != None:
188 stmts.append('%s.u.integer.max = %d;' % (var, self.maxInteger))
189 elif self.type == 'real':
190 if self.minReal != None:
191 stmts.append('%s.u.real.min = %d;' % (var, self.minReal))
192 if self.maxReal != None:
193 stmts.append('%s.u.real.max = %d;' % (var, self.maxReal))
194 elif self.type == 'string':
195 if self.reMatch != None:
196 if self.reComment != None:
197 reComment = '"%s"' % escapeCString(self.reComment)
200 stmts.append('do_set_regex(&%s, "%s", %s);' % (
201 var, escapeCString(self.reMatch), reComment))
202 if self.minLength != None:
203 stmts.append('%s.u.string.minLen = %d;' % (var, self.minLength))
204 if self.maxLength != None:
205 stmts.append('%s.u.string.maxLen = %d;' % (var, self.maxLength))
206 return '\n'.join([indent + stmt for stmt in stmts])
209 def __init__(self, key, value=None, min=1, max=1):
216 def fromJson(json, description):
217 if type(json) == unicode:
218 return Type(BaseType(json))
220 keyJson = mustGetMember(json, 'key', [dict, unicode], description)
221 key = BaseType.fromJson(keyJson, 'key in %s' % description)
222 keyRefTable = getMember(json, 'keyRefTable', [unicode], description)
224 key.refTable = keyRefTable
226 valueJson = getMember(json, 'value', [dict, unicode], description)
228 value = BaseType.fromJson(valueJson,
229 'value in %s' % description)
230 valueRefTable = getMember(json, 'valueRefTable', [unicode], description)
232 value.refTable = valueRefTable
236 min = getMember(json, 'min', [int], description, 1)
237 max = getMember(json, 'max', [int, unicode], description, 1)
238 return Type(key, value, min, max)
241 return self.min == 1 and self.max == 1 and not self.value
243 def isOptional(self):
244 return self.min == 0 and self.max == 1
246 def isOptionalPointer(self):
247 return (self.min == 0 and self.max == 1 and not self.value
248 and (self.key.type == 'string' or self.key.refTable))
251 keyName = self.key.toEnglish()
253 valueName = self.value.toEnglish()
257 elif self.isOptional():
259 return "optional %s-%s pair" % (keyName, valueName)
261 return "optional %s" % keyName
263 if self.max == "unlimited":
265 quantity = "%d or more " % self.min
269 quantity = "%d to %d " % (self.min, self.max)
271 quantity = "up to %d " % self.max
274 return "map of %s%s-%s pairs" % (quantity, keyName, valueName)
276 return "set of %s%s" % (quantity, keyName)
278 def cDeclComment(self):
279 if self.min == 1 and self.max == 1 and self.key.type == "string":
280 return "\t/* Always nonnull. */"
284 def cInitType(self, indent, var):
285 initKey = self.key.cInitBaseType(indent, "%s.key" % var)
287 initValue = self.value.cInitBaseType(indent, "%s.value" % var)
289 initValue = ('%sovsdb_base_type_init(&%s.value, '
290 'OVSDB_TYPE_VOID);' % (indent, var))
291 initMin = "%s%s.n_min = %s;" % (indent, var, self.min)
292 if self.max == "unlimited":
296 initMax = "%s%s.n_max = %s;" % (indent, var, max)
297 return "\n".join((initKey, initValue, initMin, initMax))
299 def parseSchema(filename):
300 return DbSchema.fromJson(json.load(open(filename, "r")))
302 def annotateSchema(schemaFile, annotationFile):
303 schemaJson = json.load(open(schemaFile, "r"))
304 execfile(annotationFile, globals(), {"s": schemaJson})
305 json.dump(schemaJson, sys.stdout)
307 def constify(cType, const):
309 and cType.endswith('*') and not cType.endswith('**')
310 and (cType.startswith('struct uuid') or cType.startswith('char'))):
311 return 'const %s' % cType
315 def cMembers(prefix, columnName, column, const):
317 if type.min == 1 and type.max == 1:
322 if type.isOptionalPointer():
328 key = {'name': "key_%s" % columnName,
329 'type': constify(type.key.toCType(prefix) + pointer, const),
331 value = {'name': "value_%s" % columnName,
332 'type': constify(type.value.toCType(prefix) + pointer, const),
334 members = [key, value]
336 m = {'name': columnName,
337 'type': constify(type.key.toCType(prefix) + pointer, const),
338 'comment': type.cDeclComment()}
341 if not singleton and not type.isOptionalPointer():
342 members.append({'name': 'n_%s' % columnName,
347 def printCIDLHeader(schemaFile):
348 schema = parseSchema(schemaFile)
349 prefix = schema.idlPrefix
351 /* Generated automatically -- do not modify! -*- buffer-read-only: t -*- */
353 #ifndef %(prefix)sIDL_HEADER
354 #define %(prefix)sIDL_HEADER 1
359 #include "ovsdb-idl-provider.h"
360 #include "uuid.h"''' % {'prefix': prefix.upper()}
362 for tableName, table in sorted(schema.tables.iteritems()):
363 structName = "%s%s" % (prefix, tableName.lower())
366 print "/* %s table. */" % tableName
367 print "struct %s {" % structName
368 print "\tstruct ovsdb_idl_row header_;"
369 for columnName, column in sorted(table.columns.iteritems()):
370 print "\n\t/* %s column. */" % columnName
371 for member in cMembers(prefix, columnName, column, False):
372 print "\t%(type)s%(name)s;%(comment)s" % member
376 printEnum(["%s_COL_%s" % (structName.upper(), columnName.upper())
377 for columnName in sorted(table.columns)]
378 + ["%s_N_COLUMNS" % structName.upper()])
381 for columnName in table.columns:
382 print "#define %(s)s_col_%(c)s (%(s)s_columns[%(S)s_COL_%(C)s])" % {
384 'S': structName.upper(),
386 'C': columnName.upper()}
388 print "\nextern struct ovsdb_idl_column %s_columns[%s_N_COLUMNS];" % (structName, structName.upper())
391 const struct %(s)s *%(s)s_first(const struct ovsdb_idl *);
392 const struct %(s)s *%(s)s_next(const struct %(s)s *);
393 #define %(S)s_FOR_EACH(ROW, IDL) for ((ROW) = %(s)s_first(IDL); (ROW); (ROW) = %(s)s_next(ROW))
395 void %(s)s_delete(const struct %(s)s *);
396 struct %(s)s *%(s)s_insert(struct ovsdb_idl_txn *);
397 ''' % {'s': structName, 'S': structName.upper()}
399 for columnName, column in sorted(table.columns.iteritems()):
400 print 'void %(s)s_verify_%(c)s(const struct %(s)s *);' % {'s': structName, 'c': columnName}
403 for columnName, column in sorted(table.columns.iteritems()):
405 print 'void %(s)s_set_%(c)s(const struct %(s)s *,' % {'s': structName, 'c': columnName},
406 args = ['%(type)s%(name)s' % member for member
407 in cMembers(prefix, columnName, column, True)]
408 print '%s);' % ', '.join(args)
411 printEnum(["%sTABLE_%s" % (prefix.upper(), tableName.upper()) for tableName in sorted(schema.tables)] + ["%sN_TABLES" % prefix.upper()])
413 for tableName in schema.tables:
414 print "#define %(p)stable_%(t)s (%(p)stable_classes[%(P)sTABLE_%(T)s])" % {
417 't': tableName.lower(),
418 'T': tableName.upper()}
419 print "\nextern struct ovsdb_idl_table_class %stable_classes[%sN_TABLES];" % (prefix, prefix.upper())
421 print "\nextern struct ovsdb_idl_class %sidl_class;" % prefix
422 print "\nvoid %sinit(void);" % prefix
423 print "\n#endif /* %(prefix)sIDL_HEADER */" % {'prefix': prefix.upper()}
425 def printEnum(members):
426 if len(members) == 0:
430 for member in members[:-1]:
431 print " %s," % member
432 print " %s" % members[-1]
435 def printCIDLSource(schemaFile):
436 schema = parseSchema(schemaFile)
437 prefix = schema.idlPrefix
439 /* Generated automatically -- do not modify! -*- buffer-read-only: t -*- */
445 #include "ovsdb-data.h"
446 #include "ovsdb-error.h"
451 do_set_regex(struct ovsdb_base_type *base, const char *reMatch,
452 const char *reComment)
454 struct ovsdb_error *error;
456 error = ovsdb_base_type_set_regex(base, reMatch, reComment);
458 char *s = ovsdb_error_to_string(error);
459 ovs_error(0, "%%s", s);
461 ovsdb_error_destroy(error);
463 }''' % schema.idlHeader
466 for tableName, table in sorted(schema.tables.iteritems()):
467 structName = "%s%s" % (prefix, tableName.lower())
469 static struct %(s)s *
470 %(s)s_cast(const struct ovsdb_idl_row *row)
472 return row ? CONTAINER_OF(row, struct %(s)s, header_) : NULL;
474 ''' % {'s': structName}
477 for tableName, table in sorted(schema.tables.iteritems()):
478 structName = "%s%s" % (prefix, tableName.lower())
480 if table.comment != None:
481 print "/* %s table (%s). */" % (tableName, table.comment)
483 print "/* %s table. */" % (tableName)
486 for columnName, column in sorted(table.columns.iteritems()):
489 %(s)s_parse_%(c)s(struct ovsdb_idl_row *row_, const struct ovsdb_datum *datum)
491 struct %(s)s *row = %(s)s_cast(row_);''' % {'s': structName,
496 keyVar = "row->key_%s" % columnName
497 valueVar = "row->value_%s" % columnName
499 keyVar = "row->%s" % columnName
502 if (type.min == 1 and type.max == 1) or type.isOptionalPointer():
504 print " assert(inited);"
505 print " if (datum->n >= 1) {"
506 if not type.key.refTable:
507 print " %s = datum->keys[0].%s;" % (keyVar, type.key.type)
509 print " %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[0].uuid));" % (keyVar, prefix, type.key.refTable.lower(), prefix, prefix.upper(), type.key.refTable.upper())
512 if type.value.refTable:
513 print " %s = datum->values[0].%s;" % (valueVar, type.value.type)
515 print " %s = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[0].uuid));" % (valueVar, prefix, type.value.refTable.lower(), prefix, prefix.upper(), type.value.refTable.upper())
517 print " %s" % type.key.initCDefault(keyVar, type.min == 0)
519 print " %s" % type.value.initCDefault(valueVar, type.min == 0)
522 if type.max != 'unlimited':
523 print " size_t n = MIN(%d, datum->n);" % type.max
529 print " assert(inited);"
530 print " %s = NULL;" % keyVar
532 print " %s = NULL;" % valueVar
533 print " row->n_%s = 0;" % columnName
534 print " for (i = 0; i < %s; i++) {" % nMax
536 if type.key.refTable:
537 print " struct %s%s *keyRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->keys[i].uuid));" % (prefix, type.key.refTable.lower(), prefix, type.key.refTable.lower(), prefix, prefix.upper(), type.key.refTable.upper())
539 refs.append('keyRow')
541 keySrc = "datum->keys[i].%s" % type.key.type
542 if type.value and type.value.refTable:
543 print " struct %s%s *valueRow = %s%s_cast(ovsdb_idl_get_row_arc(row_, &%stable_classes[%sTABLE_%s], &datum->values[i].uuid));" % (prefix, type.value.refTable.lower(), prefix, type.value.refTable.lower(), prefix, prefix.upper(), type.value.refTable.upper())
544 valueSrc = "valueRow"
545 refs.append('valueRow')
547 valueSrc = "datum->values[i].%s" % type.value.type
549 print " if (%s) {" % ' && '.join(refs)
553 print "%sif (!row->n_%s) {" % (indent, columnName)
554 print "%s %s = xmalloc(%s * sizeof *%s);" % (indent, keyVar, nMax, keyVar)
556 print "%s %s = xmalloc(%s * sizeof %s);" % (indent, valueVar, nMax, valueVar)
558 print "%s%s[row->n_%s] = %s;" % (indent, keyVar, columnName, keySrc)
560 print "%s%s[row->n_%s] = %s;" % (indent, valueVar, columnName, valueSrc)
561 print "%srow->n_%s++;" % (indent, columnName)
568 for columnName, column in sorted(table.columns.iteritems()):
570 if (type.min != 1 or type.max != 1) and not type.isOptionalPointer():
573 %(s)s_unparse_%(c)s(struct ovsdb_idl_row *row_)
575 struct %(s)s *row = %(s)s_cast(row_);
577 assert(inited);''' % {'s': structName, 'c': columnName}
579 keyVar = "row->key_%s" % columnName
580 valueVar = "row->value_%s" % columnName
582 keyVar = "row->%s" % columnName
584 print " free(%s);" % keyVar
586 print " free(%s);" % valueVar
591 %(s)s_unparse_%(c)s(struct ovsdb_idl_row *row UNUSED)
594 }''' % {'s': structName, 'c': columnName}
596 # First, next functions.
599 %(s)s_first(const struct ovsdb_idl *idl)
601 return %(s)s_cast(ovsdb_idl_first_row(idl, &%(p)stable_classes[%(P)sTABLE_%(T)s]));
605 %(s)s_next(const struct %(s)s *row)
607 return %(s)s_cast(ovsdb_idl_next_row(&row->header_));
608 }''' % {'s': structName,
611 'T': tableName.upper()}
615 %(s)s_delete(const struct %(s)s *row)
617 ovsdb_idl_txn_delete(&row->header_);
621 %(s)s_insert(struct ovsdb_idl_txn *txn)
623 return %(s)s_cast(ovsdb_idl_txn_insert(txn, &%(p)stable_classes[%(P)sTABLE_%(T)s]));
625 ''' % {'s': structName,
628 'T': tableName.upper()}
631 for columnName, column in sorted(table.columns.iteritems()):
634 %(s)s_verify_%(c)s(const struct %(s)s *row)
637 ovsdb_idl_txn_verify(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s]);
638 }''' % {'s': structName,
639 'S': structName.upper(),
641 'C': columnName.upper()}
644 for columnName, column in sorted(table.columns.iteritems()):
647 members = cMembers(prefix, columnName, column, True)
648 keyVar = members[0]['name']
652 valueVar = members[1]['name']
654 nVar = members[2]['name']
657 nVar = members[1]['name']
658 print '%(s)s_set_%(c)s(const struct %(s)s *row, %(args)s)' % \
659 {'s': structName, 'c': columnName,
660 'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
662 print " struct ovsdb_datum datum;"
663 if type.min == 1 and type.max == 1:
665 print " assert(inited);"
666 print " datum.n = 1;"
667 print " datum.keys = xmalloc(sizeof *datum.keys);"
668 print " " + type.key.copyCValue("datum.keys[0].%s" % type.key.type, keyVar)
670 print " datum.values = xmalloc(sizeof *datum.values);"
671 print " "+ type.value.copyCValue("datum.values[0].%s" % type.value.type, valueVar)
673 print " datum.values = NULL;"
674 elif type.isOptionalPointer():
676 print " assert(inited);"
677 print " if (%s) {" % keyVar
678 print " datum.n = 1;"
679 print " datum.keys = xmalloc(sizeof *datum.keys);"
680 print " " + type.key.copyCValue("datum.keys[0].%s" % type.key.type, keyVar)
682 print " datum.n = 0;"
683 print " datum.keys = NULL;"
685 print " datum.values = NULL;"
689 print " assert(inited);"
690 print " datum.n = %s;" % nVar
691 print " datum.keys = xmalloc(%s * sizeof *datum.keys);" % nVar
693 print " datum.values = xmalloc(%s * sizeof *datum.values);" % nVar
695 print " datum.values = NULL;"
696 print " for (i = 0; i < %s; i++) {" % nVar
697 print " " + type.key.copyCValue("datum.keys[i].%s" % type.key.type, "%s[i]" % keyVar)
699 print " " + type.value.copyCValue("datum.values[i].%s" % type.value.type, "%s[i]" % valueVar)
701 print " ovsdb_idl_txn_write(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s], &datum);" \
703 'S': structName.upper(),
704 'C': columnName.upper()}
708 print "\nstruct ovsdb_idl_column %s_columns[%s_N_COLUMNS];" % (
709 structName, structName.upper())
711 static void\n%s_columns_init(void)
713 struct ovsdb_idl_column *c;\
715 for columnName, column in sorted(table.columns.iteritems()):
716 cs = "%s_col_%s" % (structName, columnName)
717 d = {'cs': cs, 'c': columnName, 's': structName}
719 print " /* Initialize %(cs)s. */" % d
720 print " c = &%(cs)s;" % d
721 print " c->name = \"%(c)s\";" % d
722 print column.type.cInitType(" ", "c->type")
723 print " c->parse = %(s)s_parse_%(c)s;" % d
724 print " c->unparse = %(s)s_unparse_%(c)s;" % d
729 print "struct ovsdb_idl_table_class %stable_classes[%sN_TABLES] = {" % (prefix, prefix.upper())
730 for tableName, table in sorted(schema.tables.iteritems()):
731 structName = "%s%s" % (prefix, tableName.lower())
732 print " {\"%s\"," % tableName
733 print " %s_columns, ARRAY_SIZE(%s_columns)," % (
734 structName, structName)
735 print " sizeof(struct %s)}," % structName
739 print "\nstruct ovsdb_idl_class %sidl_class = {" % prefix
740 print " %stable_classes, ARRAY_SIZE(%stable_classes)" % (prefix, prefix)
743 # global init function
753 for tableName, table in sorted(schema.tables.iteritems()):
754 structName = "%s%s" % (prefix, tableName.lower())
755 print " %s_columns_init();" % structName
758 def ovsdb_escape(string):
762 raise Error("strings may not contain null bytes")
776 return '\\x%02x' % ord(c)
777 return re.sub(r'["\\\000-\037]', escape, string)
779 def printDoc(schemaFile):
780 schema = parseSchema(schemaFile)
785 for tableName, table in sorted(schema.tables.iteritems()):
786 title = "%s table" % tableName
789 print '-' * len(title)
793 for columnName, column in sorted(table.columns.iteritems()):
795 print "%s (%s)" % (columnName, column.type.toEnglish())
797 print "\t%s" % column.comment
801 %(argv0)s: ovsdb schema compiler
802 usage: %(argv0)s [OPTIONS] COMMAND ARG...
804 The following commands are supported:
805 annotate SCHEMA ANNOTATIONS print SCHEMA combined with ANNOTATIONS
806 c-idl-header IDL print C header file for IDL
807 c-idl-source IDL print C source file for IDL implementation
808 doc IDL print schema documentation
810 The following options are also available:
811 -h, --help display this help message
812 -V, --version display version information\
813 """ % {'argv0': argv0}
816 if __name__ == "__main__":
819 options, args = getopt.gnu_getopt(sys.argv[1:], 'C:hV',
823 except getopt.GetoptError, geo:
824 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
827 for key, value in options:
828 if key in ['-h', '--help']:
830 elif key in ['-V', '--version']:
831 print "ovsdb-idlc (Open vSwitch) @VERSION@"
832 elif key in ['-C', '--directory']:
837 optKeys = [key for key, value in options]
840 sys.stderr.write("%s: missing command argument "
841 "(use --help for help)\n" % argv0)
844 commands = {"annotate": (annotateSchema, 2),
845 "c-idl-header": (printCIDLHeader, 1),
846 "c-idl-source": (printCIDLSource, 1),
847 "doc": (printDoc, 1)}
849 if not args[0] in commands:
850 sys.stderr.write("%s: unknown command \"%s\" "
851 "(use --help for help)\n" % (argv0, args[0]))
854 func, n_args = commands[args[0]]
855 if len(args) - 1 != n_args:
856 sys.stderr.write("%s: \"%s\" requires %d arguments but %d "
858 % (argv0, args[0], n_args, len(args) - 1))
863 sys.stderr.write("%s: %s\n" % (argv0, e.msg))