ATLAS Offline Software
Loading...
Searching...
No Matches
python.scripts.gen_klass Namespace Reference

Classes

class  GenTypes
class  Templates

Functions

 gen_files (pkg="", klass="", klass_type='object', fname='foo', ipkg="", iklass="")
 gen_pyfiles (pkg="", klass="", klass_type='pyalg', fname='foo')
 main (args)

Variables

str __author__ = "Sebastien Binet"
str __doc__

Function Documentation

◆ gen_files()

python.scripts.gen_klass.gen_files ( pkg = "",
klass = "",
klass_type = 'object',
fname = 'foo',
ipkg = "",
iklass = "" )
Simple helper function to generate files based off some informations
 @param pkg the name of the package holding the class we want to generate
 @param klass the (fully qualified) name of the C++ class to generate
 @param klass_type the type of class to generate (svc/tool/alg/object)
 @param fname the filename to generate
 @param ipkg the name of the package holding the interface of the class
 @param iklass the name of the interface of the class we generate

Definition at line 535 of file gen_klass.py.

536 ipkg="", iklass=""):
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
544 """
545 try:
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)
550 raise err
551
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
559 pass
560
561 guard = "%s_%s_H" % (pkg.upper(), namespace_klass.upper())
562
563 d = dict( pkg=pkg,
564 klass=klass,
565 ipkg=ipkg,
566 iklass=iklass,
567 guard=guard,
568 namespace_begin=namespace_begin,
569 namespace_end=namespace_end,
570 copyright=Templates.copyright_template
571 )
572 fname = os.path.splitext(fname)[0]
573
574 o_hdr = open(fname+'.h', 'w')
575 o_hdr.writelines(hdr%d)
576 o_hdr.flush()
577 o_hdr.close()
578
579 if len(cxx)>0:
580 o_cxx = open(fname+'.cxx', 'w')
581 o_cxx.writelines(cxx%d)
582 o_cxx.flush()
583 o_cxx.close()
584
585 return 0
586
587

◆ gen_pyfiles()

python.scripts.gen_klass.gen_pyfiles ( pkg = "",
klass = "",
klass_type = 'pyalg',
fname = 'foo' )
Simple helper function to generate (python) files based off some
   user informations.
 @param pkg the name of the package holding the class we want to generate
 @param klass the name of the python class to generate
 @param klass_type the type of class to generate (pysvc/pytool/pyalg/pyaud)
 @param fname the filename to generate

Definition at line 588 of file gen_klass.py.

588def gen_pyfiles(pkg="", klass="", klass_type='pyalg', fname='foo'):
589 """Simple helper function to generate (python) files based off some
590 user informations.
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
595 """
596 try:
597 py_template = getattr(Templates, '%s_template'%klass_type)
598 except AttributeError as err:
599 print ("::: UNKNOWN klass_type [%s] !" % klass_type)
600 raise err
601
602 invalid_py_chars = ( ':', '.', '>', '<', ' ' )
603
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)
608 print (err)
609 raise RuntimeError(err)
610
611 fname=''.join([fname,'.py'])
612 d = dict( pkg=pkg,
613 klass=klass,
614 fname=fname,
615 copyright=Templates.copyright_template
616 )
617 o = open(fname, 'w')
618 o.writelines(py_template%d)
619 o.flush()
620 o.close()
621 return 0
622
623@acmdlib.command(name='gen-klass')
624@acmdlib.argument(
625 "--klass",
626 required=True,
627 help = "The (fully qualified) name of the python or C++ class to create (ex: ElectronContainer, Analysis::Electron, MyAlgTool, PyTestAlg)")
628@acmdlib.argument(
629 "--pkg",
630 required=True,
631 help = "The name of the package holding the C++ class to create (ex: MyAnalysis, JetEvent)")
632@acmdlib.argument(
633 "--type",
634 dest = "klass_type",
635 required=True,
636 choices = GenTypes.values,
637 help = "The type of class to create")
638@acmdlib.argument(
639 "--ipkg",
640 default = None,
641 help = "The name of the package holding the interface of the C++ class (mandatory for 'svc' and 'tool' types)")
642@acmdlib.argument(
643 "--iklass",
644 default = None,
645 help = "The name of the interface the C++ class is implementing (mandatory for 'svc' and 'tool' types)")
646@acmdlib.argument(
647 "-o",
648 "--output-file",
649 required=True,
650 dest = "fname",
651 help = "The name of the file(s) which will hold header and implementation of the class (ex: 'Foo' --> ('Foo.h','Foo.cxx'))")

◆ main()

python.scripts.gen_klass.main ( args)
helper script to generate header and cxx files
of various athena components (svc/tool/alg/isvc/itool/object)

Definition at line 652 of file gen_klass.py.

652def main(args):
653 """helper script to generate header and cxx files
654 of various athena components (svc/tool/alg/isvc/itool/object)
655 """
656
657 exitcode = 0
658
659 if args.klass_type in GenTypes.needing_iface and \
660 ( args.ipkg is None or args.iklass is None ) :
661 print (":: You have to give 'ipkg' and 'iklass' options to properly ",)
662 print ("generate an implementation for '%s'"%args.klass_type)
663 return 3
664
665
666 if args.ipkg is None:
667 args.ipkg = ""
668
669 if args.iklass is None:
670 args.iklass = ""
671
672 if args.klass_type.startswith('py'):
673 exitcode = gen_pyfiles(
674 klass=args.klass,
675 klass_type=args.klass_type,
676 pkg=args.pkg,
677 fname=args.fname
678 )
679 else:
680 exitcode = gen_files(
681 klass=args.klass,
682 klass_type=args.klass_type,
683 pkg=args.pkg,
684 iklass=args.iklass,
685 ipkg=args.ipkg,
686 fname=args.fname
687 )
688 return exitcode
int main()
Definition hello.cxx:18

Variable Documentation

◆ __author__

str python.scripts.gen_klass.__author__ = "Sebastien Binet"
private

Definition at line 11 of file gen_klass.py.

◆ __doc__

str python.scripts.gen_klass.__doc__
private
Initial value:
1= """\
2helper script to generate header and cxx files of various athena
3components (svc/tool/alg/isvc/itool/object)
4"""

Definition at line 12 of file gen_klass.py.