535def gen_files(pkg="", klass="", klass_type='object', fname='foo',
537 """Simple helper function to generate files based off some informations
538 @param pkg the name of the package holding the class we want to generate
539 @param klass the (fully qualified) name of the C++ class to generate
540 @param klass_type the type of class to generate (svc/tool/alg/object)
541 @param fname the filename to generate
542 @param ipkg the name of the package holding the interface of the class
543 @param iklass the name of the interface of the class we generate
546 hdr = getattr(Templates,
'%s_hdr_template'%klass_type)
547 cxx = getattr(Templates,
'%s_cxx_template'%klass_type)
548 except AttributeError
as err:
549 print (
"::: UNKNOWN klass_type [%s] !" % klass_type)
552 namespace_klass = klass.replace(
'::',
'_')
553 namespace_begin,namespace_end =
"",
""
554 if klass.count(
"::")>0:
555 nm = klass.split(
"::")[0]
556 klass = klass.split(
"::")[1]
557 namespace_begin = os.linesep +
"namespace %s {" % nm + os.linesep
558 namespace_end = os.linesep +
"} // namespace %s" % nm + os.linesep
561 guard =
"%s_%s_H" % (pkg.upper(), namespace_klass.upper())
568 namespace_begin=namespace_begin,
569 namespace_end=namespace_end,
570 copyright=Templates.copyright_template
572 fname = os.path.splitext(fname)[0]
574 o_hdr = open(fname+
'.h',
'w')
575 o_hdr.writelines(hdr%d)
580 o_cxx = open(fname+
'.cxx',
'w')
581 o_cxx.writelines(cxx%d)
588def gen_pyfiles(pkg="", klass="", klass_type='pyalg', fname='foo'):
589 """Simple helper function to generate (python) files based off some
591 @param pkg the name of the package holding the class we want to generate
592 @param klass the name of the python class to generate
593 @param klass_type the type of class to generate (pysvc/pytool/pyalg/pyaud)
594 @param fname the filename to generate
597 py_template = getattr(Templates,
'%s_template'%klass_type)
598 except AttributeError
as err:
599 print (
"::: UNKNOWN klass_type [%s] !" % klass_type)
602 invalid_py_chars = (
':',
'.',
'>',
'<',
' ' )
604 if any([c
for c
in invalid_py_chars
if c
in klass]):
605 err =
"::: INVALID class name ! (%s) !\n"%klass
606 err +=
"::: python class names can *NOT* contain any character of %s"%\
607 repr(invalid_py_chars)
609 raise RuntimeError(err)
611 fname=
''.join([fname,
'.py'])
615 copyright=Templates.copyright_template
618 o.writelines(py_template%d)
623@acmdlib.command(name='gen-klass')
627 help =
"The (fully qualified) name of the python or C++ class to create (ex: ElectronContainer, Analysis::Electron, MyAlgTool, PyTestAlg)")
631 help =
"The name of the package holding the C++ class to create (ex: MyAnalysis, JetEvent)")
636 choices = GenTypes.values,
637 help =
"The type of class to create")
641 help =
"The name of the package holding the interface of the C++ class (mandatory for 'svc' and 'tool' types)")
645 help =
"The name of the interface the C++ class is implementing (mandatory for 'svc' and 'tool' types)")
651 help =
"The name of the file(s) which will hold header and implementation of the class (ex: 'Foo' --> ('Foo.h','Foo.cxx'))")